Class InboundMessageContext
java.lang.Object
org.glassfish.jersey.message.internal.InboundMessageContext
- Direct Known Subclasses:
ClientResponse
,ContainerRequest
Base inbound message context implementation.
- Author:
- Marek Potociar
-
Constructor Summary
ConstructorDescriptionDeprecated.InboundMessageContext
(boolean translateNce) Deprecated.InboundMessageContext
(Configuration configuration) Create new inbound message context.InboundMessageContext
(Configuration configuration, boolean translateNce) Create new inbound message context. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Buffer the entity stream (if not empty).void
close()
Closes the underlying content stream.Get the allowed HTTP methods from the Allow HTTP header.The related client/server sideConfiguration
.getDate()
Get message date.Get the entity input stream.Get the entity tag.Get the mutable message headers multivalued map.getHeaderString
(String name) Get a message header as a single string value.Get If-Match header.Get If-None-Match header.Get the language of the entity.Get the last modified date.int
Get Content-Length value.Get the link for the relation.getLinkBuilder
(String relation) Convenience method that returns aLink.Builder
for the relation.getLinks()
Get the links attached to the message as header.Get the location.Get the media type of the entity.Get a list of languages that are acceptable for the message.Get a list of media types that are acceptable for a request.Get the list of language tag from the "Accept-Charset" of an HTTP request.Get the list of language tag from the "Accept-Charset" of an HTTP request.protected abstract Iterable<ReaderInterceptor>
Get reader interceptors bound to this context.Get any cookies that accompanied the request.Get any new cookies set on the response message.Get context message body workers.boolean
Check if there is a non-empty entity input stream is available in the message.boolean
Check if link for relation exists.Add a new header value.headers
(MultivaluedMap<String, String> newHeaders) Add new headers.Add new header values.Add new header values.Add new headers.<T> T
readEntity
(Class<T> rawType, Annotation[] annotations, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, Type type, Annotation[] annotations, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, Type type, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.Remove a header.void
setEntityStream
(InputStream input) Set a new entity input stream.void
setWorkers
(MessageBodyWorkers workers) Set context message body workers.
-
Constructor Details
-
InboundMessageContext
Create new inbound message context.- Parameters:
configuration
- the related client/server sideConfiguration
-
InboundMessageContext
Create new inbound message context.- Parameters:
configuration
- the related client/server sideConfiguration
. Ifnull
, the default behaviour is expected.translateNce
- iftrue
, theNoContentException
thrown by a selected message body reader will be translated into aBadRequestException
as required by JAX-RS specification on the server side.
-
InboundMessageContext
Deprecated.Create new inbound message context.- See Also:
-
InboundMessageContext
Deprecated.Create new inbound message context.- Parameters:
translateNce
- iftrue
, theNoContentException
thrown by a selected message body reader will be translated into aBadRequestException
as required by JAX-RS specification on the server side. *- See Also:
-
-
Method Details
-
header
Add a new header value.- Parameters:
name
- header name.value
- header value.- Returns:
- updated context.
-
headers
Add new header values.- Parameters:
name
- header name.values
- header values.- Returns:
- updated context.
-
headers
Add new header values.- Parameters:
name
- header name.values
- header values.- Returns:
- updated context.
-
headers
Add new headers.- Parameters:
newHeaders
- new headers.- Returns:
- updated context.
-
headers
Add new headers.- Parameters:
newHeaders
- new headers.- Returns:
- updated context.
-
remove
Remove a header.- Parameters:
name
- header name.- Returns:
- updated context.
-
getHeaderString
Get a message header as a single string value. Each single header value is converted to String using aRuntimeDelegate.HeaderDelegate
if one is available viaRuntimeDelegate.createHeaderDelegate(java.lang.Class)
for the header value class or using itstoString
method 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
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.
-
getHeaders
Get the mutable message headers multivalued map.- Returns:
- mutable multivalued map of message headers.
-
getDate
Get message date.- Returns:
- the message date, otherwise
null
if not present.
-
getIfMatch
Get If-Match header.- Returns:
- the If-Match header value, otherwise
null
if not present.
-
getIfNoneMatch
Get If-None-Match header.- Returns:
- the If-None-Match header value, otherwise
null
if not present.
-
getLanguage
Get the language of the entity.- Returns:
- the language of the entity or
null
if not specified.
-
getLength
public int getLength()Get Content-Length value.- Returns:
- Content-Length as integer if present and valid number. In other cases returns -1.
-
getMediaType
Get the media type of the entity.- Returns:
- the media type or
null
if not specified (e.g. there's no message entity).
-
getQualifiedAcceptableMediaTypes
Get a list of media types that are acceptable for a request.- Returns:
- a read-only list of requested response media types sorted according to their q-value, with highest preference first.
-
getQualifiedAcceptableLanguages
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.
-
getQualifiedAcceptCharset
Get the list of language tag from the "Accept-Charset" of an HTTP request.- Returns:
- The list of AcceptableToken. This list is ordered with the highest quality acceptable charset occurring first.
-
getQualifiedAcceptEncoding
Get the list of language tag from the "Accept-Charset" of an HTTP request.- Returns:
- The list of AcceptableToken. This list is ordered with the highest quality acceptable charset occurring first.
-
getRequestCookies
Get any cookies that accompanied the request.- 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.
-
getResponseCookies
Get any new cookies set on the response message.- Returns:
- a read-only map of cookie name (String) to a
new cookie
.
-
getEntityTag
Get the entity tag.- Returns:
- the entity tag, otherwise
null
if not present.
-
getLastModified
Get the last modified date.- Returns:
- the last modified date, otherwise
null
if not present.
-
getLocation
Get the location.- Returns:
- the location URI, otherwise
null
if not present.
-
getLinks
Get the links attached to the message as header.- Returns:
- links, may return empty
Set
if no links are present. Never returnsnull
.
-
hasLink
Check if link for relation exists.- Parameters:
relation
- link relation.- Returns:
true
if the for the relation link exists,false
otherwise.
-
getLink
Get the link for the relation.- Parameters:
relation
- link relation.- Returns:
- the link for the relation, otherwise
null
if not present.
-
getLinkBuilder
Convenience method that returns aLink.Builder
for the relation.- Parameters:
relation
- link relation.- Returns:
- the link builder for the relation, otherwise
null
if not present.
-
getWorkers
Get context message body workers.- Returns:
- context message body workers.
-
setWorkers
Set context message body workers.- Parameters:
workers
- context message body workers.
-
hasEntity
public boolean hasEntity()Check if there is a non-empty entity input stream is available in the message. The method returnstrue
if the entity is present, returnsfalse
otherwise.- Returns:
true
if there is an entity present in the message,false
otherwise.
-
getEntityStream
Get the entity input stream.- Returns:
- entity input stream.
-
setEntityStream
Set a new entity input stream.- Parameters:
input
- new entity input stream.
-
readEntity
Read entity from a context entity input stream.- Type Parameters:
T
- entity Java object type.- Parameters:
rawType
- raw Java entity type.propertiesDelegate
- request-scoped properties delegate.- Returns:
- entity read from a context entity input stream.
-
readEntity
public <T> T readEntity(Class<T> rawType, Annotation[] annotations, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.- Type Parameters:
T
- entity Java object type.- Parameters:
rawType
- raw Java entity type.annotations
- entity annotations.propertiesDelegate
- request-scoped properties delegate.- Returns:
- entity read from a context entity input stream.
-
readEntity
Read entity from a context entity input stream.- Type Parameters:
T
- entity Java object type.- Parameters:
rawType
- raw Java entity type.type
- generic Java entity type.propertiesDelegate
- request-scoped properties delegate.- Returns:
- entity read from a context entity input stream.
-
readEntity
public <T> T readEntity(Class<T> rawType, Type type, Annotation[] annotations, PropertiesDelegate propertiesDelegate) Read entity from a context entity input stream.- Type Parameters:
T
- entity Java object type.- Parameters:
rawType
- raw Java entity type.type
- generic Java entity type.annotations
- entity annotations.propertiesDelegate
- request-scoped properties delegate.- Returns:
- entity read from a context entity input stream.
-
bufferEntity
Buffer the entity stream (if not empty).- Returns:
true
if the entity input stream was successfully buffered.- Throws:
ProcessingException
- in case of an IO error.
-
close
public void close()Closes the underlying content stream. -
getReaderInterceptors
Get reader interceptors bound to this context.Interceptors will be used when one of the
readEntity
methods is invoked.- Returns:
- reader interceptors bound to this context.
-
getConfiguration
The related client/server sideConfiguration
. Can benull
.- Returns:
Configuration
the configuration
-