public class ContainerRequest extends InboundMessageContext implements javax.ws.rs.container.ContainerRequestContext, javax.ws.rs.core.Request, javax.ws.rs.core.HttpHeaders, PropertiesDelegate
ApplicationHandler
for each incoming client request.ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONTENT_DISPOSITION, CONTENT_ENCODING, CONTENT_ID, CONTENT_LANGUAGE, CONTENT_LENGTH, CONTENT_LOCATION, CONTENT_TYPE, COOKIE, DATE, ETAG, EXPIRES, HOST, IF_MATCH, IF_MODIFIED_SINCE, IF_NONE_MATCH, IF_UNMODIFIED_SINCE, LAST_EVENT_ID_HEADER, LAST_MODIFIED, LINK, LOCATION, RETRY_AFTER, SET_COOKIE, USER_AGENT, VARY, WWW_AUTHENTICATE
Constructor and Description |
---|
ContainerRequest(java.net.URI baseUri,
java.net.URI requestUri,
java.lang.String httpMethod,
javax.ws.rs.core.SecurityContext securityContext,
PropertiesDelegate propertiesDelegate)
Create new Jersey container request context.
|
Modifier and Type | Method and Description |
---|---|
void |
abortWith(javax.ws.rs.core.Response response) |
(package private) void |
checkState()
Check if the container request has been properly initialized for processing.
|
private static <T> java.lang.Iterable<T> |
emptyIfNull(java.lang.Iterable<T> iterable) |
private java.lang.String |
encodedRelativePath() |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfMatch(javax.ws.rs.core.EntityTag eTag) |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfModifiedSince(long lastModified) |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfModifiedSince(long lastModified,
java.lang.String ifModifiedSinceHeader) |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfNoneMatch(javax.ws.rs.core.EntityTag eTag) |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfNoneMatch(javax.ws.rs.core.EntityTag eTag,
java.util.Set<? extends javax.ws.rs.core.EntityTag> matchingTags,
boolean isGetOrHead) |
private javax.ws.rs.core.Response.ResponseBuilder |
evaluateIfUnmodifiedSince(long lastModified) |
javax.ws.rs.core.Response.ResponseBuilder |
evaluatePreconditions() |
javax.ws.rs.core.Response.ResponseBuilder |
evaluatePreconditions(java.util.Date lastModified) |
javax.ws.rs.core.Response.ResponseBuilder |
evaluatePreconditions(java.util.Date lastModified,
javax.ws.rs.core.EntityTag eTag) |
javax.ws.rs.core.Response.ResponseBuilder |
evaluatePreconditions(javax.ws.rs.core.EntityTag eTag) |
javax.ws.rs.core.Response |
getAbortResponse()
Get the request filter chain aborting response if set, or
null otherwise. |
java.net.URI |
getAbsolutePath()
Get the absolute path of the request.
|
java.util.List<java.util.Locale> |
getAcceptableLanguages() |
java.util.List<javax.ws.rs.core.MediaType> |
getAcceptableMediaTypes() |
java.net.URI |
getBaseUri()
Get base request URI.
|
java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> |
getCookies() |
private Inflector<RequestProcessingContext,ContainerResponse> |
getInflector() |
java.lang.String |
getMethod() |
java.lang.String |
getPath(boolean decode)
Get the path of the current request relative to the application root (base)
URI as a string.
|
PropertiesDelegate |
getPropertiesDelegate()
Get the underlying properties delegate.
|
java.lang.Object |
getProperty(java.lang.String name)
Returns the property with the given name registered in the current request/response
exchange context, or
null if there is no property by that name. |
java.util.Collection<java.lang.String> |
getPropertyNames()
Returns an immutable
collection containing the property
names available within the context of the current request/response exchange context. |
protected java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> |
getReaderInterceptors()
Get all reader interceptors applicable to this request.
|
javax.ws.rs.core.Request |
getRequest() |
(package private) java.lang.Iterable<RankedProvider<javax.ws.rs.container.ContainerRequestFilter>> |
getRequestFilters()
Get all bound request filters applicable to this request.
|
java.util.List<java.lang.String> |
getRequestHeader(java.lang.String name)
Get the values of a HTTP request header.
|
javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> |
getRequestHeaders()
Get the values of HTTP request headers.
|
RequestScopedInitializer |
getRequestScopedInitializer()
Get a custom container extensions initializer for the current request.
|
java.net.URI |
getRequestUri()
Get request URI.
|
(package private) java.lang.Iterable<RankedProvider<javax.ws.rs.container.ContainerResponseFilter>> |
getResponseFilters()
Get all bound response filters applicable to this request.
|
ContainerResponseWriter |
getResponseWriter()
Get the container response writer for the current request.
|
javax.ws.rs.core.SecurityContext |
getSecurityContext() |
ExtendedUriInfo |
getUriInfo() |
(package private) UriRoutingContext |
getUriRoutingContext() |
java.lang.String |
getVaryValue()
Get the value of HTTP Vary response header to be set in the response,
or
null if no value is to be set. |
(package private) java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> |
getWriterInterceptors()
Get all writer interceptors applicable to this request.
|
void |
inResponseProcessing()
Notify this request that the response created from this request is already being
processed.
|
<T> T |
readEntity(java.lang.Class<T> rawType)
Read entity from a context entity input stream.
|
<T> T |
readEntity(java.lang.Class<T> rawType,
java.lang.annotation.Annotation[] annotations)
Read entity from a context entity input stream.
|
<T> T |
readEntity(java.lang.Class<T> rawType,
java.lang.reflect.Type type)
Read entity from a context entity input stream.
|
<T> T |
readEntity(java.lang.Class<T> rawType,
java.lang.reflect.Type type,
java.lang.annotation.Annotation[] annotations)
Read entity from a context entity input stream.
|
void |
removeProperty(java.lang.String name)
Removes a property with the given name from the current request/response
exchange context.
|
private static long |
roundDown(long time)
Round down the time to the nearest second.
|
javax.ws.rs.core.Variant |
selectVariant(java.util.List<javax.ws.rs.core.Variant> variants) |
void |
setEntityStream(java.io.InputStream input)
Set a new entity input stream.
|
void |
setMethod(java.lang.String method) |
void |
setMethodWithoutException(java.lang.String method)
Like
setMethod(String) but does not throw IllegalStateException if the method is invoked in other than
pre-matching phase. |
(package private) void |
setProcessingProviders(ProcessingProviders providers) |
void |
setProperty(java.lang.String name,
java.lang.Object object)
Binds an object to a given property name in the current request/response
exchange context.
|
void |
setRequestScopedInitializer(RequestScopedInitializer requestScopedInitializer)
Set a custom container extensions initializer for the current request.
|
void |
setRequestUri(java.net.URI requestUri) |
void |
setRequestUri(java.net.URI baseUri,
java.net.URI requestUri) |
void |
setSecurityContext(javax.ws.rs.core.SecurityContext context) |
void |
setWriter(ContainerResponseWriter responseWriter)
Set the container response writer for the current request.
|
bufferEntity, close, getAllowedMethods, getDate, getEntityStream, getEntityTag, getHeaders, getHeaderString, getIfMatch, getIfNoneMatch, getLanguage, getLastModified, getLength, getLink, getLinkBuilder, getLinks, getLocation, getMediaType, getQualifiedAcceptableLanguages, getQualifiedAcceptableMediaTypes, getQualifiedAcceptCharset, getQualifiedAcceptEncoding, getRequestCookies, getResponseCookies, getWorkers, hasEntity, hasLink, header, headers, headers, headers, headers, readEntity, readEntity, readEntity, readEntity, remove, setWorkers
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
private static final java.net.URI DEFAULT_BASE_URI
private final PropertiesDelegate propertiesDelegate
private final UriRoutingContext uriRoutingContext
private java.net.URI baseUri
private java.net.URI requestUri
private java.lang.String encodedRelativePath
private java.lang.String decodedRelativePath
private java.net.URI absolutePathUri
private java.lang.String httpMethod
private javax.ws.rs.core.SecurityContext securityContext
private javax.ws.rs.core.Response abortResponse
private java.lang.String varyValue
private ProcessingProviders processingProviders
private RequestScopedInitializer requestScopedInitializer
private ContainerResponseWriter responseWriter
private boolean inResponseProcessingPhase
private static final java.lang.String ERROR_REQUEST_SET_ENTITY_STREAM_IN_RESPONSE_PHASE
private static final java.lang.String ERROR_REQUEST_SET_SECURITY_CONTEXT_IN_RESPONSE_PHASE
private static final java.lang.String ERROR_REQUEST_ABORT_IN_RESPONSE_PHASE
private static final java.lang.String METHOD_PARAMETER_CANNOT_BE_NULL_OR_EMPTY
private static final java.lang.String METHOD_PARAMETER_CANNOT_BE_NULL_ETAG
private static final java.lang.String METHOD_PARAMETER_CANNOT_BE_NULL_LAST_MODIFIED
public ContainerRequest(java.net.URI baseUri, java.net.URI requestUri, java.lang.String httpMethod, javax.ws.rs.core.SecurityContext securityContext, PropertiesDelegate propertiesDelegate)
baseUri
- base application URI.requestUri
- request URI.httpMethod
- request HTTP method name.securityContext
- security context of the current request. Must not be null
.
The SecurityContext.getUserPrincipal()
must return
null
if the current request has not been authenticated
by the container.propertiesDelegate
- custom properties delegate
to be used by the context.public RequestScopedInitializer getRequestScopedInitializer()
null
if not
available.public void setRequestScopedInitializer(RequestScopedInitializer requestScopedInitializer)
requestScopedInitializer
- custom container extensions initializer.public ContainerResponseWriter getResponseWriter()
public void setWriter(ContainerResponseWriter responseWriter)
responseWriter
- container response writer. Must not be null
.public <T> T readEntity(java.lang.Class<T> rawType)
T
- entity Java object type.rawType
- raw Java entity type.public <T> T readEntity(java.lang.Class<T> rawType, java.lang.annotation.Annotation[] annotations)
T
- entity Java object type.rawType
- raw Java entity type.annotations
- entity annotations.public <T> T readEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type)
T
- entity Java object type.rawType
- raw Java entity type.type
- generic Java entity type.public <T> T readEntity(java.lang.Class<T> rawType, java.lang.reflect.Type type, java.lang.annotation.Annotation[] annotations)
T
- entity Java object type.rawType
- raw Java entity type.type
- generic Java entity type.annotations
- entity annotations.public java.lang.Object getProperty(java.lang.String name)
PropertiesDelegate
null
if there is no property by that name.
A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.
A list of supported properties can be retrieved using PropertiesDelegate.getPropertyNames()
.
Custom property names should follow the same convention as package names.
getProperty
in interface javax.ws.rs.container.ContainerRequestContext
getProperty
in interface PropertiesDelegate
name
- a String
specifying the name of the property.Object
containing the value of the property, or
null
if no property exists matching the given name.PropertiesDelegate.getPropertyNames()
public java.util.Collection<java.lang.String> getPropertyNames()
PropertiesDelegate
collection
containing the property
names available within the context of the current request/response exchange context.
Use the PropertiesDelegate.getProperty(java.lang.String)
method with a property name to get the value of
a property.
getPropertyNames
in interface javax.ws.rs.container.ContainerRequestContext
getPropertyNames
in interface PropertiesDelegate
collection
of property names.PropertiesDelegate.getProperty(java.lang.String)
public void setProperty(java.lang.String name, java.lang.Object object)
PropertiesDelegate
A property allows a JAX-RS filters and interceptors to exchange additional custom information not already provided by this interface.
A list of supported properties can be retrieved using PropertiesDelegate.getPropertyNames()
.
Custom property names should follow the same convention as package names.
If a null
value is passed, the effect is the same as calling the
PropertiesDelegate.removeProperty(String)
method.
setProperty
in interface javax.ws.rs.container.ContainerRequestContext
setProperty
in interface PropertiesDelegate
name
- a String
specifying the name of the property.object
- an Object
representing the property to be bound.public void removeProperty(java.lang.String name)
PropertiesDelegate
PropertiesDelegate.getProperty(java.lang.String)
to retrieve the property value will return null
.removeProperty
in interface javax.ws.rs.container.ContainerRequestContext
removeProperty
in interface PropertiesDelegate
name
- a String
specifying the name of the property to be removed.public PropertiesDelegate getPropertiesDelegate()
public ExtendedUriInfo getUriInfo()
getUriInfo
in interface javax.ws.rs.container.ContainerRequestContext
void setProcessingProviders(ProcessingProviders providers)
UriRoutingContext getUriRoutingContext()
java.lang.Iterable<RankedProvider<javax.ws.rs.container.ContainerRequestFilter>> getRequestFilters()
java.lang.Iterable<RankedProvider<javax.ws.rs.container.ContainerResponseFilter>> getResponseFilters()
protected java.lang.Iterable<javax.ws.rs.ext.ReaderInterceptor> getReaderInterceptors()
getReaderInterceptors
in class InboundMessageContext
java.lang.Iterable<javax.ws.rs.ext.WriterInterceptor> getWriterInterceptors()
private Inflector<RequestProcessingContext,ContainerResponse> getInflector()
private static <T> java.lang.Iterable<T> emptyIfNull(java.lang.Iterable<T> iterable)
public java.net.URI getBaseUri()
public java.net.URI getRequestUri()
public java.net.URI getAbsolutePath()
public void setRequestUri(java.net.URI requestUri) throws java.lang.IllegalStateException
setRequestUri
in interface javax.ws.rs.container.ContainerRequestContext
java.lang.IllegalStateException
public void setRequestUri(java.net.URI baseUri, java.net.URI requestUri) throws java.lang.IllegalStateException
setRequestUri
in interface javax.ws.rs.container.ContainerRequestContext
java.lang.IllegalStateException
public java.lang.String getPath(boolean decode)
decode
- controls whether sequences of escaped octets are decoded
(true
) or not (false
).private java.lang.String encodedRelativePath()
public java.lang.String getMethod()
getMethod
in interface javax.ws.rs.container.ContainerRequestContext
getMethod
in interface javax.ws.rs.core.Request
public void setMethod(java.lang.String method) throws java.lang.IllegalStateException
setMethod
in interface javax.ws.rs.container.ContainerRequestContext
java.lang.IllegalStateException
public void setMethodWithoutException(java.lang.String method)
setMethod(String)
but does not throw IllegalStateException
if the method is invoked in other than
pre-matching phase.method
- HTTP method.public javax.ws.rs.core.SecurityContext getSecurityContext()
getSecurityContext
in interface javax.ws.rs.container.ContainerRequestContext
public void setSecurityContext(javax.ws.rs.core.SecurityContext context)
setSecurityContext
in interface javax.ws.rs.container.ContainerRequestContext
public void setEntityStream(java.io.InputStream input)
InboundMessageContext
setEntityStream
in interface javax.ws.rs.container.ContainerRequestContext
setEntityStream
in class InboundMessageContext
input
- new entity input stream.public javax.ws.rs.core.Request getRequest()
getRequest
in interface javax.ws.rs.container.ContainerRequestContext
public void abortWith(javax.ws.rs.core.Response response)
abortWith
in interface javax.ws.rs.container.ContainerRequestContext
public void inResponseProcessing()
public javax.ws.rs.core.Response getAbortResponse()
null
otherwise.null
otherwise.public java.util.Map<java.lang.String,javax.ws.rs.core.Cookie> getCookies()
getCookies
in interface javax.ws.rs.container.ContainerRequestContext
getCookies
in interface javax.ws.rs.core.HttpHeaders
public java.util.List<javax.ws.rs.core.MediaType> getAcceptableMediaTypes()
getAcceptableMediaTypes
in interface javax.ws.rs.container.ContainerRequestContext
getAcceptableMediaTypes
in interface javax.ws.rs.core.HttpHeaders
public java.util.List<java.util.Locale> getAcceptableLanguages()
getAcceptableLanguages
in interface javax.ws.rs.container.ContainerRequestContext
getAcceptableLanguages
in interface javax.ws.rs.core.HttpHeaders
public javax.ws.rs.core.Variant selectVariant(java.util.List<javax.ws.rs.core.Variant> variants) throws java.lang.IllegalArgumentException
selectVariant
in interface javax.ws.rs.core.Request
java.lang.IllegalArgumentException
public java.lang.String getVaryValue()
null
if no value is to be set.null
otherwise.public javax.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(javax.ws.rs.core.EntityTag eTag)
evaluatePreconditions
in interface javax.ws.rs.core.Request
public javax.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(java.util.Date lastModified)
evaluatePreconditions
in interface javax.ws.rs.core.Request
public javax.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(java.util.Date lastModified, javax.ws.rs.core.EntityTag eTag)
evaluatePreconditions
in interface javax.ws.rs.core.Request
public javax.ws.rs.core.Response.ResponseBuilder evaluatePreconditions()
evaluatePreconditions
in interface javax.ws.rs.core.Request
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfMatch(javax.ws.rs.core.EntityTag eTag)
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfNoneMatch(javax.ws.rs.core.EntityTag eTag)
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfNoneMatch(javax.ws.rs.core.EntityTag eTag, java.util.Set<? extends javax.ws.rs.core.EntityTag> matchingTags, boolean isGetOrHead)
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfUnmodifiedSince(long lastModified)
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfModifiedSince(long lastModified)
private javax.ws.rs.core.Response.ResponseBuilder evaluateIfModifiedSince(long lastModified, java.lang.String ifModifiedSinceHeader)
private static long roundDown(long time)
time
- the time to round down.public java.util.List<java.lang.String> getRequestHeader(java.lang.String name)
getRequestHeaders().get(name)
.getRequestHeader
in interface javax.ws.rs.core.HttpHeaders
name
- the header name, case insensitive.java.lang.IllegalStateException
- if called outside the scope of a request.public javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> getRequestHeaders()
null
.getRequestHeaders
in interface javax.ws.rs.core.HttpHeaders
java.lang.IllegalStateException
- if called outside the scope of a request.void checkState() throws java.lang.IllegalStateException
java.lang.IllegalStateException
- in case the internal state is not ready for processing.