Interface EntityPart

public interface EntityPart
A EntityPart is one part of a multipart entity. As defined in RFC 7578, a multipart request or response must have a content type of "multipart/form-data" with a boundary parameter indicating where one part ends the next may begin.

Multipart entities may be received in a resource method as a collection of parts (e.g. List<EntityPart>) or as a form parameter (ex: @FormParam("part1Name") EntityPart part1).

Likewise, a client may receive a multipart response by reading the returned entity as a collection of EntityParts (ex: response.readEntity(new GenericType<List<EntityPart>>() {})).

In order to send a multipart entity either as a client request or a response from a resource method, you may create the Lists using EntityPart.Builder. For example:

 Client c = ClientBuilder.newClient();
WebTarget target =;
List<EntityPart> parts = Arrays.asList(
     EntityPart.withName("name3").fileName("file3.xml").content(myObject, MyClass.class).mediaType("application/xml").build());
GenericEntity<List<EntityPart>> genericEntity = new GenericEntity<>(parts){};
Entity entity = Entity.entity(genericEntity, MediaType.MULTIPART_FORM_DATA);
Response r = target.request().post(entity);
Note that when building a EntityPart, the name and content are required. Other properties such as headers, file name, and media type are optional. It is the responsibility of the implementation code to close the content input streams when sending the multipart content. Closing the stream before the implementation has sent it could result in unexpected exceptions. It is the responsibility of the calling code to close the stream when receiving the multipart content.
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    static interface 
    Builder for EntityPart instances.
  • Method Summary

    Modifier and Type
    Returns the input stream for this part.
    <T> T
    Converts the content stream for this part to the specified type and returns it.
    <T> T
    getContent(Class<T> type)
    Converts the content stream for this part to the specified class and returns it.
    Returns the filename of this part.
    Returns an immutable multivalued map of headers for this specific part.
    Returns the content type of this part, and equivalent to calling MediaType.valueOf(part.getHeaders().getFirst(HttpHeaders.CONTENT_TYPE)).
    Returns the name of this part within the multipart entity.
    withFileName(String partAndFileName)
    Creates a new EntityPart.Builder instance that sets the part name and fileName to the passed in partAndFileName value.
    withName(String partName)
    Creates a new EntityPart.Builder instance.