org.glassfish.jersey.media.multipart
Class BodyPart

java.lang.Object
  extended by 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 (paul.sandoz at oracle.com), Michal Gajdos (michal.gajdos at oracle.com)

Field Summary
protected  ContentDisposition contentDisposition
           
 org.glassfish.jersey.message.MessageBodyWorkers messageBodyWorkers
           
 
Constructor Summary
BodyPart()
          Instantiates a new BodyPart with a mediaType of text/plain.
BodyPart(javax.ws.rs.core.MediaType mediaType)
          Instantiates a new BodyPart with the specified characteristics.
BodyPart(Object entity, javax.ws.rs.core.MediaType mediaType)
          Instantiates a new BodyPart with the specified characteristics.
 
Method Summary
 void cleanup()
          Perform any necessary cleanup at the end of processing this BodyPart.
 BodyPart contentDisposition(ContentDisposition contentDisposition)
          Builder pattern method to return this BodyPart after additional configuration.
 BodyPart entity(Object entity)
          Builder pattern method to return this BodyPart after additional configuration.
 ContentDisposition getContentDisposition()
          Gets the content disposition.
 Object getEntity()
          Returns the entity object to be unmarshalled from a request, or to be marshalled on a response.
<T> T
getEntityAs(Class<T> clazz)
          Returns the entity after appropriate conversion to the requested type.
 javax.ws.rs.core.MultivaluedMap<String,String> getHeaders()
          Returns a mutable map of HTTP header value(s) for this BodyPart, keyed by the header name.
 javax.ws.rs.core.MediaType getMediaType()
          Returns the MediaType for this BodyPart.
 javax.ws.rs.core.MultivaluedMap<String,org.glassfish.jersey.message.internal.ParameterizedHeader> getParameterizedHeaders()
          Returns an immutable map of parameterized HTTP header value(s) for this BodyPart, keyed by header name.
 MultiPart getParent()
          Returns the parent MultiPart (if any) for this BodyPart.
 javax.ws.rs.ext.Providers getProviders()
          Returns the configured Providers for this BodyPart.
 void setContentDisposition(ContentDisposition contentDisposition)
          Sets the content disposition.
 void setEntity(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 the MediaType for this BodyPart.
 void setMessageBodyWorkers(org.glassfish.jersey.message.MessageBodyWorkers messageBodyWorkers)
           
 void setParent(MultiPart parent)
          Sets the parent MultiPart (if any) for this BodyPart.
 void setProviders(javax.ws.rs.ext.Providers providers)
          Sets the configured Providers for this BodyPart.
 BodyPart type(javax.ws.rs.core.MediaType type)
          Builder pattern method to return this BodyPart after additional configuration.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

contentDisposition

protected ContentDisposition contentDisposition

messageBodyWorkers

public org.glassfish.jersey.message.MessageBodyWorkers messageBodyWorkers
Constructor Detail

BodyPart

public BodyPart()
Instantiates a new BodyPart with a mediaType of text/plain.


BodyPart

public BodyPart(javax.ws.rs.core.MediaType mediaType)
Instantiates a new BodyPart with the specified characteristics.

Parameters:
mediaType - MediaType for this body part.

BodyPart

public BodyPart(Object entity,
                javax.ws.rs.core.MediaType mediaType)
Instantiates a new BodyPart with the specified characteristics.

Parameters:
entity - entity for this body part.
mediaType - MediaType for 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.

Throws:
IllegalStateException - if this method is called on a MultiPart instance; access the underlying BodyParts 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 a MultiPart instance; access the underlying BodyParts instead

getHeaders

public javax.ws.rs.core.MultivaluedMap<String,String> getHeaders()
Returns a mutable map of HTTP header value(s) for this BodyPart, keyed by the header name. Key comparisons in the returned map must be case-insensitive.

Note: MIME specifications says only headers that match Content-* should be included on a BodyPart.


getParameterizedHeaders

public javax.ws.rs.core.MultivaluedMap<String,org.glassfish.jersey.message.internal.ParameterizedHeader> getParameterizedHeaders()
                                                                                                                          throws ParseException
Returns an immutable map of parameterized HTTP header value(s) for this BodyPart, keyed by header name. Key comparisons in the returned map must be case-insensitive. If you wish to modify the headers map for this BodyPart, modify the map returned by getHeaders() instead.

Throws:
ParseException

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 javax.ws.rs.core.MediaType getMediaType()
Returns the MediaType for this BodyPart. If not set, the default MediaType MUST be text/plain.

Returns:
media type for this body part.

setMediaType

public void setMediaType(javax.ws.rs.core.MediaType mediaType)
Sets the MediaType for this BodyPart.

Parameters:
mediaType - the new MediaType.
Throws:
IllegalArgumentException - if the mediaType is null.

getParent

public MultiPart getParent()
Returns the parent MultiPart (if any) for this BodyPart.

Returns:
parent of this body type, null if not set.

setParent

public void setParent(MultiPart parent)
Sets the parent MultiPart (if any) for this BodyPart.

Parameters:
parent - the new parent.

getProviders

public javax.ws.rs.ext.Providers getProviders()
Returns the configured Providers for this BodyPart.

Returns:
providers of this body part.

setProviders

public void setProviders(javax.ws.rs.ext.Providers providers)
Sets the configured Providers for this BodyPart.

Parameters:
providers - the new Providers.

cleanup

public void cleanup()
Perform any necessary cleanup at the end of processing this BodyPart.


entity

public BodyPart entity(Object entity)
Builder pattern method to return this BodyPart after additional configuration.

Parameters:
entity - entity to set for this BodyPart.

getEntityAs

public <T> T getEntityAs(Class<T> clazz)
Returns the entity after appropriate conversion to the requested type. This is useful only when the containing MultiPart instance has been received, which causes the providers property to have been set.

Parameters:
clazz - desired class into which the entity should be converted.
Throws:
IllegalArgumentException - if no MessageBodyReader can be found to perform the requested conversion.
IllegalStateException - if this method is called when the providers 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 this BodyPart after additional configuration.

Parameters:
type - media type to set for this BodyPart.

contentDisposition

public BodyPart contentDisposition(ContentDisposition contentDisposition)
Builder pattern method to return this BodyPart after additional configuration.

Parameters:
contentDisposition - content disposition to set for this BodyPart.

setMessageBodyWorkers

public void setMessageBodyWorkers(org.glassfish.jersey.message.MessageBodyWorkers messageBodyWorkers)


Copyright © 2007-2014, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.