org.glassfish.jersey.server

## Class ContainerRequest

- java.lang.Object
- - org.glassfish.jersey.message.internal.InboundMessageContext
  - - org.glassfish.jersey.server.ContainerRequest

All Implemented Interfaces:
  jakarta.ws.rs.container.ContainerRequestContext, jakarta.ws.rs.core.HttpHeaders, jakarta.ws.rs.core.Request, org.glassfish.jersey.internal.PropertiesDelegate

    public class ContainerRequest
    extends org.glassfish.jersey.message.internal.InboundMessageContext
    implements jakarta.ws.rs.container.ContainerRequestContext, jakarta.ws.rs.core.Request, jakarta.ws.rs.core.HttpHeaders, org.glassfish.jersey.internal.PropertiesDelegate

Jersey container request context.

An instance of the request context is passed by the container to the `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, 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

Constructors
Constructor and Description
`ContainerRequest(URI baseUri, URI requestUri, String httpMethod, jakarta.ws.rs.core.SecurityContext securityContext, org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate)` Deprecated.
`ContainerRequest(URI baseUri, URI requestUri, String httpMethod, jakarta.ws.rs.core.SecurityContext securityContext, org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate, jakarta.ws.rs.core.Configuration configuration)` Create new Jersey container request context.

### Method Summary

All Methods Instance Methods Concrete Methods
`void` `abortWith(jakarta.ws.rs.core.Response response)`
`jakarta.ws.rs.core.Response.ResponseBuilder` `evaluatePreconditions()`
`jakarta.ws.rs.core.Response.ResponseBuilder` `evaluatePreconditions(Date lastModified)`
`jakarta.ws.rs.core.Response.ResponseBuilder` `evaluatePreconditions(Date lastModified, jakarta.ws.rs.core.EntityTag eTag)`
`jakarta.ws.rs.core.Response.ResponseBuilder` `evaluatePreconditions(jakarta.ws.rs.core.EntityTag eTag)`
`jakarta.ws.rs.core.Response` `getAbortResponse()` Get the request filter chain aborting response if set, or `null` otherwise.
`URI` `getAbsolutePath()` Get the absolute path of the request.
`List<Locale>` `getAcceptableLanguages()`
`List<jakarta.ws.rs.core.MediaType>` `getAcceptableMediaTypes()`
`URI` `getBaseUri()` Get base request URI.
`Map<String,jakarta.ws.rs.core.Cookie>` `getCookies()`
`String` `getMethod()`
`String` `getPath(boolean decode)` Get the path of the current request relative to the application root (base) URI as a string.
`org.glassfish.jersey.internal.PropertiesDelegate` `getPropertiesDelegate()` Get the underlying properties delegate.
`Object` `getProperty(String name)`
`Collection<String>` `getPropertyNames()`
`protected Iterable<jakarta.ws.rs.ext.ReaderInterceptor>` `getReaderInterceptors()` Get all reader interceptors applicable to this request.
`jakarta.ws.rs.core.Request` `getRequest()`
`List<String>` `getRequestHeader(String name)` Get the values of a HTTP request header.
`jakarta.ws.rs.core.MultivaluedMap<String,String>` `getRequestHeaders()` Get the values of HTTP request headers.
`RequestScopedInitializer` `getRequestScopedInitializer()` Get a custom container extensions initializer for the current request.
`URI` `getRequestUri()` Get request URI.
`ContainerResponseWriter` `getResponseWriter()` Get the container response writer for the current request.
`jakarta.ws.rs.core.SecurityContext` `getSecurityContext()`
`ExtendedUriInfo` `getUriInfo()`
`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.
`void` `inResponseProcessing()` 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)`
`jakarta.ws.rs.core.Variant` `selectVariant(List<jakarta.ws.rs.core.Variant> variants)`
`void` `setEntityStream(InputStream input)`
`void` `setMethod(String method)`
`void` `setMethodWithoutException(String method)` Like `setMethod(String)` but does not throw `IllegalStateException` if the method is invoked in other than pre-matching phase.
`void` `setProperty(String name, Object object)`
`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(jakarta.ws.rs.core.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 Detail

#### ContainerRequest

    public ContainerRequest(URI baseUri,
                            URI requestUri,
                            String httpMethod,
                            jakarta.ws.rs.core.SecurityContext securityContext,
                            org.glassfish.jersey.internal.PropertiesDelegate propertiesDelegate,
                            jakarta.ws.rs.core.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 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.
  `configuration` - the server `Configuration`. If `null`, the default behaviour is expected.

#### ContainerRequest

    @Deprecated
    public ContainerRequest(URI baseUri,
                                        URI requestUri,
                                        String httpMethod,
                                        jakarta.ws.rs.core.SecurityContext securityContext,
                                        org.glassfish.jersey.internal.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 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.
See Also:
  `ContainerRequest(URI, URI, String, SecurityContext, PropertiesDelegate, Configuration)`

### Method Detail

#### getRequestScopedInitializer

    public RequestScopedInitializer 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

    public void setRequestScopedInitializer(RequestScopedInitializer requestScopedInitializer)

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

    public ContainerResponseWriter getResponseWriter()

Get the container response writer for the current request.

Returns:
  container response writer.

#### setWriter

    public void setWriter(ContainerResponseWriter responseWriter)

Set the container response writer for the current request.

Parameters:
  `responseWriter` - container response writer. Must not be `null`.

#### readEntity

    public <T> T readEntity(Class<T> rawType)

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

    public <T> T readEntity(Class<T> rawType,
                            Annotation[] annotations)

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

    public <T> T readEntity(Class<T> rawType,
                            Type type)

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

    public <T> T readEntity(Class<T> rawType,
                            Type type,
                            Annotation[] annotations)

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.

#### getProperty

    public Object getProperty(String name)

Specified by:
  `getProperty` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getProperty` in interface `org.glassfish.jersey.internal.PropertiesDelegate`

#### getPropertyNames

    public Collection<String> getPropertyNames()

Specified by:
  `getPropertyNames` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getPropertyNames` in interface `org.glassfish.jersey.internal.PropertiesDelegate`

#### setProperty

    public void setProperty(String name,
                            Object object)

Specified by:
  `setProperty` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `setProperty` in interface `org.glassfish.jersey.internal.PropertiesDelegate`

#### removeProperty

    public void removeProperty(String name)

Specified by:
  `removeProperty` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `removeProperty` in interface `org.glassfish.jersey.internal.PropertiesDelegate`

#### getPropertiesDelegate

    public org.glassfish.jersey.internal.PropertiesDelegate getPropertiesDelegate()

Get the underlying properties delegate.

Returns:
  underlying properties delegate.

#### getUriInfo

    public ExtendedUriInfo getUriInfo()

Specified by:
  `getUriInfo` in interface `jakarta.ws.rs.container.ContainerRequestContext`

#### getReaderInterceptors

    protected Iterable<jakarta.ws.rs.ext.ReaderInterceptor> getReaderInterceptors()

Get all reader interceptors applicable to this request. This is populated once the right resource method is matched.

Specified by:
  `getReaderInterceptors` in class `org.glassfish.jersey.message.internal.InboundMessageContext`
Returns:
  All reader interceptors applicable to the matched inflector (or an empty collection if no inflector matched yet).

#### getBaseUri

    public URI getBaseUri()

Get base request URI.

Returns:
  base request URI.

#### getRequestUri

    public URI getRequestUri()

Get request URI.

Returns:
  request URI.

#### getAbsolutePath

    public 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

    public void setRequestUri(URI requestUri)
                       throws IllegalStateException

Specified by:
  `setRequestUri` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Throws:
  `IllegalStateException`

#### setRequestUri

    public void setRequestUri(URI baseUri,
                              URI requestUri)
                       throws IllegalStateException

Specified by:
  `setRequestUri` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Throws:
  `IllegalStateException`

#### getPath

    public String getPath(boolean decode)

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

    public String getMethod()

Specified by:
  `getMethod` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getMethod` in interface `jakarta.ws.rs.core.Request`

#### setMethod

    public void setMethod(String method)
                   throws IllegalStateException

Specified by:
  `setMethod` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Throws:
  `IllegalStateException`

#### setMethodWithoutException

    public void setMethodWithoutException(String method)

Like `setMethod(String)` but does not throw `IllegalStateException` if the method is invoked in other than pre-matching phase.

Parameters:
  `method` - HTTP method.

#### getSecurityContext

    public jakarta.ws.rs.core.SecurityContext getSecurityContext()

Specified by:
  `getSecurityContext` in interface `jakarta.ws.rs.container.ContainerRequestContext`

#### setSecurityContext

    public void setSecurityContext(jakarta.ws.rs.core.SecurityContext context)

Specified by:
  `setSecurityContext` in interface `jakarta.ws.rs.container.ContainerRequestContext`

#### setEntityStream

    public void setEntityStream(InputStream input)

Specified by:
  `setEntityStream` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Overrides:
  `setEntityStream` in class `org.glassfish.jersey.message.internal.InboundMessageContext`

#### getRequest

    public jakarta.ws.rs.core.Request getRequest()

Specified by:
  `getRequest` in interface `jakarta.ws.rs.container.ContainerRequestContext`

#### abortWith

    public void abortWith(jakarta.ws.rs.core.Response response)

Specified by:
  `abortWith` in interface `jakarta.ws.rs.container.ContainerRequestContext`

#### 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

    public jakarta.ws.rs.core.Response getAbortResponse()

Get the request filter chain aborting response if set, or `null` otherwise.

Returns:
  request filter chain aborting response if set, or `null` otherwise.

#### getCookies

    public Map<String,jakarta.ws.rs.core.Cookie> getCookies()

Specified by:
  `getCookies` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getCookies` in interface `jakarta.ws.rs.core.HttpHeaders`

#### getAcceptableMediaTypes

    public List<jakarta.ws.rs.core.MediaType> getAcceptableMediaTypes()

Specified by:
  `getAcceptableMediaTypes` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getAcceptableMediaTypes` in interface `jakarta.ws.rs.core.HttpHeaders`

#### getAcceptableLanguages

    public List<Locale> getAcceptableLanguages()

Specified by:
  `getAcceptableLanguages` in interface `jakarta.ws.rs.container.ContainerRequestContext`
Specified by:
  `getAcceptableLanguages` in interface `jakarta.ws.rs.core.HttpHeaders`

#### selectVariant

    public jakarta.ws.rs.core.Variant selectVariant(List<jakarta.ws.rs.core.Variant> variants)
                                             throws IllegalArgumentException

Specified by:
  `selectVariant` in interface `jakarta.ws.rs.core.Request`
Throws:
  `IllegalArgumentException`

#### getVaryValue

    public 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.

Returns:
  value of HTTP Vary response header to be set in the response if available, `null` otherwise.

#### evaluatePreconditions

    public jakarta.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(jakarta.ws.rs.core.EntityTag eTag)

Specified by:
  `evaluatePreconditions` in interface `jakarta.ws.rs.core.Request`

#### evaluatePreconditions

    public jakarta.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(Date lastModified)

Specified by:
  `evaluatePreconditions` in interface `jakarta.ws.rs.core.Request`

#### evaluatePreconditions

    public jakarta.ws.rs.core.Response.ResponseBuilder evaluatePreconditions(Date lastModified,
                                                                             jakarta.ws.rs.core.EntityTag eTag)

Specified by:
  `evaluatePreconditions` in interface `jakarta.ws.rs.core.Request`

#### evaluatePreconditions

    public jakarta.ws.rs.core.Response.ResponseBuilder evaluatePreconditions()

Specified by:
  `evaluatePreconditions` in interface `jakarta.ws.rs.core.Request`

#### getRequestHeader

    public List<String> getRequestHeader(String name)

Get the values of a HTTP request header. The returned List is read-only. This is a shortcut for `getRequestHeaders().get(name)`.

Specified by:
  `getRequestHeader` in interface `jakarta.ws.rs.core.HttpHeaders`
Parameters:
  `name` - the header name, case insensitive.
Returns:
  a read-only list of header values.
Throws:
  `IllegalStateException` - if called outside the scope of a request.

#### getRequestHeaders

    public jakarta.ws.rs.core.MultivaluedMap<String,String> getRequestHeaders()

Get the values of HTTP request headers. The returned Map is case-insensitive wrt. keys and is read-only. The method never returns `null`.

Specified by:
  `getRequestHeaders` in interface `jakarta.ws.rs.core.HttpHeaders`
Returns:
  a read-only map of header names and values.
Throws:
  `IllegalStateException` - if called outside the scope of a request.