Class BodyPart
- java.lang.Object
-
- org.glassfish.jersey.media.multipart.BodyPart
-
- Direct Known Subclasses:
FormDataBodyPart,MultiPart
public class BodyPart extends Object
A mutable model representing a body part nested inside a MIME MultiPart entity.- Author:
- Craig McClanahan, Paul Sandoz, Michal Gajdos
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentDispositioncontentDispositionMessageBodyWorkersmessageBodyWorkers
-
Constructor Summary
Constructors Constructor Description BodyPart()Instantiates a newBodyPartwith amediaTypeoftext/plain.BodyPart(jakarta.ws.rs.core.MediaType mediaType)Instantiates a newBodyPartwith the specified characteristics.BodyPart(Object entity, jakarta.ws.rs.core.MediaType mediaType)Instantiates a newBodyPartwith the specified characteristics.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidcleanup()Perform any necessary cleanup at the end of processing thisBodyPart.BodyPartcontentDisposition(ContentDisposition contentDisposition)Builder pattern method to return thisBodyPartafter additional configuration.BodyPartentity(Object entity)Builder pattern method to return thisBodyPartafter additional configuration.ContentDispositiongetContentDisposition()Gets the content disposition.ObjectgetEntity()Returns the entity object to be unmarshalled from a request, or to be marshalled on a response.<T> TgetEntityAs(Class<T> clazz)Returns the entity after appropriate conversion to the requested type.jakarta.ws.rs.core.MultivaluedMap<String,String>getHeaders()Returns a mutable map of HTTP header value(s) for thisBodyPart, keyed by the header name.jakarta.ws.rs.core.MediaTypegetMediaType()Returns theMediaTypefor thisBodyPart.jakarta.ws.rs.core.MultivaluedMap<String,ParameterizedHeader>getParameterizedHeaders()Returns an immutable map of parameterized HTTP header value(s) for thisBodyPart, keyed by header name.MultiPartgetParent()Returns the parentMultiPart(if any) for thisBodyPart.jakarta.ws.rs.ext.ProvidersgetProviders()Returns the configuredProvidersfor thisBodyPart.voidsetContentDisposition(ContentDisposition contentDisposition)Sets the content disposition.voidsetEntity(Object entity)Set the entity object to be unmarshalled from a request, or to be marshalled on a response.voidsetMediaType(jakarta.ws.rs.core.MediaType mediaType)Sets theMediaTypefor thisBodyPart.voidsetMessageBodyWorkers(MessageBodyWorkers messageBodyWorkers)Set message body workers used to transform an entity stream into particular Java type.voidsetParent(MultiPart parent)Sets the parentMultiPart(if any) for thisBodyPart.voidsetProviders(jakarta.ws.rs.ext.Providers providers)Sets the configuredProvidersfor thisBodyPart.BodyParttype(jakarta.ws.rs.core.MediaType type)Builder pattern method to return thisBodyPartafter additional configuration.
-
-
-
Field Detail
-
contentDisposition
protected ContentDisposition contentDisposition
-
messageBodyWorkers
public MessageBodyWorkers messageBodyWorkers
-
-
Constructor Detail
-
BodyPart
public BodyPart()
Instantiates a newBodyPartwith amediaTypeoftext/plain.
-
BodyPart
public BodyPart(jakarta.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPartwith the specified characteristics.- Parameters:
mediaType-MediaTypefor this body part.
-
BodyPart
public BodyPart(Object entity, jakarta.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPartwith the specified characteristics.- Parameters:
entity- entity for this body part.mediaType-MediaTypefor this body part.
-
-
Method Detail
-
getEntity
public Object getEntity()
Returns the entity object to be unmarshalled from a request, or to be marshalled on a response.- Returns:
- an entity of this body part.
- Throws:
IllegalStateException- if this method is called on aMultiPartinstance; access the underlyingBodyParts instead
-
setEntity
public void setEntity(Object entity)
Set the entity object to be unmarshalled from a request, or to be marshalled on a response.- Parameters:
entity- the new entity object.- Throws:
IllegalStateException- if this method is called on aMultiPartinstance; access the underlyingBodyParts instead
-
getHeaders
public jakarta.ws.rs.core.MultivaluedMap<String,String> getHeaders()
Returns a mutable map of HTTP header value(s) for thisBodyPart, keyed by the header name. Key comparisons in the returned map must be case-insensitive. Note: MIME specifications says only headers that matchContent-*should be included on aBodyPart.- Returns:
- mutable map of HTTP header values.
-
getParameterizedHeaders
public jakarta.ws.rs.core.MultivaluedMap<String,ParameterizedHeader> getParameterizedHeaders() throws ParseException
Returns an immutable map of parameterized HTTP header value(s) for thisBodyPart, keyed by header name. Key comparisons in the returned map must be case-insensitive. If you wish to modify the headers map for thisBodyPart, modify the map returned bygetHeaders()instead.- Returns:
- immutable map of HTTP header values.
- Throws:
ParseException- if an un-expected/in-correct value is found during parsing the headers.
-
getContentDisposition
public ContentDisposition getContentDisposition()
Gets the content disposition. The "Content-Disposition" header, if present, will be parsed.- Returns:
- the content disposition, will be null if not present.
- Throws:
IllegalArgumentException- if the content disposition header cannot be parsed.
-
setContentDisposition
public void setContentDisposition(ContentDisposition contentDisposition)
Sets the content disposition.- Parameters:
contentDisposition- the content disposition.
-
getMediaType
public jakarta.ws.rs.core.MediaType getMediaType()
Returns theMediaTypefor thisBodyPart. If not set, the defaultMediaTypeMUST betext/plain.- Returns:
- media type for this body part.
-
setMediaType
public void setMediaType(jakarta.ws.rs.core.MediaType mediaType)
Sets theMediaTypefor thisBodyPart.- Parameters:
mediaType- the newMediaType.- Throws:
IllegalArgumentException- if themediaTypeisnull.
-
getParent
public MultiPart getParent()
Returns the parentMultiPart(if any) for thisBodyPart.- Returns:
- parent of this body type,
nullif not set.
-
setParent
public void setParent(MultiPart parent)
Sets the parentMultiPart(if any) for thisBodyPart.- Parameters:
parent- the new parent.
-
getProviders
public jakarta.ws.rs.ext.Providers getProviders()
Returns the configuredProvidersfor thisBodyPart.- Returns:
- providers of this body part.
-
setProviders
public void setProviders(jakarta.ws.rs.ext.Providers providers)
Sets the configuredProvidersfor thisBodyPart.- Parameters:
providers- the newProviders.
-
cleanup
public void cleanup()
Perform any necessary cleanup at the end of processing thisBodyPart.
-
entity
public BodyPart entity(Object entity)
Builder pattern method to return thisBodyPartafter additional configuration.- Parameters:
entity- entity to set for thisBodyPart.- Returns:
- body-part instance.
-
getEntityAs
public <T> T getEntityAs(Class<T> clazz)
Returns the entity after appropriate conversion to the requested type. This is useful only when the containingMultiPartinstance has been received, which causes theprovidersproperty to have been set.- Parameters:
clazz- desired class into which the entity should be converted.- Returns:
- entity after appropriate conversion to the requested type.
- Throws:
jakarta.ws.rs.ProcessingException- if an IO error arises during reading an entity.IllegalArgumentException- if noMessageBodyReadercan be found to perform the requested conversion.IllegalStateException- if this method is called when theprovidersproperty has not been set or when the entity instance is not the unconverted content of the body part entity.
-
type
public BodyPart type(jakarta.ws.rs.core.MediaType type)
Builder pattern method to return thisBodyPartafter additional configuration.- Parameters:
type- media type to set for thisBodyPart.- Returns:
- body-part instance.
-
contentDisposition
public BodyPart contentDisposition(ContentDisposition contentDisposition)
Builder pattern method to return thisBodyPartafter additional configuration.- Parameters:
contentDisposition- content disposition to set for thisBodyPart.- Returns:
- body-part instance.
-
setMessageBodyWorkers
public void setMessageBodyWorkers(MessageBodyWorkers messageBodyWorkers)
Set message body workers used to transform an entity stream into particular Java type.- Parameters:
messageBodyWorkers- message body workers.
-
-