Refine search
final MultiPart multiPart = formData ? new FormDataMultiPart() : new MultiPart(); multiPart.setMessageBodyWorkers(workers); final MultivaluedMap<String, String> multiPartHeaders = multiPart.getHeaders(); for (final Map.Entry<String, List<String>> entry : headers.entrySet()) { final List<String> values = entry.getValue(); final BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart(); bodyPart.setMessageBodyWorkers(workers); bodyPart.getHeaders().add(header.getName(), header.getValue()); final String contentType = bodyPart.getHeaders().getFirst("Content-Type"); if (contentType != null) { bodyPart.setMediaType(MediaType.valueOf(contentType)); bodyPart.getContentDisposition(); } catch (final IllegalArgumentException ex) { throw new BadRequestException(ex); bodyPart.setEntity(new BodyPartEntity(mimePart));
if ((entity.getBodyParts() == null) || (entity.getBodyParts().size() < 1)) { throw new IllegalArgumentException(LocalizationMessages.MUST_SPECIFY_BODY_PART()); if (entity.getParent() == null) { final Object value = headers.getFirst("MIME-Version"); if (value == null) { final MediaType bodyMediaType = bodyPart.getMediaType(); if (bodyMediaType == null) { throw new IllegalArgumentException(LocalizationMessages.MISSING_MEDIA_TYPE_OF_BODY_PART()); final MultivaluedMap<String, String> bodyHeaders = bodyPart.getHeaders(); bodyHeaders.putSingle("Content-Type", bodyMediaType.toString()); if (bodyHeaders.getFirst("Content-Disposition") == null && bodyPart.getContentDisposition() != null) { bodyHeaders.putSingle("Content-Disposition", bodyPart.getContentDisposition().toString()); Object bodyEntity = bodyPart.getEntity(); if (bodyEntity == null) { throw new IllegalArgumentException(LocalizationMessages.MISSING_ENTITY_OF_BODY_PART(bodyMediaType));
/** * Performs any necessary cleanup at the end of processing this * {@link MultiPart}. */ @Override public void cleanup() { for (BodyPart bp : getBodyParts()) { bp.cleanup(); } }
/** * Instantiates a new {@code BodyPart} with the specified characteristics. * * @param entity entity for this body part. * @param mediaType {@link MediaType} for this body part. */ public BodyPart(final Object entity, final MediaType mediaType) { setEntity(entity); setMediaType(mediaType); }
formData = true; } else { multiPart = new MultiPart(); multiPart.setProviders(providers); multiPart.setMediaType(mediaType); bodyPart = new FormDataBodyPart(); } else { bodyPart = new BodyPart(); bodyPart.setProviders(providers); bodyPart.getHeaders().add(h.getName(), getFixedHeaderValue(h)); String contentType = bodyPart.getHeaders().getFirst("Content-Type"); bodyPart.setMediaType(MediaType.valueOf(contentType)); bodyPart.getContentDisposition(); } catch (IllegalArgumentException ex) { logger.error( "readFrom error", ex ); bodyPart.setEntity(new BodyPartEntity(mp)); multiPart.getBodyParts().add(bodyPart);
/** * Builder pattern method to add a newly configured {@link BodyPart} * to this {@link MultiPart}. * * @param entity entity object for this body part. * @param mediaType content type for this body part. */ public MultiPart bodyPart(Object entity, MediaType mediaType) { BodyPart bodyPart = new BodyPart(entity, mediaType); return bodyPart(bodyPart); }
final MultiPart multiPartEntity = new MultiPart() .bodyPart(new BodyPart().entity("hello")) .bodyPart(new BodyPart(new JaxbBean("xml"), MediaType.APPLICATION_XML_TYPE)) .bodyPart(new BodyPart(new JaxbBean("json"), MediaType.APPLICATION_JSON_TYPE)); final WebTarget target = // Create WebTarget. final Response response = target .request() .post(Entity.entity(multiPartEntity, multiPartEntity.getMediaType()));
@POST @Consumes(MultiPartMediaTypes.MULTIPART_MIXED) public Response post(MultiPart multiPart) { for(BodyPart part : multiPart.getBodyParts()) { System.out.println(part.getMediaType()); } return Response.status(Response.Status.ACCEPTED). entity("Attachements processed successfully."). type(MediaType.TEXT_PLAIN).build(); }
/** * Builder pattern method to return this {@code BodyPart} after additional configuration. * * @param type media type to set for this {@code BodyPart}. * @return body-part instance. */ public BodyPart type(final MediaType type) { setMediaType(type); return this; }
/** * Sets the form data content disposition. * * @param formDataContentDisposition the form data content disposition. */ public void setFormDataContentDisposition(FormDataContentDisposition formDataContentDisposition) { super.setContentDisposition(formDataContentDisposition); }
@POST @Path("upload") @Produces(MediaType.TEXT_PLAIN) @Consumes(MediaType.MULTIPART_FORM_DATA) public String uploadMultipleFile( FormDataMultiPart multiform) { BodyPartEntity bodyPartEntity; String uploadedFileLocation; for(BodyPart part: multiform.getBodyParts()){ bodyPartEntity = (BodyPartEntity) part.getEntity(); uploadedFileLocation = "c://test/" + part.getContentDisposition().getFileName(); saveToFile(bodyPartEntity.getInputStream(), uploadedFileLocation); } return "OK"; }
@POST @Consumes(MediaType.MULTIPART_FORM_DATA) public void uploadMultiple(@FormDataParam("file") FormDataBodyPart body){ for(BodyPart part : body.getParent().getBodyParts()){ InputStream is = part.getEntityAs(InputStream.class); ContentDisposition meta = part.getContentDisposition(); doUpload(is, meta); } }
/** * Builder pattern method to return this {@code BodyPart} after additional configuration. * * @param entity entity to set for this {@code BodyPart}. * @return body-part instance. */ public BodyPart entity(final Object entity) { setEntity(entity); return this; }
private boolean fileHasCSVExtension(BodyPart bodyPart) { ContentDisposition contentDisposition = bodyPart.getContentDisposition(); return contentDisposition != null && contentDisposition.getFileName() != null && contentDisposition .getFileName().endsWith(".csv"); }
private MediaType determinePartContentType( Object parameter ) { // TODO: how to get the media type? we could use something like @FormData if( parameter instanceof BodyPart ) { return ( ( BodyPart )parameter ).getMediaType(); } if( parameter instanceof ContentDisposition ) { return MediaType.valueOf( ( ( ContentDisposition )parameter ).getType() ); } return MediaType.TEXT_PLAIN_TYPE; }
function BodyPart(name) { this.name = name; this.test = function() { alert('called test'); } this.geometry = new THREE.BoxGeometry(1, 1, 1); this.material = new THREE.MeshNormalMaterial({ color: 0x00ff00 }); this.mesh = new THREE.Mesh(this.geometry, this.material); //Now, as a property instead of returning. } var backFoot = new BodyPart("Back foot"); alert("calling test"); backFoot.test(); //Access the mesh with backFoot.mesh
/** * Builder pattern method to add a newly configured {@link BodyPart} * to this {@link MultiPart}. * * @param entity entity object for this body part. * @param mediaType content type for this body part. */ public MultiPart bodyPart(Object entity, MediaType mediaType) { BodyPart bodyPart = new BodyPart(entity, mediaType); return bodyPart(bodyPart); }
/** * Instantiates a new {@code BodyPart} with the specified characteristics. * * @param entity entity for this body part. * @param mediaType {@link MediaType} for this body part. */ public BodyPart(final Object entity, final MediaType mediaType) { setEntity(entity); setMediaType(mediaType); }