Class OutboundMessageContext
- java.lang.Object
-
- org.glassfish.jersey.message.internal.MessageHeaderMethods
-
- org.glassfish.jersey.message.internal.OutboundMessageContext
-
public class OutboundMessageContext extends MessageHeaderMethods
Base outbound message context implementation.- Author:
- Marek Potociar
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceOutboundMessageContext.StreamProviderThe callback interface which is used to get the terminal output stream into which the entity should be written and to inform the implementation about the entity size.
-
Field Summary
-
Fields inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
runtimeDelegateDecorator
-
-
Constructor Summary
Constructors Constructor Description OutboundMessageContext()Deprecated.OutboundMessageContext(Configuration configuration)Create new outbound message context.OutboundMessageContext(OutboundMessageContext original)Create new outbound message context copying the content of another context.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the context.voidcommitStream()Commits theentity streamif it wasn't already committed.voidenableBuffering(Configuration configuration)Enable a buffering of serialized entity.List<Locale>getAcceptableLanguages()Get a list of languages that are acceptable for the message.List<MediaType>getAcceptableMediaTypes()Get a list of media types that are acceptable for the message.ConfigurationgetConfiguration()The related client/server sideConfiguration.ObjectgetEntity()Get the message entity Java instance.Annotation[]getEntityAnnotations()Get the annotations attached to the entity.Class<?>getEntityClass()Get the raw message entity type information.OutputStreamgetEntityStream()Get the entity output stream.TypegetEntityType()Get the message entity type information.MultivaluedMap<String,Object>getHeaders()Get the mutable message headers multivalued map.StringgetHeaderString(String name)Get a message header as a single string value.HeaderValueException.ContextgetHeaderValueExceptionContext()ReturnHeaderValueException.Contexttype of the message context.Set<Link>getLinks()Get the links attached to the message as header.MediaTypegetMediaType()Get the media type of the entity.MultivaluedMap<String,String>getStringHeaders()Get a multi-valued map representing outbound message headers with their values converted to strings.booleanhasEntity()Check if there is an entity available in the message.booleanisCommitted()Returnstrueif the entity stream has been committed.voidreplaceHeaders(MultivaluedMap<String,Object> headers)Replace all headers.voidsetEntity(Object entity)Set a new message message entity.voidsetEntity(Object entity, Annotation[] annotations)Set a new message message entity.voidsetEntity(Object entity, Annotation[] annotations, MediaType mediaType)Set a new message message entity.voidsetEntity(Object entity, Type type, Annotation[] annotations)Set a new message message entity.voidsetEntityAnnotations(Annotation[] annotations)Set the annotations attached to the entity.voidsetEntityStream(OutputStream outputStream)Set a new entity output stream.voidsetEntityType(Type type)Set the message entity type information.voidsetMediaType(MediaType mediaType)Set the message content media type.voidsetStreamProvider(OutboundMessageContext.StreamProvider streamProvider)Set a stream provider callback.-
Methods inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
containsHeaderString, containsHeaderString, exception, getAllowedMethods, getDate, getEntityTag, getLanguage, getLastModified, getLength, getLengthLong, getLink, getLinkBuilder, getLocation, getRequestCookies, getResponseCookies, hasLink, singleHeader, singleHeader
-
-
-
-
Constructor Detail
-
OutboundMessageContext
public OutboundMessageContext(Configuration configuration)
Create new outbound message context.- Parameters:
configuration- the client/serverConfiguration. Ifnull, the default behaviour is expected.
-
OutboundMessageContext
public OutboundMessageContext(OutboundMessageContext original)
Create new outbound message context copying the content of another context.- Parameters:
original- the original outbound message context.
-
OutboundMessageContext
@Deprecated public OutboundMessageContext()
Deprecated.Create new outbound message context.- See Also:
OutboundMessageContext(Configuration)
-
-
Method Detail
-
replaceHeaders
public void replaceHeaders(MultivaluedMap<String,Object> headers)
Replace all headers.- Parameters:
headers- new headers.
-
getStringHeaders
public MultivaluedMap<String,String> getStringHeaders()
Get a multi-valued map representing outbound message headers with their values converted to strings.- Returns:
- multi-valued map of outbound message header names to their string-converted values.
-
getHeaderString
public String getHeaderString(String name)
Get a message header as a single string value.Each single header value is converted to String using a
RuntimeDelegate.HeaderDelegateif one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)for the header value class or using itstoStringmethod if a header delegate is not available.- Specified by:
getHeaderStringin classMessageHeaderMethods- Parameters:
name- the message header.- Returns:
- the message header value. If the message header is not present then
nullis returned. If the message header is present but has no value then the empty string is returned. If the message header is present more than once then the values of joined together and separated by a ',' character.
-
getHeaderValueExceptionContext
public HeaderValueException.Context getHeaderValueExceptionContext()
Description copied from class:MessageHeaderMethodsReturnHeaderValueException.Contexttype of the message context.- Specified by:
getHeaderValueExceptionContextin classMessageHeaderMethods- Returns:
HeaderValueException.Contexttype of the message context.
-
getHeaders
public MultivaluedMap<String,Object> getHeaders()
Get the mutable message headers multivalued map.- Specified by:
getHeadersin classMessageHeaderMethods- Returns:
- mutable multivalued map of message headers.
-
getMediaType
public MediaType getMediaType()
Get the media type of the entity.- Returns:
- the media type or
nullif not specified (e.g. there's no message entity).
-
getAcceptableMediaTypes
public List<MediaType> getAcceptableMediaTypes()
Get a list of media types that are acceptable for the message.- Returns:
- a read-only list of requested message media types sorted according to their q-value, with highest preference first.
-
getAcceptableLanguages
public List<Locale> getAcceptableLanguages()
Get a list of languages that are acceptable for the message.- Returns:
- a read-only list of acceptable languages sorted according to their q-value, with highest preference first.
-
getLinks
public Set<Link> getLinks()
Get the links attached to the message as header.- Specified by:
getLinksin classMessageHeaderMethods- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
hasEntity
public boolean hasEntity()
Check if there is an entity available in the message.The method returns
trueif the entity is present, returnsfalseotherwise.- Returns:
trueif there is an entity present in the message,falseotherwise.
-
getEntity
public Object getEntity()
Get the message entity Java instance.Returns
nullif the message does not contain an entity.- Returns:
- the message entity or
nullif message does not contain an entity body.
-
setEntity
public void setEntity(Object entity)
Set a new message message entity.- Parameters:
entity- entity object.- See Also:
MessageBodyWriter
-
setEntity
public void setEntity(Object entity, Annotation[] annotations)
Set a new message message entity.- Parameters:
entity- entity object.annotations- annotations attached to the entity.- See Also:
MessageBodyWriter
-
setEntity
public void setEntity(Object entity, Type type, Annotation[] annotations)
Set a new message message entity.- Parameters:
entity- entity object.type- declared entity class.annotations- annotations attached to the entity.- See Also:
MessageBodyWriter
-
setEntity
public void setEntity(Object entity, Annotation[] annotations, MediaType mediaType)
Set a new message message entity.- Parameters:
entity- entity object.annotations- annotations attached to the entity.mediaType- entity media type.- See Also:
MessageBodyWriter
-
setMediaType
public void setMediaType(MediaType mediaType)
Set the message content media type.- Parameters:
mediaType- message content media type.
-
getEntityClass
public Class<?> getEntityClass()
Get the raw message entity type information.- Returns:
- raw message entity type information.
-
getEntityType
public Type getEntityType()
Get the message entity type information.- Returns:
- message entity type.
-
setEntityType
public void setEntityType(Type type)
Set the message entity type information.This method overrides any computed or previously set entity type information.
- Parameters:
type- overriding message entity type.
-
getEntityAnnotations
public Annotation[] getEntityAnnotations()
Get the annotations attached to the entity.- Returns:
- entity annotations.
-
setEntityAnnotations
public void setEntityAnnotations(Annotation[] annotations)
Set the annotations attached to the entity.- Parameters:
annotations- entity annotations.
-
getEntityStream
public OutputStream getEntityStream()
Get the entity output stream.- Returns:
- entity output stream.
-
setEntityStream
public void setEntityStream(OutputStream outputStream)
Set a new entity output stream.- Parameters:
outputStream- new entity output stream.
-
enableBuffering
public void enableBuffering(Configuration configuration)
Enable a buffering of serialized entity. The buffering will be configured from configuration. The property determining the size of the buffer isCommonProperties.OUTBOUND_CONTENT_LENGTH_BUFFER. The buffering functionality is by default disabled and could be enabled by calling this method. In this case this method must be called before first bytes are written to theentity stream.- Parameters:
configuration- runtime configuration.
-
setStreamProvider
public void setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
Set a stream provider callback. This method must be called before first bytes are written to theentity stream.- Parameters:
streamProvider- non-nulloutput stream provider.
-
commitStream
public void commitStream() throws IOExceptionCommits theentity streamif it wasn't already committed.- Throws:
IOException- in case of the IO error.
-
isCommitted
public boolean isCommitted()
Returnstrueif the entity stream has been committed.- Returns:
trueif the entity stream has been committed. Otherwise returnsfalse.
-
close
public void close()
Closes the context. Flushes and closes the entity stream.
-
getConfiguration
public Configuration getConfiguration()
The related client/server sideConfiguration. Can benull.- Returns:
Configurationthe configuration
-
-