public class OutboundMessageContext
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
static interface |
OutboundMessageContext.StreamProvider
The 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.
|
Modifier and Type | Field and Description |
---|---|
private CommittingOutputStream |
committingOutputStream |
private static java.lang.annotation.Annotation[] |
EMPTY_ANNOTATIONS |
private java.lang.Object |
entity |
private java.lang.annotation.Annotation[] |
entityAnnotations |
private java.io.OutputStream |
entityStream |
private javax.ws.rs.core.GenericType<?> |
entityType |
private javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> |
headers |
private static java.util.List<javax.ws.rs.core.MediaType> |
WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST |
Constructor and Description |
---|
OutboundMessageContext()
Create new outbound message context.
|
OutboundMessageContext(OutboundMessageContext original)
Create new outbound message context copying the content
of another context.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the context.
|
void |
commitStream()
Commits the
entity stream if it wasn't already committed. |
void |
enableBuffering(javax.ws.rs.core.Configuration configuration)
Enable a buffering of serialized entity.
|
private static HeaderValueException |
exception(java.lang.String headerName,
java.lang.Object headerValue,
java.lang.Exception e) |
java.util.List<java.util.Locale> |
getAcceptableLanguages()
Get a list of languages that are acceptable for the message.
|
java.util.List<javax.ws.rs.core.MediaType> |
getAcceptableMediaTypes()
Get a list of media types that are acceptable for the message.
|
java.util.Set<java.lang.String> |
getAllowedMethods()
Get the allowed HTTP methods from the Allow HTTP header.
|
java.util.Date |
getDate()
Get message date.
|
java.lang.Object |
getEntity()
Get the message entity Java instance.
|
java.lang.annotation.Annotation[] |
getEntityAnnotations()
Get the annotations attached to the entity.
|
java.lang.Class<?> |
getEntityClass()
Get the raw message entity type information.
|
java.io.OutputStream |
getEntityStream()
Get the entity output stream.
|
javax.ws.rs.core.EntityTag |
getEntityTag()
Get the entity tag.
|
java.lang.reflect.Type |
getEntityType()
Get the message entity type information.
|
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> |
getHeaders()
Get the mutable message headers multivalued map.
|
java.lang.String |
getHeaderString(java.lang.String name)
Get a message header as a single string value.
|
java.util.Locale |
getLanguage()
Get the language of the entity.
|
java.util.Date |
getLastModified()
Get the last modified date.
|
int |
getLength()
Get Content-Length value.
|
javax.ws.rs.core.Link |
getLink(java.lang.String relation)
Get the link for the relation.
|
javax.ws.rs.core.Link.Builder |
getLinkBuilder(java.lang.String relation)
Convenience method that returns a
Link.Builder
for the relation. |
java.util.Set<javax.ws.rs.core.Link> |
getLinks()
Get the links attached to the message as header.
|
java.net.URI |
getLocation()
Get the location.
|
javax.ws.rs.core.MediaType |
getMediaType()
Get the media type of the entity.
|
java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> |
getRequestCookies()
Get any cookies that accompanied the message.
|
java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> |
getResponseCookies()
Get any new cookies set on the message message.
|
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> |
getStringHeaders()
Get a multi-valued map representing outbound message headers with their values converted
to strings.
|
boolean |
hasEntity()
Check if there is an entity available in the message.
|
boolean |
hasLink(java.lang.String relation)
Check if link for relation exists.
|
boolean |
isCommitted()
Returns
true if the entity stream has been committed. |
void |
replaceHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)
Replace all headers.
|
void |
setEntity(java.lang.Object entity)
Set a new message message entity.
|
void |
setEntity(java.lang.Object entity,
java.lang.annotation.Annotation[] annotations)
Set a new message message entity.
|
void |
setEntity(java.lang.Object entity,
java.lang.annotation.Annotation[] annotations,
javax.ws.rs.core.MediaType mediaType)
Set a new message message entity.
|
private void |
setEntity(java.lang.Object entity,
javax.ws.rs.core.GenericType<?> type)
Set a new message message entity.
|
void |
setEntity(java.lang.Object entity,
java.lang.reflect.Type type,
java.lang.annotation.Annotation[] annotations)
Set a new message message entity.
|
void |
setEntityAnnotations(java.lang.annotation.Annotation[] annotations)
Set the annotations attached to the entity.
|
void |
setEntityStream(java.io.OutputStream outputStream)
Set a new entity output stream.
|
void |
setEntityType(java.lang.reflect.Type type)
Set the message entity type information.
|
void |
setMediaType(javax.ws.rs.core.MediaType mediaType)
Set the message content media type.
|
void |
setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
Set a stream provider callback.
|
private <T> T |
singleHeader(java.lang.String name,
java.lang.Class<T> valueType,
com.google.common.base.Function<java.lang.String,T> converter,
boolean convertNull)
Get a single typed header value.
|
private static final java.lang.annotation.Annotation[] EMPTY_ANNOTATIONS
private static final java.util.List<javax.ws.rs.core.MediaType> WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST
private final javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers
private final CommittingOutputStream committingOutputStream
private java.lang.Object entity
private javax.ws.rs.core.GenericType<?> entityType
private java.lang.annotation.Annotation[] entityAnnotations
private java.io.OutputStream entityStream
public OutboundMessageContext()
public OutboundMessageContext(OutboundMessageContext original)
original
- the original outbound message context.public void replaceHeaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> headers)
headers
- new headers.public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getStringHeaders()
public java.lang.String getHeaderString(java.lang.String name)
RuntimeDelegate.HeaderDelegate
if one is available
via RuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using its toString
method if a header
delegate is not available.name
- the message header.null
is 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.private <T> T singleHeader(java.lang.String name, java.lang.Class<T> valueType, com.google.common.base.Function<java.lang.String,T> converter, boolean convertNull)
T
- header value type.name
- header name.valueType
- header value class.converter
- from string conversion function. Is expected to throw ProcessingException
if conversion fails.convertNull
- if true
this method calls the provided converter even for null
. Otherwise this
method returns the null
without calling the converter.null
if not present.private static HeaderValueException exception(java.lang.String headerName, java.lang.Object headerValue, java.lang.Exception e)
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.Object> getHeaders()
public java.util.Date getDate()
null
if not present.public java.util.Locale getLanguage()
null
if not specifiedpublic javax.ws.rs.core.MediaType getMediaType()
null
if not specified (e.g. there's no
message entity).public java.util.List<javax.ws.rs.core.MediaType> getAcceptableMediaTypes()
public java.util.List<java.util.Locale> getAcceptableLanguages()
public java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> getRequestCookies()
Cookie
.public java.util.Set<java.lang.String> getAllowedMethods()
public int getLength()
public java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> getResponseCookies()
new cookie
.public javax.ws.rs.core.EntityTag getEntityTag()
null
if not present.public java.util.Date getLastModified()
null
if not present.public java.net.URI getLocation()
null
if not present.public java.util.Set<javax.ws.rs.core.Link> getLinks()
Set
if no links are present. Never
returns null
.public boolean hasLink(java.lang.String relation)
relation
- link relation.true
if the for the relation link exists, false
otherwise.public javax.ws.rs.core.Link getLink(java.lang.String relation)
relation
- link relation.null
if not present.public javax.ws.rs.core.Link.Builder getLinkBuilder(java.lang.String relation)
Link.Builder
for the relation.relation
- link relation.null
if not
present.public boolean hasEntity()
true
if the entity is present, returns
false
otherwise.true
if there is an entity present in the message,
false
otherwise.public java.lang.Object getEntity()
null
if the message does not contain an entity.null
if message does not contain an
entity body.public void setEntity(java.lang.Object entity)
entity
- entity object.MessageBodyWriter
public void setEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations)
entity
- entity object.annotations
- annotations attached to the entity.MessageBodyWriter
private void setEntity(java.lang.Object entity, javax.ws.rs.core.GenericType<?> type)
entity
- entity object.type
- entity generic type information.MessageBodyWriter
public void setEntity(java.lang.Object entity, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations)
entity
- entity object.type
- declared entity class.annotations
- annotations attached to the entity.MessageBodyWriter
public void setEntity(java.lang.Object entity, java.lang.annotation.Annotation[] annotations, javax.ws.rs.core.MediaType mediaType)
entity
- entity object.annotations
- annotations attached to the entity.mediaType
- entity media type.MessageBodyWriter
public void setMediaType(javax.ws.rs.core.MediaType mediaType)
mediaType
- message content media type.public java.lang.Class<?> getEntityClass()
public java.lang.reflect.Type getEntityType()
public void setEntityType(java.lang.reflect.Type type)
type
- overriding message entity type.public java.lang.annotation.Annotation[] getEntityAnnotations()
public void setEntityAnnotations(java.lang.annotation.Annotation[] annotations)
annotations
- entity annotations.public java.io.OutputStream getEntityStream()
public void setEntityStream(java.io.OutputStream outputStream)
outputStream
- new entity output stream.public void enableBuffering(javax.ws.rs.core.Configuration configuration)
CommonProperties.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 the entity stream
.configuration
- runtime configuration.public void setStreamProvider(OutboundMessageContext.StreamProvider streamProvider)
entity stream
.streamProvider
- non-null
output stream provider.public void commitStream() throws java.io.IOException
entity stream
if it wasn't already committed.java.io.IOException
- in case of the IO error.public boolean isCommitted()
true
if the entity stream has been committed.true
if the entity stream has been committed. Otherwise returns false
.public void close()