Class InboundMessageContext
- java.lang.Object
-
- org.glassfish.jersey.message.internal.InboundMessageContext
-
- Direct Known Subclasses:
ClientResponse,ContainerRequest
public abstract class InboundMessageContext extends java.lang.ObjectBase inbound message context implementation.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static classInboundMessageContext.EntityContentInput stream and its state.
-
Field Summary
Fields Modifier and Type Field Description private static java.io.InputStreamEMPTYprivate static java.lang.annotation.Annotation[]EMPTY_ANNOTATIONSprivate InboundMessageContext.EntityContententityContentprivate javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>headersprivate booleantranslateNceprivate static java.util.List<AcceptableMediaType>WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LISTprivate MessageBodyWorkersworkers
-
Constructor Summary
Constructors Constructor Description InboundMessageContext()Create new inbound message context.InboundMessageContext(boolean translateNce)Create new inbound message context.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description booleanbufferEntity()Buffer the entity stream (if not empty).voidclose()Closes the underlying content stream.private static HeaderValueExceptionexception(java.lang.String headerName, java.lang.Object headerValue, java.lang.Exception e)java.util.Set<java.lang.String>getAllowedMethods()Get the allowed HTTP methods from the Allow HTTP header.java.util.DategetDate()Get message date.java.io.InputStreamgetEntityStream()Get the entity input stream.javax.ws.rs.core.EntityTaggetEntityTag()Get the entity tag.javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String>getHeaders()Get the mutable message headers multivalued map.java.lang.StringgetHeaderString(java.lang.String name)Get a message header as a single string value.java.util.Set<MatchingEntityTag>getIfMatch()Get If-Match header.java.util.Set<MatchingEntityTag>getIfNoneMatch()Get If-None-Match header.java.util.LocalegetLanguage()Get the language of the entity.java.util.DategetLastModified()Get the last modified date.intgetLength()Get Content-Length value.javax.ws.rs.core.LinkgetLink(java.lang.String relation)Get the link for the relation.javax.ws.rs.core.Link.BuildergetLinkBuilder(java.lang.String relation)Convenience method that returns aLink.Builderfor the relation.java.util.Set<javax.ws.rs.core.Link>getLinks()Get the links attached to the message as header.java.net.URIgetLocation()Get the location.javax.ws.rs.core.MediaTypegetMediaType()Get the media type of the entity.java.util.List<AcceptableLanguageTag>getQualifiedAcceptableLanguages()Get a list of languages that are acceptable for the message.java.util.List<AcceptableMediaType>getQualifiedAcceptableMediaTypes()Get a list of media types that are acceptable for a request.java.util.List<AcceptableToken>getQualifiedAcceptCharset()Get the list of language tag from the "Accept-Charset" of an HTTP request.java.util.List<AcceptableToken>getQualifiedAcceptEncoding()Get the list of language tag from the "Accept-Charset" of an HTTP request.protected abstract java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor>getReaderInterceptors()Get reader interceptors bound to this context.java.util.Map<java.lang.String,javax.ws.rs.core.Cookie>getRequestCookies()Get any cookies that accompanied the request.java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie>getResponseCookies()Get any new cookies set on the response message.MessageBodyWorkersgetWorkers()Get context message body workers.booleanhasEntity()Check if there is a non-empty entity input stream is available in the message.booleanhasLink(java.lang.String relation)Check if link for relation exists.InboundMessageContextheader(java.lang.String name, java.lang.Object value)Add a new header value.InboundMessageContextheaders(java.lang.String name, java.lang.Iterable<?> values)Add new header values.InboundMessageContextheaders(java.lang.String name, java.lang.Object... values)Add new header values.InboundMessageContextheaders(java.util.Map<java.lang.String,java.util.List<java.lang.String>> newHeaders)Add new headers.InboundMessageContextheaders(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> newHeaders)Add new headers.private static java.util.List<java.lang.String>iterableToList(java.lang.Iterable<?> values)<T> TreadEntity(java.lang.Class<T> rawType, java.lang.annotation.Annotation[] annotations, PropertiesDelegate propertiesDelegate)Read entity from a context entity input stream.<T> TreadEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations, PropertiesDelegate propertiesDelegate)Read entity from a context entity input stream.<T> TreadEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type, PropertiesDelegate propertiesDelegate)Read entity from a context entity input stream.<T> TreadEntity(java.lang.Class<T> rawType, PropertiesDelegate propertiesDelegate)Read entity from a context entity input stream.InboundMessageContextremove(java.lang.String name)Remove a header.voidsetEntityStream(java.io.InputStream input)Set a new entity input stream.voidsetWorkers(MessageBodyWorkers workers)Set context message body workers.private <T> TsingleHeader(java.lang.String name, java.util.function.Function<java.lang.String,T> converter, boolean convertNull)Get a single typed header value.
-
-
-
Field Detail
-
EMPTY
private static final java.io.InputStream EMPTY
-
EMPTY_ANNOTATIONS
private static final java.lang.annotation.Annotation[] EMPTY_ANNOTATIONS
-
WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST
private static final java.util.List<AcceptableMediaType> WILDCARD_ACCEPTABLE_TYPE_SINGLETON_LIST
-
headers
private final javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> headers
-
entityContent
private final InboundMessageContext.EntityContent entityContent
-
translateNce
private final boolean translateNce
-
workers
private MessageBodyWorkers workers
-
-
Constructor Detail
-
InboundMessageContext
public InboundMessageContext()
Create new inbound message context.
-
InboundMessageContext
public InboundMessageContext(boolean translateNce)
Create new inbound message context.- Parameters:
translateNce- iftrue, theNoContentExceptionthrown by a selected message body reader will be translated into aBadRequestExceptionas required by JAX-RS specification on the server side.
-
-
Method Detail
-
header
public InboundMessageContext header(java.lang.String name, java.lang.Object value)
Add a new header value.- Parameters:
name- header name.value- header value.- Returns:
- updated context.
-
headers
public InboundMessageContext headers(java.lang.String name, java.lang.Object... values)
Add new header values.- Parameters:
name- header name.values- header values.- Returns:
- updated context.
-
headers
public InboundMessageContext headers(java.lang.String name, java.lang.Iterable<?> values)
Add new header values.- Parameters:
name- header name.values- header values.- Returns:
- updated context.
-
headers
public InboundMessageContext headers(javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> newHeaders)
Add new headers.- Parameters:
newHeaders- new headers.- Returns:
- updated context.
-
headers
public InboundMessageContext headers(java.util.Map<java.lang.String,java.util.List<java.lang.String>> newHeaders)
Add new headers.- Parameters:
newHeaders- new headers.- Returns:
- updated context.
-
remove
public InboundMessageContext remove(java.lang.String name)
Remove a header.- Parameters:
name- header name.- Returns:
- updated context.
-
iterableToList
private static java.util.List<java.lang.String> iterableToList(java.lang.Iterable<?> values)
-
getHeaderString
public java.lang.String getHeaderString(java.lang.String name)
Get a message header as a single string value. Each single header value is converted to String using aRuntimeDelegate.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(java.lang.String name, java.util.function.Function<java.lang.String,T> converter, boolean convertNull)Get a single typed header value.- Parameters:
name- header name.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
private static HeaderValueException exception(java.lang.String headerName, java.lang.Object headerValue, java.lang.Exception e)
-
getHeaders
public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getHeaders()
Get the mutable message headers multivalued map.- Returns:
- mutable multivalued map of message headers.
-
getDate
public java.util.Date getDate()
Get message date.- Returns:
- the message date, otherwise
nullif not present.
-
getIfMatch
public java.util.Set<MatchingEntityTag> getIfMatch()
Get If-Match header.- Returns:
- the If-Match header value, otherwise
nullif not present.
-
getIfNoneMatch
public java.util.Set<MatchingEntityTag> getIfNoneMatch()
Get If-None-Match header.- Returns:
- the If-None-Match header value, otherwise
nullif not present.
-
getLanguage
public java.util.Locale getLanguage()
Get the language of the entity.- Returns:
- the language of the entity or
nullif 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
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).
-
getQualifiedAcceptableMediaTypes
public java.util.List<AcceptableMediaType> 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
public java.util.List<AcceptableLanguageTag> 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
public java.util.List<AcceptableToken> 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
public java.util.List<AcceptableToken> 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
public java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> getRequestCookies()
Get any cookies that accompanied the request.- Returns:
- a read-only map of cookie name (String) to
Cookie.
-
getAllowedMethods
public java.util.Set<java.lang.String> 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
public java.util.Map<java.lang.String,javax.ws.rs.core.NewCookie> getResponseCookies()
Get any new cookies set on the response 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
public java.util.Date getLastModified()
Get the last modified date.- Returns:
- the last modified date, otherwise
nullif not present.
-
getLocation
public java.net.URI getLocation()
Get the location.- Returns:
- the location URI, otherwise
nullif not present.
-
getLinks
public java.util.Set<javax.ws.rs.core.Link> getLinks()
Get the links attached to the message as header.- Returns:
- links, may return empty
Setif no links are present. Never returnsnull.
-
hasLink
public boolean hasLink(java.lang.String relation)
Check if link for relation exists.- Parameters:
relation- link relation.- Returns:
trueif the for the relation link exists,falseotherwise.
-
getLink
public javax.ws.rs.core.Link getLink(java.lang.String relation)
Get the link for the relation.- Parameters:
relation- link relation.- Returns:
- the link for the relation, otherwise
nullif not present.
-
getLinkBuilder
public javax.ws.rs.core.Link.Builder getLinkBuilder(java.lang.String relation)
Convenience method that returns aLink.Builderfor the relation.- Parameters:
relation- link relation.- Returns:
- the link builder for the relation, otherwise
nullif not present.
-
getWorkers
public MessageBodyWorkers getWorkers()
Get context message body workers.- Returns:
- context message body workers.
-
setWorkers
public void setWorkers(MessageBodyWorkers workers)
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 returnstrueif the entity is present, returnsfalseotherwise.- Returns:
trueif there is an entity present in the message,falseotherwise.
-
getEntityStream
public java.io.InputStream getEntityStream()
Get the entity input stream.- Returns:
- entity input stream.
-
setEntityStream
public void setEntityStream(java.io.InputStream input)
Set a new entity input stream.- Parameters:
input- new entity input stream.
-
readEntity
public <T> T readEntity(java.lang.Class<T> rawType, PropertiesDelegate propertiesDelegate)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(java.lang.Class<T> rawType, java.lang.annotation.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
public <T> T readEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type, 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.propertiesDelegate- request-scoped properties delegate.- Returns:
- entity read from a context entity input stream.
-
readEntity
public <T> T readEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type, java.lang.annotation.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
public boolean bufferEntity() throws javax.ws.rs.ProcessingExceptionBuffer the entity stream (if not empty).- Returns:
trueif the entity input stream was successfully buffered.- Throws:
javax.ws.rs.ProcessingException- in case of an IO error.
-
close
public void close()
Closes the underlying content stream.
-
getReaderInterceptors
protected abstract java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> getReaderInterceptors()
Get reader interceptors bound to this context.Interceptors will be used when one of the
readEntitymethods is invoked.- Returns:
- reader interceptors bound to this context.
-
-