private void extractHeaders() { if (part == null || extractedHeaders) return; MultivaluedMap<String, String> headers = part.getHeaders(); format = getHeaderFormat(headers); mimetype = getHeaderMimetype(headers); length = getHeaderLength(headers); extractedHeaders = true; } }
protected ClientResponse multipartPost(final WebResource resource, final Map<String, Object> fields, final Iterable<BodyPart> bodyParts) { final WebResource.Builder builder = resource.type(MediaType.MULTIPART_FORM_DATA_TYPE); final FormDataMultiPart multiPart = new FormDataMultiPart(); for(final Map.Entry<String, Object> fieldEntry : fields.entrySet()) { final FormDataBodyPart bp = new FormDataBodyPart(fieldEntry.getKey(), fieldEntry.getValue(), MediaType.APPLICATION_JSON_TYPE); multiPart.bodyPart(bp); } for(final BodyPart bodyPart : bodyParts) { bodyPart.setMediaType(MediaType.APPLICATION_OCTET_STREAM_TYPE); multiPart.bodyPart(bodyPart); } return builder.post(ClientResponse.class, multiPart); }
final ContentDisposition contentDisposition = bodyPart.getContentDisposition(); if (contentDisposition != null) { final Map<String, String> parameters = contentDisposition.getParameters(); if ("photo".equals(name)) { final BodyPartEntity bodyPartEntity = (BodyPartEntity)bodyPart.getEntity(); photoBytes = IOUtils.toByteArray(bodyPartEntity.getInputStream()); jsonMetadata = bodyPart.getEntityAs(String.class);
final MediaType bodyMediaType = bodyPart.getMediaType(); if (bodyMediaType == null) { throw new WebApplicationException(new IllegalArgumentException("Missing body part media type")); final MultivaluedMap<String, String> bodyHeaders = bodyPart.getHeaders(); bodyHeaders.putSingle("Content-Type", bodyMediaType.toString()); && bodyPart.getContentDisposition() != null) { bodyHeaders.putSingle("Content-Disposition", bodyPart.getContentDisposition().toString()); Object bodyEntity = bodyPart.getEntity(); if (bodyEntity == null) { throw new WebApplicationException(
@Override public Void call() throws Exception { final MultiPart multiPartInput = new MultiPart(); for (AttachmentInput attachment : myAttachments) { BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder = FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME); dispositionBuilder.fileName(attachment.getFilename()); final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build(); bp.setContentDisposition(formDataContentDisposition); multiPartInput.bodyPart(bp); } postFileMultiPart(multiPartInput, attachmentsUri); return null; }
.getHeaders(); if (isExternalDescriptor(desc)) { updateVersion(desc, responseHeaders); metadataBase.receiveContent(partList.get(0).getEntityAs( metadataBase.receiveAs())); Object contentEntity = contentPart.getEntityAs(contentBase.receiveAs()); contentBase.receiveContent((reqlog != null) ? reqlog .copyContent(contentEntity) : contentEntity);
@Override public <R extends AbstractReadHandle> R getContent(R handle) { if (part == null) throw new IllegalStateException("Content already retrieved"); HandleImplementation handleBase = HandleAccessor.as(handle); extractHeaders(); updateFormat(handleBase, format); updateMimetype(handleBase, mimetype); updateLength(handleBase, length); Object contentEntity = part.getEntityAs(handleBase.receiveAs()); handleBase.receiveContent((reqlog != null) ? reqlog .copyContent(contentEntity) : contentEntity); part = null; reqlog = null; return handle; }
final ContentDisposition contentDisposition = bodyPart.getContentDisposition(); if (contentDisposition != null) { final Map<String, String> parameters = contentDisposition.getParameters(); if ("photo".equals(name)) { final BodyPartEntity bodyPartEntity = (BodyPartEntity)bodyPart.getEntity(); photoBytes = IOUtils.toByteArray(bodyPartEntity.getInputStream()); jsonMetadata = bodyPart.getEntityAs(String.class);
@Override public Void call() throws Exception { final MultiPart multiPartInput = new MultiPart(); for (AttachmentInput attachment : myAttachments) { BodyPart bp = new BodyPart(attachment.getInputStream(), MediaType.APPLICATION_OCTET_STREAM_TYPE); FormDataContentDisposition.FormDataContentDispositionBuilder dispositionBuilder = FormDataContentDisposition.name(FILE_ATTACHMENT_CONTROL_NAME); dispositionBuilder.fileName(attachment.getFilename()); final FormDataContentDisposition formDataContentDisposition = dispositionBuilder.build(); bp.setContentDisposition(formDataContentDisposition); multiPartInput.bodyPart(bp); } postFileMultiPart(multiPartInput, attachmentsUri); return null; }