Class ContainerRequest
- All Implemented Interfaces:
ContainerRequestContext
,HttpHeaders
,Request
,PropertiesDelegate
,PropertiesResolver
ApplicationHandler
for each incoming client request.- Author:
- Marek Potociar
-
Field Summary
Fields inherited from interface jakarta.ws.rs.core.HttpHeaders
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, EXPECT, 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 Summary
ConstructorDescriptionContainerRequest
(URI baseUri, URI requestUri, String httpMethod, SecurityContext securityContext, PropertiesDelegate propertiesDelegate) Deprecated.ContainerRequest
(URI baseUri, URI requestUri, String httpMethod, SecurityContext securityContext, PropertiesDelegate propertiesDelegate, Configuration configuration) Create new Jersey container request context. -
Method Summary
Modifier and TypeMethodDescriptionvoid
evaluatePreconditions
(Date lastModified) evaluatePreconditions
(Date lastModified, EntityTag eTag) Get the request filter chain aborting response if set, ornull
otherwise.Get the absolute path of the request.Get base request URI.getPath
(boolean decode) Get the path of the current request relative to the application root (base) URI as a string.Get the underlying properties delegate.getProperty
(String name) Returns the property with the given name registered in the current request/response exchange context, ornull
if there is no property by that name.Returns an immutablecollection
containing the property names available within the context of the current request/response exchange context.protected Iterable<ReaderInterceptor>
Get all reader interceptors applicable to this request.getRequestHeader
(String name) Get the values of an HTTP request header if the header exists on the current request.Get the values of HTTP request headers.Get a custom container extensions initializer for the current request.Get request URI.Get the container response writer for the current request.Get the value of HTTP Vary response header to be set in the response, ornull
if no value is to be set.boolean
hasProperty
(String name) Returnstrue
if the property with the given name registered in the current request/response exchange context, orfalse
if there is no property by that name.void
Notify this request that the response created from this request is already being processed.<T> T
readEntity
(Class<T> rawType) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, Annotation[] annotations) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, Type type) Read entity from a context entity input stream.<T> T
readEntity
(Class<T> rawType, Type type, Annotation[] annotations) Read entity from a context entity input stream.void
removeProperty
(String name) Removes a property with the given name from the current request/response exchange context.<T> T
resolveProperty
(String name, Class<T> type) Resolve a property value for the specified propertyname
.<T> T
resolveProperty
(String name, T defaultValue) Resolve a property value for the specified propertyname
.selectVariant
(List<Variant> variants) void
setEntityStream
(InputStream input) Set a new entity input stream.void
void
setMethodWithoutException
(String method) LikesetMethod(String)
but does not throwIllegalStateException
if the method is invoked in other than pre-matching phase.void
setProperty
(String name, 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
(URI requestUri) void
setRequestUri
(URI baseUri, URI requestUri) void
setSecurityContext
(SecurityContext context) void
setWriter
(ContainerResponseWriter responseWriter) Set the container response writer for the current request.Methods inherited from class org.glassfish.jersey.message.internal.InboundMessageContext
bufferEntity, close, getAllowedMethods, getConfiguration, 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
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jakarta.ws.rs.container.ContainerRequestContext
getDate, getEntityStream, getHeaders, getHeaderString, getLanguage, getLength, getMediaType, hasEntity
Methods inherited from interface jakarta.ws.rs.core.HttpHeaders
getDate, getHeaderString, getLanguage, getLength, getMediaType
-
Constructor Details
-
ContainerRequest
public ContainerRequest(URI baseUri, URI requestUri, String httpMethod, SecurityContext securityContext, PropertiesDelegate propertiesDelegate, Configuration configuration) Create new Jersey container request context.- Parameters:
baseUri
- base application URI.requestUri
- request URI.httpMethod
- request HTTP method name.securityContext
- security context of the current request. Must not benull
. TheSecurityContext.getUserPrincipal()
must returnnull
if the current request has not been authenticated by the container.propertiesDelegate
- customproperties delegate
to be used by the context.configuration
- the serverConfiguration
. Ifnull
, the default behaviour is expected.
-
ContainerRequest
@Deprecated public ContainerRequest(URI baseUri, URI requestUri, String httpMethod, SecurityContext securityContext, PropertiesDelegate propertiesDelegate) Deprecated.Create new Jersey container request context.- Parameters:
baseUri
- base application URI.requestUri
- request URI.httpMethod
- request HTTP method name.securityContext
- security context of the current request. Must not benull
. TheSecurityContext.getUserPrincipal()
must returnnull
if the current request has not been authenticated by the container.propertiesDelegate
- customproperties delegate
to be used by the context.- See Also:
-
-
Method Details
-
getRequestScopedInitializer
Get a custom container extensions initializer for the current request. The initializer is guaranteed to be run from within the request scope of the current request.- Returns:
- custom container extensions initializer or
null
if not available.
-
setRequestScopedInitializer
Set a custom container extensions initializer for the current request. The initializer is guaranteed to be run from within the request scope of the current request.- Parameters:
requestScopedInitializer
- custom container extensions initializer.
-
getResponseWriter
Get the container response writer for the current request.- Returns:
- container response writer.
-
setWriter
Set the container response writer for the current request.- Parameters:
responseWriter
- container response writer. Must not benull
.
-
readEntity
Read entity from a context entity input stream.- Type Parameters:
T
- entity Java object type.- Parameters:
rawType
- raw Java entity type.- 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.annotations
- entity annotations.- 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.- 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.annotations
- entity annotations.- Returns:
- entity read from a context entity input stream.
-
resolveProperty
Description copied from interface:PropertiesResolver
Resolve a property value for the specified propertyname
.The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the
global runtime configuration
this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returnsnull
if no such property is registered neither in the runtime nor in the request-specific property bag.- Specified by:
resolveProperty
in interfacePropertiesResolver
- Type Parameters:
T
- property Java type.- Parameters:
name
- property name.type
- expected property class type.- Returns:
- resolved property value or
null
if no such property is registered.
-
resolveProperty
Description copied from interface:PropertiesResolver
Resolve a property value for the specified propertyname
.The method returns the value of the property registered in the request-specific property bag, if available. If no property for the given property name is found in the request-specific property bag, the method looks at the properties stored in the
global runtime configuration
this request belongs to. If there is a value defined in the runtime configuration, it is returned, otherwise the method returnsdefaultValue
if no such property is registered neither in the runtime nor in the request-specific property bag.- Specified by:
resolveProperty
in interfacePropertiesResolver
- Type Parameters:
T
- property Java type.- Parameters:
name
- property name.defaultValue
- default value to return if the property is not registered.- Returns:
- resolved property value or
defaultValue
if no such property is registered.
-
hasProperty
Description copied from interface:PropertiesDelegate
Returnstrue
if the property with the given name registered in the current request/response exchange context, orfalse
if there is no property by that name.Use the
PropertiesDelegate.getProperty(java.lang.String)
method with a property name to get the value of a property.- Specified by:
hasProperty
in interfaceContainerRequestContext
- Specified by:
hasProperty
in interfacePropertiesDelegate
- Returns:
true
if a property matching the given name exists, orfalse
otherwise.- See Also:
-
getProperty
Description copied from interface:PropertiesDelegate
Returns the property with the given name registered in the current request/response exchange context, ornull
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.- Specified by:
getProperty
in interfaceContainerRequestContext
- Specified by:
getProperty
in interfacePropertiesDelegate
- Parameters:
name
- aString
specifying the name of the property.- Returns:
- an
Object
containing the value of the property, ornull
if no property exists matching the given name. - See Also:
-
getPropertyNames
Description copied from interface:PropertiesDelegate
Returns an immutablecollection
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.- Specified by:
getPropertyNames
in interfaceContainerRequestContext
- Specified by:
getPropertyNames
in interfacePropertiesDelegate
- Returns:
- an immutable
collection
of property names. - See Also:
-
setProperty
Description copied from interface:PropertiesDelegate
Binds an object to a given property name in the current request/response exchange context. If the name specified is already used for a property, this method will replace the value of the property with the new value.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 thePropertiesDelegate.removeProperty(String)
method.- Specified by:
setProperty
in interfaceContainerRequestContext
- Specified by:
setProperty
in interfacePropertiesDelegate
- Parameters:
name
- aString
specifying the name of the property.object
- anObject
representing the property to be bound.
-
removeProperty
Description copied from interface:PropertiesDelegate
Removes a property with the given name from the current request/response exchange context. After removal, subsequent calls toPropertiesDelegate.getProperty(java.lang.String)
to retrieve the property value will returnnull
.- Specified by:
removeProperty
in interfaceContainerRequestContext
- Specified by:
removeProperty
in interfacePropertiesDelegate
- Parameters:
name
- aString
specifying the name of the property to be removed.
-
getPropertiesDelegate
Get the underlying properties delegate.- Returns:
- underlying properties delegate.
-
getUriInfo
- Specified by:
getUriInfo
in interfaceContainerRequestContext
-
getReaderInterceptors
Get all reader interceptors applicable to this request. This is populated once the right resource method is matched.- Specified by:
getReaderInterceptors
in classInboundMessageContext
- Returns:
- All reader interceptors applicable to the matched inflector (or an empty collection if no inflector matched yet).
-
getBaseUri
Get base request URI.- Returns:
- base request URI.
-
getRequestUri
Get request URI.- Returns:
- request URI.
-
getAbsolutePath
Get the absolute path of the request. This includes everything preceding the path (host, port etc), but excludes query parameters or fragment.- Returns:
- the absolute path of the request.
-
setRequestUri
- Specified by:
setRequestUri
in interfaceContainerRequestContext
- Throws:
IllegalStateException
-
setRequestUri
- Specified by:
setRequestUri
in interfaceContainerRequestContext
- Throws:
IllegalStateException
-
getPath
Get the path of the current request relative to the application root (base) URI as a string.- Parameters:
decode
- controls whether sequences of escaped octets are decoded (true
) or not (false
).- Returns:
- relative request path.
-
getMethod
- Specified by:
getMethod
in interfaceContainerRequestContext
- Specified by:
getMethod
in interfaceRequest
-
setMethod
- Specified by:
setMethod
in interfaceContainerRequestContext
- Throws:
IllegalStateException
-
setMethodWithoutException
LikesetMethod(String)
but does not throwIllegalStateException
if the method is invoked in other than pre-matching phase.- Parameters:
method
- HTTP method.
-
getSecurityContext
- Specified by:
getSecurityContext
in interfaceContainerRequestContext
-
setSecurityContext
- Specified by:
setSecurityContext
in interfaceContainerRequestContext
-
setEntityStream
Description copied from class:InboundMessageContext
Set a new entity input stream.- Specified by:
setEntityStream
in interfaceContainerRequestContext
- Overrides:
setEntityStream
in classInboundMessageContext
- Parameters:
input
- new entity input stream.
-
getRequest
- Specified by:
getRequest
in interfaceContainerRequestContext
-
abortWith
- Specified by:
abortWith
in interfaceContainerRequestContext
-
inResponseProcessing
public void inResponseProcessing()Notify this request that the response created from this request is already being processed. This means that the request processing phase has finished and this request can be used only in the request processing phase (for example in ContainerResponseFilter). The request can be used for processing of more than one response (in async cases). Then this method should be called when the first response is created from this request. Multiple calls to this method has the same effect as calling the method only once. -
getAbortResponse
Get the request filter chain aborting response if set, ornull
otherwise.- Returns:
- request filter chain aborting response if set, or
null
otherwise.
-
getCookies
- Specified by:
getCookies
in interfaceContainerRequestContext
- Specified by:
getCookies
in interfaceHttpHeaders
-
getAcceptableMediaTypes
- Specified by:
getAcceptableMediaTypes
in interfaceContainerRequestContext
- Specified by:
getAcceptableMediaTypes
in interfaceHttpHeaders
-
getAcceptableLanguages
- Specified by:
getAcceptableLanguages
in interfaceContainerRequestContext
- Specified by:
getAcceptableLanguages
in interfaceHttpHeaders
-
selectVariant
- Specified by:
selectVariant
in interfaceRequest
- Throws:
IllegalArgumentException
-
getVaryValue
Get the value of HTTP Vary response header to be set in the response, ornull
if no value is to be set.- Returns:
- value of HTTP Vary response header to be set in the response if available,
null
otherwise.
-
evaluatePreconditions
- Specified by:
evaluatePreconditions
in interfaceRequest
-
evaluatePreconditions
- Specified by:
evaluatePreconditions
in interfaceRequest
-
evaluatePreconditions
- Specified by:
evaluatePreconditions
in interfaceRequest
-
evaluatePreconditions
- Specified by:
evaluatePreconditions
in interfaceRequest
-
getRequestHeader
Get the values of an HTTP request header if the header exists on the current request. The returned value will be a read-only List if the specified header exists ornull
if it does not. This is a shortcut forgetRequestHeaders().get(name)
.- Specified by:
getRequestHeader
in interfaceHttpHeaders
- Parameters:
name
- the header name, case insensitive.- Returns:
- a read-only list of header values if the specified header exists, otherwise
null
. - Throws:
IllegalStateException
- if called outside the scope of a request.
-
getRequestHeaders
Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returnsnull
.- Specified by:
getRequestHeaders
in interfaceHttpHeaders
- Returns:
- a read-only map of header names and values.
- Throws:
IllegalStateException
- if called outside the scope of a request.
-