public InputStream getInputStream() throws IOException { return inputPart.getBody(InputStream.class, null); }
LOG.info("\"" + part.getBodyAsString() + "\"");
@Override protected InputPart extractPart(BodyPart bodyPart) throws IOException { InputPart inputPart = super.extractPart(bodyPart); relatedMap .put(inputPart.getHeaders().getFirst("Content-ID"), inputPart); return inputPart; }
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream, final MultipartRelatedInput xopPackage) throws IOException { try { LogMessages.LOGGER.debugf("Provider : %s, Method : readFrom", getClass().getName()); InputPart rootPart = xopPackage.getRootPart(); JAXBContext jaxb = findJAXBContext(type, annotations, rootPart .getMediaType(), true); Unmarshaller unmarshaller = jaxb.createUnmarshaller(); unmarshaller .setAttachmentUnmarshaller(new XopAttachmentUnmarshaller( xopPackage)); return unmarshaller.unmarshal(new StreamSource(rootPart.getBody( InputStream.class, null))); } catch (JAXBException e) { Response response = Response.serverError().build(); throw new WebApplicationException(e, response); } }
public static FilePart getFilePart(List<InputPart> parts) throws IOException { Objects.requireNonNull(parts); for (InputPart inputPart : parts) { String disposition = inputPart.getHeaders().getFirst("Content-Disposition"); if (disposition != null) { Optional<String> filenameHeader = Arrays.stream(disposition.split(";")) .filter(n -> n.trim().startsWith("filename")).findFirst(); if (filenameHeader.isPresent()) { String[] filenameTokens = filenameHeader.get().split("="); if (filenameTokens.length > 1) { String filename = filenameTokens[1].trim().replaceAll("\"", ""); if (!filename.isEmpty()) { return new FilePart(filename, inputPart.getBody(InputStream.class, null)); } } } } } return null; }
public static Map<String, Object> toMap(MultipartInput input) { Map<String, Object> result = new HashMap<>(); try { for (InputPart p : input.getParts()) { String name = MultipartUtils.extractName(p); if (name == null || name.startsWith("/") || name.contains("..")) { throw new ConcordApplicationException("Invalid attachment name: " + name); } if (name.endsWith(JSON_FIELD_SUFFIX)) { name = name.substring(0, name.length() - JSON_FIELD_SUFFIX.length()); Object v = objectMapper.readValue(p.getBodyAsString(), Object.class); result.put(name, v); } else if (p.getMediaType().isCompatible(MediaType.TEXT_PLAIN_TYPE)) { String currentValue = p.getBodyAsString().trim(); result.compute(name, (k, oldValue) -> computeStringMultipartEntry(oldValue, currentValue)); } else { result.put(name, p.getBody(InputStream.class, null)); } } return result; } catch (IOException e) { throw new ConcordApplicationException("Error parsing the request", e); } }
private static Map<String, String> getTextFormFields(final String format, final MultipartInput multipartInput, final Set<String> assetNames) throws IOException { Map<String, String> fields = new HashMap<>(); List<InputPart> fieldsParts = multipartInput.getParts().stream() .filter(part -> TEXT_PLAIN_TYPE.isCompatible(part.getMediaType())) .collect(toList()); for (InputPart inputPart : fieldsParts) { Optional<String> maybeContentDisposition = getContentDisposition(inputPart); if (maybeContentDisposition.isPresent()) { Optional<String> maybeFieldName = extractFieldName(format, maybeContentDisposition.get()); if (maybeFieldName.isPresent() && !assetNames.contains(maybeFieldName.get())) { fields.put(maybeFieldName.get(), inputPart.getBodyAsString()); } } } return fields; }
public String getContentType() { return inputPart.getMediaType().toString(); }
try { MultivaluedMap<String, String> headers = inputPart.getHeaders(); String[] contentDispositionHeader = headers.getFirst("Content-Disposition").split(";"); for (String name : contentDispositionHeader) { InputStream istream = inputPart.getBody(InputStream.class,null);
if (p.getMediaType().isCompatible(MediaType.TEXT_PLAIN_TYPE)) { String v = p.getBodyAsString().trim(); Map<String, Object> m = ConfigurationUtils.toNested(name, v); cfg = ConfigurationUtils.deepMerge(cfg, m); Path dst = baseDir.resolve(name); Files.createDirectories(dst.getParent()); try (InputStream in = p.getBody(InputStream.class, null); OutputStream out = Files.newOutputStream(dst)) { IOUtils.copy(in, out);
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream, final MultipartRelatedInput xopPackage) throws IOException { try { LogMessages.LOGGER.debugf("Provider : %s, Method : readFrom", getClass().getName()); InputPart rootPart = xopPackage.getRootPart(); JAXBContext jaxb = findJAXBContext(type, annotations, rootPart .getMediaType(), true); Unmarshaller unmarshaller = jaxb.createUnmarshaller(); unmarshaller .setAttachmentUnmarshaller(new XopAttachmentUnmarshaller( xopPackage)); return unmarshaller.unmarshal(new StreamSource(rootPart.getBody( InputStream.class, null))); } catch (JAXBException e) { Response response = Response.serverError().build(); throw new WebApplicationException(e, response); } }
public String getContentType() { return inputPart.getMediaType().toString(); }
public <T> T getFormDataPart(String key, GenericType<T> type) throws IOException { List<InputPart> list = getFormDataMap().get(key); if (list == null || list.isEmpty()) return null; InputPart part = list.get(0); if (part == null) return null; return part.getBody(type); }
MultivaluedMap<String, String> header = inputPart.getHeaders(); fileName = getFileName(header); String tmp = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date()); InputStream inputStream = inputPart.getBody(InputStream.class, null);
private static Map<String, InputStreamPartPayload> getAssetsPayloads(final String format, final MultipartInput multipartInput) throws IOException { Map<String, InputStreamPartPayload> payloads = new HashMap<>(); for (InputPart inputPart : multipartInput.getParts()) { Optional<String> maybeContentDisposition = getContentDisposition(inputPart); if (maybeContentDisposition.isPresent()) { String contentDisposition = maybeContentDisposition.get(); Optional<String> maybeFieldName = extractFieldName(format, contentDisposition); if (maybeFieldName.isPresent()) { String fieldName = maybeFieldName.get(); boolean isAsset = fieldName.matches(ASSET_NAME_REGEX); if (isAsset) { Optional<String> maybeFilename = extractFilename(contentDisposition); InputStream inputStream = inputPart.getBody(InputStream.class, null); String filename = maybeFilename.orElse(null); String contentType = inputPart.getMediaType().toString(); InputStreamPartPayload payload = new InputStreamPartPayload(filename, fieldName, inputStream, contentType); payloads.put(fieldName, payload); } } } } return payloads; }
public static String getParameter(List<InputPart> parts) { try { return parts.stream().filter(Objects::nonNull).findFirst().get().getBodyAsString(); } catch (IOException e) { LOGGER.error("Error reading parameter", e); } return null; }
private static Optional<String> getContentDisposition(final InputPart inputPart) { return Optional.ofNullable(inputPart.getHeaders().getFirst(CONTENT_DISPOSITION)); }
private String charset(final InputPart part) { return part.getMediaType().getParameters().get("charset"); //$NON-NLS-1$ }
public <T> T getFormDataPart(String key, Class<T> rawType, Type genericType) throws IOException { List<InputPart> list = getFormDataMap().get(key); if (list == null || list.isEmpty()) return null; InputPart part = list.get(0); if (part == null) return null; return part.getBody(rawType, genericType); }
String contentId = part.getHeaders().getFirst("Content-ID"); //$NON-NLS-1$ String path = contentId.substring(1, contentId.lastIndexOf('@')); HttpResponseBean rbean = part.getBody(HttpResponseBean.class, null); if (rbean.getCode() == 201) { Entry entry = (Entry) rbean.getBody();