Package org.glassfish.jersey.server
Class ContainerRequest
- java.lang.Object
-
- org.glassfish.jersey.message.internal.MessageHeaderMethods
-
- org.glassfish.jersey.message.internal.InboundMessageContext
-
- org.glassfish.jersey.server.ContainerRequest
-
- All Implemented Interfaces:
ContainerRequestContext,HttpHeaders,Request,HttpHeaders,PropertiesDelegate,PropertiesResolver
public class ContainerRequest extends InboundMessageContext implements ContainerRequestContext, Request, HttpHeaders, PropertiesDelegate, PropertiesResolver
Jersey container request context. An instance of the request context is passed by the container to theApplicationHandlerfor each incoming client request.- Author:
- Marek Potociar
-
-
Field Summary
-
Fields inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
runtimeDelegateDecorator
-
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, LOCATION, RETRY_AFTER, SET_COOKIE, USER_AGENT, VARY, WWW_AUTHENTICATE
-
Fields inherited from interface org.glassfish.jersey.http.HttpHeaders
ACCEPT_PATCH, ACCEPT_RANGES, AGE, CONNECTION, CONTENT_RANGE, EXPECT, FORWARDED, FROM, IF_RANGE, LINK, MAX_FORWARDS, MIME_VERSION, ORIGIN, PROXY_AUTHENTICATE, PROXY_AUTHENTICATION_INFO, PROXY_AUTHORIZATION, PROXY_CONNECTION, RANGE, REFERER, SERVER, TE, TRAILER, TRANSFER_ENCODING, UPGRADE, VIA
-
-
Constructor Summary
Constructors Constructor Description ContainerRequest(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidabortWith(Response response)Response.ResponseBuilderevaluatePreconditions()Response.ResponseBuilderevaluatePreconditions(EntityTag eTag)Response.ResponseBuilderevaluatePreconditions(Date lastModified)Response.ResponseBuilderevaluatePreconditions(Date lastModified, EntityTag eTag)ResponsegetAbortResponse()Get the request filter chain aborting response if set, ornullotherwise.URIgetAbsolutePath()Get the absolute path of the request.List<Locale>getAcceptableLanguages()List<MediaType>getAcceptableMediaTypes()URIgetBaseUri()Get base request URI.Map<String,Cookie>getCookies()StringgetMethod()StringgetPath(boolean decode)Get the path of the current request relative to the application root (base) URI as a string.PropertiesDelegategetPropertiesDelegate()Get the underlying properties delegate.ObjectgetProperty(String name)Collection<String>getPropertyNames()protected Iterable<ReaderInterceptor>getReaderInterceptors()Get all reader interceptors applicable to this request.RequestgetRequest()List<String>getRequestHeader(String name)Get the values of an HTTP request header if the header exists on the current request.MultivaluedMap<String,String>getRequestHeaders()Get the values of HTTP request headers.RequestScopedInitializergetRequestScopedInitializer()Get a custom container extensions initializer for the current request.URIgetRequestUri()Get request URI.ContainerResponseWritergetResponseWriter()Get the container response writer for the current request.SecurityContextgetSecurityContext()ExtendedUriInfogetUriInfo()StringgetVaryValue()Get the value of HTTP Vary response header to be set in the response, ornullif no value is to be set.booleanhasProperty(String name)voidinResponseProcessing()Notify this request that the response created from this request is already being processed.<T> TreadEntity(Class<T> rawType)Read entity from a context entity input stream.<T> TreadEntity(Class<T> rawType, Annotation[] annotations)Read entity from a context entity input stream.<T> TreadEntity(Class<T> rawType, Type type)Read entity from a context entity input stream.<T> TreadEntity(Class<T> rawType, Type type, Annotation[] annotations)Read entity from a context entity input stream.voidremoveProperty(String name)<T> TresolveProperty(String name, Class<T> type)<T> TresolveProperty(String name, T defaultValue)VariantselectVariant(List<Variant> variants)voidsetEntityStream(InputStream input)voidsetMethod(String method)voidsetMethodWithoutException(String method)LikesetMethod(String)but does not throwIllegalStateExceptionif the method is invoked in other than pre-matching phase.voidsetProperty(String name, Object object)voidsetRequestScopedInitializer(RequestScopedInitializer requestScopedInitializer)Set a custom container extensions initializer for the current request.voidsetRequestUri(URI requestUri)voidsetRequestUri(URI baseUri, URI requestUri)voidsetSecurityContext(SecurityContext context)voidsetWriter(ContainerResponseWriter responseWriter)Set the container response writer for the current request.-
Methods inherited from class org.glassfish.jersey.message.internal.InboundMessageContext
bufferEntity, close, getConfiguration, getEntityStream, getHeaders, getHeaderString, getHeaderValueExceptionContext, getIfMatch, getIfNoneMatch, getLinks, getMediaType, getQualifiedAcceptableLanguages, getQualifiedAcceptableMediaTypes, getQualifiedAcceptCharset, getQualifiedAcceptEncoding, getWorkers, hasEntity, header, headers, headers, headers, headers, readEntity, readEntity, readEntity, readEntity, remove, setWorkers
-
Methods inherited from class org.glassfish.jersey.message.internal.MessageHeaderMethods
containsHeaderString, containsHeaderString, exception, getAllowedMethods, getDate, getEntityTag, getLanguage, getLastModified, getLength, getLengthLong, getLink, getLinkBuilder, getLocation, getRequestCookies, getResponseCookies, hasLink, singleHeader, singleHeader
-
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, 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 returnnullif the current request has not been authenticated by the container.propertiesDelegate- customproperties delegateto 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 returnnullif the current request has not been authenticated by the container.propertiesDelegate- customproperties delegateto 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
nullif 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 benull.
-
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.
-
resolveProperty
public <T> T resolveProperty(String name, Class<T> type)
- Specified by:
resolvePropertyin interfacePropertiesResolver
-
resolveProperty
public <T> T resolveProperty(String name, T defaultValue)
- Specified by:
resolvePropertyin interfacePropertiesResolver
-
hasProperty
public boolean hasProperty(String name)
- Specified by:
hasPropertyin interfaceContainerRequestContext- Specified by:
hasPropertyin interfacePropertiesDelegate
-
getProperty
public Object getProperty(String name)
- Specified by:
getPropertyin interfaceContainerRequestContext- Specified by:
getPropertyin interfacePropertiesDelegate
-
getPropertyNames
public Collection<String> getPropertyNames()
- Specified by:
getPropertyNamesin interfaceContainerRequestContext- Specified by:
getPropertyNamesin interfacePropertiesDelegate
-
setProperty
public void setProperty(String name, Object object)
- Specified by:
setPropertyin interfaceContainerRequestContext- Specified by:
setPropertyin interfacePropertiesDelegate
-
removeProperty
public void removeProperty(String name)
- Specified by:
removePropertyin interfaceContainerRequestContext- Specified by:
removePropertyin interfacePropertiesDelegate
-
getPropertiesDelegate
public PropertiesDelegate getPropertiesDelegate()
Get the underlying properties delegate.- Returns:
- underlying properties delegate.
-
getUriInfo
public ExtendedUriInfo getUriInfo()
- Specified by:
getUriInfoin interfaceContainerRequestContext
-
getReaderInterceptors
protected Iterable<ReaderInterceptor> getReaderInterceptors()
Get all reader interceptors applicable to this request. This is populated once the right resource method is matched.- Specified by:
getReaderInterceptorsin classInboundMessageContext- 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:
setRequestUriin interfaceContainerRequestContext- Throws:
IllegalStateException
-
setRequestUri
public void setRequestUri(URI baseUri, URI requestUri) throws IllegalStateException
- Specified by:
setRequestUriin interfaceContainerRequestContext- 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:
getMethodin interfaceContainerRequestContext- Specified by:
getMethodin interfaceRequest
-
setMethod
public void setMethod(String method) throws IllegalStateException
- Specified by:
setMethodin interfaceContainerRequestContext- Throws:
IllegalStateException
-
setMethodWithoutException
public void setMethodWithoutException(String method)
LikesetMethod(String)but does not throwIllegalStateExceptionif the method is invoked in other than pre-matching phase.- Parameters:
method- HTTP method.
-
getSecurityContext
public SecurityContext getSecurityContext()
- Specified by:
getSecurityContextin interfaceContainerRequestContext
-
setSecurityContext
public void setSecurityContext(SecurityContext context)
- Specified by:
setSecurityContextin interfaceContainerRequestContext
-
setEntityStream
public void setEntityStream(InputStream input)
- Specified by:
setEntityStreamin interfaceContainerRequestContext- Overrides:
setEntityStreamin classInboundMessageContext
-
getRequest
public Request getRequest()
- Specified by:
getRequestin interfaceContainerRequestContext
-
abortWith
public void abortWith(Response response)
- Specified by:
abortWithin 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
public Response getAbortResponse()
Get the request filter chain aborting response if set, ornullotherwise.- Returns:
- request filter chain aborting response if set, or
nullotherwise.
-
getCookies
public Map<String,Cookie> getCookies()
- Specified by:
getCookiesin interfaceContainerRequestContext- Specified by:
getCookiesin interfaceHttpHeaders
-
getAcceptableMediaTypes
public List<MediaType> getAcceptableMediaTypes()
- Specified by:
getAcceptableMediaTypesin interfaceContainerRequestContext- Specified by:
getAcceptableMediaTypesin interfaceHttpHeaders
-
getAcceptableLanguages
public List<Locale> getAcceptableLanguages()
- Specified by:
getAcceptableLanguagesin interfaceContainerRequestContext- Specified by:
getAcceptableLanguagesin interfaceHttpHeaders
-
selectVariant
public Variant selectVariant(List<Variant> variants) throws IllegalArgumentException
- Specified by:
selectVariantin interfaceRequest- Throws:
IllegalArgumentException
-
getVaryValue
public String getVaryValue()
Get the value of HTTP Vary response header to be set in the response, ornullif no value is to be set.- Returns:
- value of HTTP Vary response header to be set in the response if available,
nullotherwise.
-
evaluatePreconditions
public Response.ResponseBuilder evaluatePreconditions(EntityTag eTag)
- Specified by:
evaluatePreconditionsin interfaceRequest
-
evaluatePreconditions
public Response.ResponseBuilder evaluatePreconditions(Date lastModified)
- Specified by:
evaluatePreconditionsin interfaceRequest
-
evaluatePreconditions
public Response.ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag)
- Specified by:
evaluatePreconditionsin interfaceRequest
-
evaluatePreconditions
public Response.ResponseBuilder evaluatePreconditions()
- Specified by:
evaluatePreconditionsin interfaceRequest
-
getRequestHeader
public List<String> getRequestHeader(String name)
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 ornullif it does not. This is a shortcut forgetRequestHeaders().get(name).- Specified by:
getRequestHeaderin 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
public 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 returnsnull.- Specified by:
getRequestHeadersin interfaceHttpHeaders- Returns:
- a read-only map of header names and values.
- Throws:
IllegalStateException- if called outside the scope of a request.
-
-