Class BodyPart
- java.lang.Object
-
- org.glassfish.jersey.media.multipart.BodyPart
-
- Direct Known Subclasses:
FormDataBodyPart
,MultiPart
public class BodyPart extends java.lang.Object
A mutable model representing a body part nested inside a MIME MultiPart entity.
-
-
Field Summary
Fields Modifier and Type Field Description protected ContentDisposition
contentDisposition
private java.lang.Object
entity
private javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>
headers
private javax.ws.rs.core.MediaType
mediaType
Media type of this body part.MessageBodyWorkers
messageBodyWorkers
private MultiPart
parent
Parent of this body part.private javax.ws.rs.ext.Providers
providers
-
Constructor Summary
Constructors Constructor Description BodyPart()
Instantiates a newBodyPart
with amediaType
oftext/plain
.BodyPart(java.lang.Object entity, javax.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPart
with the specified characteristics.BodyPart(javax.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPart
with the specified characteristics.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanup()
Perform any necessary cleanup at the end of processing thisBodyPart
.BodyPart
contentDisposition(ContentDisposition contentDisposition)
Builder pattern method to return thisBodyPart
after additional configuration.BodyPart
entity(java.lang.Object entity)
Builder pattern method to return thisBodyPart
after additional configuration.ContentDisposition
getContentDisposition()
Gets the content disposition.java.lang.Object
getEntity()
Returns the entity object to be unmarshalled from a request, or to be marshalled on a response.<T> T
getEntityAs(java.lang.Class<T> clazz)
Returns the entity after appropriate conversion to the requested type.javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>
getHeaders()
Returns a mutable map of HTTP header value(s) for thisBodyPart
, keyed by the header name.javax.ws.rs.core.MediaType
getMediaType()
Returns theMediaType
for thisBodyPart
.javax.ws.rs.core.MultivaluedMap<java.lang.String,ParameterizedHeader>
getParameterizedHeaders()
Returns an immutable map of parameterized HTTP header value(s) for thisBodyPart
, keyed by header name.MultiPart
getParent()
Returns the parentMultiPart
(if any) for thisBodyPart
.javax.ws.rs.ext.Providers
getProviders()
Returns the configuredProviders
for thisBodyPart
.void
setContentDisposition(ContentDisposition contentDisposition)
Sets the content disposition.void
setEntity(java.lang.Object entity)
Set the entity object to be unmarshalled from a request, or to be marshalled on a response.void
setMediaType(javax.ws.rs.core.MediaType mediaType)
Sets theMediaType
for thisBodyPart
.void
setMessageBodyWorkers(MessageBodyWorkers messageBodyWorkers)
Set message body workers used to transform an entity stream into particular Java type.void
setParent(MultiPart parent)
Sets the parentMultiPart
(if any) for thisBodyPart
.void
setProviders(javax.ws.rs.ext.Providers providers)
Sets the configuredProviders
for thisBodyPart
.BodyPart
type(javax.ws.rs.core.MediaType type)
Builder pattern method to return thisBodyPart
after additional configuration.
-
-
-
Field Detail
-
contentDisposition
protected ContentDisposition contentDisposition
-
entity
private java.lang.Object entity
-
headers
private final javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers
-
mediaType
private javax.ws.rs.core.MediaType mediaType
Media type of this body part.
-
messageBodyWorkers
public MessageBodyWorkers messageBodyWorkers
-
parent
private MultiPart parent
Parent of this body part.
-
providers
private javax.ws.rs.ext.Providers providers
-
-
Constructor Detail
-
BodyPart
public BodyPart()
Instantiates a newBodyPart
with amediaType
oftext/plain
.
-
BodyPart
public BodyPart(javax.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPart
with the specified characteristics.- Parameters:
mediaType
-MediaType
for this body part.
-
BodyPart
public BodyPart(java.lang.Object entity, javax.ws.rs.core.MediaType mediaType)
Instantiates a newBodyPart
with the specified characteristics.- Parameters:
entity
- entity for this body part.mediaType
-MediaType
for this body part.
-
-
Method Detail
-
getEntity
public java.lang.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:
java.lang.IllegalStateException
- if this method is called on aMultiPart
instance; access the underlyingBodyPart
s instead
-
setEntity
public void setEntity(java.lang.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:
java.lang.IllegalStateException
- if this method is called on aMultiPart
instance; access the underlyingBodyPart
s instead
-
getHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.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 javax.ws.rs.core.MultivaluedMap<java.lang.String,ParameterizedHeader> getParameterizedHeaders() throws java.text.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:
java.text.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:
java.lang.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 javax.ws.rs.core.MediaType getMediaType()
Returns theMediaType
for thisBodyPart
. If not set, the defaultMediaType
MUST betext/plain
.- Returns:
- media type for this body part.
-
setMediaType
public void setMediaType(javax.ws.rs.core.MediaType mediaType)
Sets theMediaType
for thisBodyPart
.- Parameters:
mediaType
- the newMediaType
.- Throws:
java.lang.IllegalArgumentException
- if themediaType
isnull
.
-
getParent
public MultiPart getParent()
Returns the parentMultiPart
(if any) for thisBodyPart
.- Returns:
- parent of this body type,
null
if not set.
-
setParent
public void setParent(MultiPart parent)
Sets the parentMultiPart
(if any) for thisBodyPart
.- Parameters:
parent
- the new parent.
-
getProviders
public javax.ws.rs.ext.Providers getProviders()
Returns the configuredProviders
for thisBodyPart
.- Returns:
- providers of this body part.
-
setProviders
public void setProviders(javax.ws.rs.ext.Providers providers)
Sets the configuredProviders
for thisBodyPart
.- Parameters:
providers
- the newProviders
.
-
cleanup
public void cleanup()
Perform any necessary cleanup at the end of processing thisBodyPart
.
-
entity
public BodyPart entity(java.lang.Object entity)
Builder pattern method to return thisBodyPart
after additional configuration.- Parameters:
entity
- entity to set for thisBodyPart
.- Returns:
- body-part instance.
-
getEntityAs
public <T> T getEntityAs(java.lang.Class<T> clazz)
Returns the entity after appropriate conversion to the requested type. This is useful only when the containingMultiPart
instance has been received, which causes theproviders
property 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:
javax.ws.rs.ProcessingException
- if an IO error arises during reading an entity.java.lang.IllegalArgumentException
- if noMessageBodyReader
can be found to perform the requested conversion.java.lang.IllegalStateException
- if this method is called when theproviders
property has not been set or when the entity instance is not the unconverted content of the body part entity.
-
type
public BodyPart type(javax.ws.rs.core.MediaType type)
Builder pattern method to return thisBodyPart
after 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 thisBodyPart
after 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.
-
-