@POST @Path("upload2") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFileAndJSON(@FormDataParam("emp") FormDataBodyPart jsonPart, @FormDataParam("file") FormDataBodyPart bodyPart) { jsonPart.setMediaType(MediaType.APPLICATION_JSON_TYPE); Employee emp = jsonPart.getValueAs(Employee.class); }
/** * Sets the field media type and value for this body part. * * @param mediaType the media type for this field value. * @param value the field value as a Java object. */ public void setValue(MediaType mediaType, Object value) { setMediaType(mediaType); setEntity(value); }
/** * Allows to explicitly set the value and the MIME type of the body part * entity. This method doesn't have to be invoked if one of the non-default * constructors was already called. * <p/> * Either this method or {@link StreamDataBodyPart#setStreamEntity(InputStream)} * <strong>must</strong> be invoked if the default constructor was called. * * @param streamEntity entity to be set as a body part. * @param mediaType MIME type of the {@code streamEntity} attachment. */ public void setStreamEntity(final InputStream streamEntity, MediaType mediaType) { if (streamEntity == null) { throw new IllegalArgumentException("Stream body part entity cannot be null."); } if (mediaType == null) { mediaType = getDefaultMediaType(); } this.streamEntity = streamEntity; // Be sure to hit the parent (non-overloaded) method. super.setMediaType(mediaType); super.setEntity(streamEntity); setFormDataContentDisposition(buildContentDisposition()); }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
@POST @Path("somepath") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response uploadFileAndJSON(@FormDataParam("model") FormDataBodyPart jsonPart, @FormDataParam("file") FormDataBodyPart bodyPart) { jsonPart.setMediaType(MediaType.APPLICATION_JSON_TYPE); SomeModel model = jsonPart.getValueAs(SomeModel.class); }
/** * Sets the field media type and value for this body part. * * @param mediaType the media type for this field value. * @param value the field value as a Java object. */ public void setValue(MediaType mediaType, Object value) { setMediaType(mediaType); setEntity(value); }
/** * Sets the field media type and value for this body part. * * @param mediaType the media type for this field value. * @param value the field value as a Java object. */ public void setValue(MediaType mediaType, Object value) { setMediaType(mediaType); setEntity(value); }
/** * Sets the field media type and value for this body part. * * @param mediaType the media type for this field value. * @param value the field value as a Java object. */ public void setValue(MediaType mediaType, Object value) { setMediaType(mediaType); setEntity(value); }
/** * Sets the field media type and value for this body part. * * @param mediaType the media type for this field value. * @param value the field value as a Java object. */ public void setValue(MediaType mediaType, Object value) { setMediaType(mediaType); setEntity(value); }
@POST @Path("no-content-type") public Bean[] post2(@FormDataParam("beans") FormDataBodyPart bodyPart) throws IOException { bodyPart.setMediaType(MediaType.APPLICATION_JSON_TYPE); Bean[] beans = bodyPart.getEntityAs(Bean[].class); return beans; }
@POST @Path("/upload1") @Consumes(MediaType.MULTIPART_FORM_DATA) public Response createFile1(@FormDataParam("doc") FormDataBodyPart part) { part.setMediaType(MediaType.APPLICATION_JSON_TYPE); Test doc = part.getValueAs(Test.class); return Response.ok(doc.getName()).build(); }
/** * Allows to explicitly set the value and the MIME type of the body part * entity. This method doesn't have to be invoked if one of the non-default * constructors was already called. * <p/> * Either this method or {@link StreamDataBodyPart#setStreamEntity(InputStream)} * <strong>must</strong> be invoked if the default constructor was called. * * @param streamEntity entity to be set as a body part. * @param mediaType MIME type of the {@code streamEntity} attachment. */ public void setStreamEntity(final InputStream streamEntity, MediaType mediaType) { if (streamEntity == null) { throw new IllegalArgumentException("Stream body part entity cannot be null."); } if (mediaType == null) { mediaType = getDefaultMediaType(); } this.streamEntity = streamEntity; // Be sure to hit the parent (non-overloaded) method. super.setMediaType(mediaType); super.setEntity(streamEntity); setFormDataContentDisposition(buildContentDisposition()); }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Sets the {@link MediaType} and fileEntity for this {@link FormDataBodyPart}. * * @param fileEntity the entity of this body part. * @param mediaType the media type. */ public void setFileEntity(final File fileEntity, final MediaType mediaType) { super.setMediaType(mediaType); super.setEntity(fileEntity); this.fileEntity = fileEntity; if (fileEntity != null) { FormDataContentDisposition.FormDataContentDispositionBuilder builder = FormDataContentDisposition.name(getName()); builder.fileName(fileEntity.getName()); if (fileEntity.exists()) { builder.size(fileEntity.length()); builder.modificationDate(new Date(fileEntity.lastModified())); } setFormDataContentDisposition(builder.build()); } }
/** * Allows to explicitly set the value and the MIME type of the body part * entity. This method doesn't have to be invoked if one of the non-default * constructors was already called. * <p/> * Either this method or {@link StreamDataBodyPart#setStreamEntity(InputStream)} * <strong>must</strong> be invoked if the default constructor was called. * * @param streamEntity entity to be set as a body part. * @param mediaType MIME type of the {@code streamEntity} attachment. */ public void setStreamEntity(final InputStream streamEntity, MediaType mediaType) { if (streamEntity == null) { throw new IllegalArgumentException("Stream body part entity cannot be null."); } if (mediaType == null) { mediaType = getDefaultMediaType(); } this.streamEntity = streamEntity; // Be sure to hit the parent (non-overloaded) method. super.setMediaType(mediaType); super.setEntity(streamEntity); setFormDataContentDisposition(buildContentDisposition()); }
/** * Allows to explicitly set the value and the MIME type of the body part * entity. This method doesn't have to be invoked if one of the non-default * constructors was already called. * <p/> * Either this method or {@link StreamDataBodyPart#setStreamEntity(InputStream)} * <strong>must</strong> be invoked if the default constructor was called. * * @param streamEntity entity to be set as a body part. * @param mediaType MIME type of the {@code streamEntity} attachment. */ public void setStreamEntity(final InputStream streamEntity, MediaType mediaType) { if (streamEntity == null) { throw new IllegalArgumentException("Stream body part entity cannot be null."); } if (mediaType == null) { mediaType = getDefaultMediaType(); } this.streamEntity = streamEntity; // Be sure to hit the parent (non-overloaded) method. super.setMediaType(mediaType); super.setEntity(streamEntity); setFormDataContentDisposition(buildContentDisposition()); }
/** * Allows to explicitly set the value and the MIME type of the body part * entity. This method doesn't have to be invoked if one of the non-default * constructors was already called. * <p/> * Either this method or {@link StreamDataBodyPart#setStreamEntity(InputStream)} * <strong>must</strong> be invoked if the default constructor was called. * * @param streamEntity entity to be set as a body part. * @param mediaType MIME type of the {@code streamEntity} attachment. */ public void setStreamEntity(final InputStream streamEntity, MediaType mediaType) { if (streamEntity == null) { throw new IllegalArgumentException("Stream body part entity cannot be null."); } if (mediaType == null) { mediaType = getDefaultMediaType(); } this.streamEntity = streamEntity; // Be sure to hit the parent (non-overloaded) method. super.setMediaType(mediaType); super.setEntity(streamEntity); setFormDataContentDisposition(buildContentDisposition()); }
@Path("no-content-type") public Bean[] post2(@FormDataParam("beans") FormDataBodyPart bodyPart) throws IOException { bodyPart.setMediaType(MediaType.APPLICATION_JSON_TYPE); Bean[] beans = bodyPart.getEntityAs(Bean[].class); return beans;