Class OutboundMessageContext
java.lang.Object
org.glassfish.jersey.message.internal.OutboundMessageContext
- Direct Known Subclasses:
ClientRequest
Base outbound message context implementation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceThe 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
FieldsModifier and TypeFieldDescriptionprivate final CommittingOutputStreamprivate static final Annotation[]private Objectprivate Annotation[]private OutputStreamprivate javax.ws.rs.core.GenericType<?> private static final List<javax.ws.rs.core.MediaType> -
Constructor Summary
ConstructorsConstructorDescriptionCreate new outbound message context.OutboundMessageContext(OutboundMessageContext original) Create new outbound message context copying the content of another context. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the context.voidCommits theentity streamif it wasn't already committed.voidenableBuffering(javax.ws.rs.core.Configuration configuration) Enable a buffering of serialized entity.private static HeaderValueExceptionGet a list of languages that are acceptable for the message.List<javax.ws.rs.core.MediaType> Get a list of media types that are acceptable for the message.Get the allowed HTTP methods from the Allow HTTP header.getDate()Get message date.Get the message entity Java instance.Get the annotations attached to the entity.Class<?> Get the raw message entity type information.Get the entity output stream.javax.ws.rs.core.EntityTagGet the entity tag.Get the message entity type information.Get the mutable message headers multivalued map.getHeaderString(String name) Get a message header as a single string value.Get the language of the entity.Get the last modified date.intGet Content-Length value.longGet Content-Length value.javax.ws.rs.core.LinkGet the link for the relation.javax.ws.rs.core.Link.BuildergetLinkBuilder(String relation) Convenience method that returns aLink.Builderfor the relation.Set<javax.ws.rs.core.Link> getLinks()Get the links attached to the message as header.Get the location.javax.ws.rs.core.MediaTypeGet the media type of the entity.Get any cookies that accompanied the message.Get any new cookies set on the message message.Get a multi-valued map representing outbound message headers with their values converted to strings.booleanCheck if there is an entity available in the message.booleanCheck if link for relation exists.booleanReturnstrueif the entity stream has been committed.voidreplaceHeaders(javax.ws.rs.core.MultivaluedMap<String, Object> headers) Replace all headers.voidSet a new message message entity.voidsetEntity(Object entity, Annotation[] annotations) Set a new message message entity.voidsetEntity(Object entity, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Set a new message message entity.voidsetEntity(Object entity, Type type, Annotation[] annotations) Set a new message message entity.private voidSet 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(javax.ws.rs.core.MediaType mediaType) Set the message content media type.voidsetStreamProvider(OutboundMessageContext.StreamProvider streamProvider) Set a stream provider callback.private <T> TsingleHeader(String name, Class<T> valueType, Function<String, T> converter, boolean convertNull) Get a single typed header value.
-
Field Details
-
EMPTY_ANNOTATIONS
-
WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST
-
headers
-
committingOutputStream
-
entity
-
entityType
private javax.ws.rs.core.GenericType<?> entityType -
entityAnnotations
-
entityStream
-
-
Constructor Details
-
OutboundMessageContext
public OutboundMessageContext()Create new outbound message context. -
OutboundMessageContext
Create new outbound message context copying the content of another context.- Parameters:
original- the original outbound message context.
-
-
Method Details
-
replaceHeaders
Replace all headers.- Parameters:
headers- new headers.
-
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
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.- 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.
-
singleHeader
private <T> T singleHeader(String name, Class<T> valueType, Function<String, T> converter, boolean convertNull) Get a single typed header value.- Type Parameters:
T- header value type.- Parameters:
name- header name.valueType- header value class.converter- from string conversion function. Is expected to throwProcessingExceptionif conversion fails.convertNull- iftruethis method calls the provided converter even fornull. Otherwise this method returns thenullwithout calling the converter.- Returns:
- value of the header, or (possibly converted)
nullif not present.
-
exception
-
getHeaders
Get the mutable message headers multivalued map.- Returns:
- mutable multivalued map of message headers.
-
getDate
Get message date.- Returns:
- the message date, otherwise
nullif not present.
-
getLanguage
Get the language of the entity.- Returns:
- the language of the entity or
nullif not specified
-
getMediaType
public javax.ws.rs.core.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
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
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.
-
getRequestCookies
Get any cookies that accompanied the message.- Returns:
- a read-only map of cookie name (String) to
Cookie.
-
getAllowedMethods
Get the allowed HTTP methods from the Allow HTTP header.- Returns:
- the allowed HTTP methods, all methods will returned as upper case strings.
-
getLength
public int getLength()Get Content-Length value.Note:
getLengthLong()should be preferred over this method, since it returns alonginstead and is therefore more portable.- Returns:
- Content-Length as a postive integer if present and valid number,
-1if negative number. - Throws:
javax.ws.rs.ProcessingException- whenInteger.parseInt(String)(String)} throwsNumberFormatException.
-
getLengthLong
public long getLengthLong()Get Content-Length value.- Returns:
- Content-Length as a positive long if present and valid number,
-1if negative number. - Throws:
javax.ws.rs.ProcessingException- whenLong.parseLong(String)throwsNumberFormatException.
-
getResponseCookies
Get any new cookies set on the message message.- Returns:
- a read-only map of cookie name (String) to a
new cookie.
-
getEntityTag
public javax.ws.rs.core.EntityTag getEntityTag()Get the entity tag.- Returns:
- the entity tag, otherwise
nullif not present.
-
getLastModified
Get the last modified date.- Returns:
- the last modified date, otherwise
nullif not present.
-
getLocation
Get the location.- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
Get the links attached to the message as header.- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
hasLink
Check if link for relation exists.- Parameters:
relation- link relation.- Returns:
trueif the for the relation link exists,falseotherwise.
-
getLink
Get the link for the relation.- Parameters:
relation- link relation.- Returns:
- the link for the relation, otherwise
nullif not present.
-
getLinkBuilder
Convenience method that returns aLink.Builderfor the relation.- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
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
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
Set a new message message entity.- Parameters:
entity- entity object.- See Also:
-
setEntity
Set a new message message entity.- Parameters:
entity- entity object.annotations- annotations attached to the entity.- See Also:
-
setEntity
Set a new message message entity.- Parameters:
entity- entity object.type- entity generic type information.- See Also:
-
setEntity
Set a new message message entity.- Parameters:
entity- entity object.type- declared entity class.annotations- annotations attached to the entity.- See Also:
-
setEntity
public void setEntity(Object entity, Annotation[] annotations, javax.ws.rs.core.MediaType mediaType) Set a new message message entity.- Parameters:
entity- entity object.annotations- annotations attached to the entity.mediaType- entity media type.- See Also:
-
setMediaType
public void setMediaType(javax.ws.rs.core.MediaType mediaType) Set the message content media type.- Parameters:
mediaType- message content media type.
-
getEntityClass
Get the raw message entity type information.- Returns:
- raw message entity type information.
-
getEntityType
Get the message entity type information.- Returns:
- message entity type.
-
setEntityType
Set the message entity type information.This method overrides any computed or previously set entity type information.
- Parameters:
type- overriding message entity type.
-
getEntityAnnotations
Get the annotations attached to the entity.- Returns:
- entity annotations.
-
setEntityAnnotations
Set the annotations attached to the entity.- Parameters:
annotations- entity annotations.
-
getEntityStream
Get the entity output stream.- Returns:
- entity output stream.
-
setEntityStream
Set a new entity output stream.- Parameters:
outputStream- new entity output stream.
-
enableBuffering
public void enableBuffering(javax.ws.rs.core.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
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
Commits 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.
-