org.glassfish.jersey.server
Class ContainerRequest

java.lang.Object
  extended by org.glassfish.jersey.message.internal.InboundMessageContext
      extended by org.glassfish.jersey.server.ContainerRequest
All Implemented Interfaces:
ContainerRequestContext, HttpHeaders, Request

public class ContainerRequest
extends InboundMessageContext
implements ContainerRequestContext, Request, HttpHeaders

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 (marek.potociar at oracle.com)

Field Summary
 
Fields inherited from interface javax.ws.rs.core.HttpHeaders
ACCEPT, ACCEPT_CHARSET, ACCEPT_ENCODING, ACCEPT_LANGUAGE, ALLOW, AUTHORIZATION, CACHE_CONTROL, CONTENT_ENCODING, 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_MODIFIED, LINK, LOCATION, RETRY_AFTER, SET_COOKIE, USER_AGENT, VARY, WWW_AUTHENTICATE
 
Constructor Summary
ContainerRequest(URI baseUri, URI requestUri, String httpMethod, SecurityContext securityContext, PropertiesDelegate propertiesDelegate)
          Create new Jersey container request context.
 
Method Summary
 void abortWith(Response response)
           
 Response.ResponseBuilder evaluatePreconditions()
           
 Response.ResponseBuilder evaluatePreconditions(Date lastModified)
           
 Response.ResponseBuilder evaluatePreconditions(Date lastModified, EntityTag eTag)
           
 Response.ResponseBuilder evaluatePreconditions(EntityTag eTag)
           
 Response getAbortResponse()
          Get the request filter chain aborting response if set, or null otherwise.
 List<Locale> getAcceptableLanguages()
           
 List<MediaType> getAcceptableMediaTypes()
           
 URI getBaseUri()
          Get base request URI.
 Map<String,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.
 PropertiesDelegate getPropertiesDelegate()
          Get the underlying properties delegate.
 Object getProperty(String name)
           
 Enumeration<String> getPropertyNames()
           
 Request getRequest()
           
 List<String> getRequestHeader(String name)
          Get the values of a HTTP request header.
 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.
 SecurityContext getSecurityContext()
           
 UriInfo 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.
<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)
           
 Variant selectVariant(List<Variant> variants)
           
 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(SecurityContext context)
           
 void setUriInfo(UriInfo uriInfo)
          Set the request scoped UriInfo instance.
 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, 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, setEntityStream, setWorkers
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.ws.rs.container.ContainerRequestContext
getDate, getEntityStream, getHeaders, getHeaderString, getLanguage, getLength, getMediaType, hasEntity, setEntityStream
 
Methods inherited from interface javax.ws.rs.core.HttpHeaders
getDate, getHeaderString, getLanguage, getLength, getMediaType
 

Constructor Detail

ContainerRequest

public ContainerRequest(URI baseUri,
                        URI requestUri,
                        String httpMethod,
                        SecurityContext securityContext,
                        PropertiesDelegate propertiesDelegate)
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.
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 ContainerRequestContext

getPropertyNames

public Enumeration<String> getPropertyNames()
Specified by:
getPropertyNames in interface ContainerRequestContext

setProperty

public void setProperty(String name,
                        Object object)
Specified by:
setProperty in interface ContainerRequestContext

removeProperty

public void removeProperty(String name)
Specified by:
removeProperty in interface ContainerRequestContext

getPropertiesDelegate

public PropertiesDelegate getPropertiesDelegate()
Get the underlying properties delegate.

Returns:
underlying properties delegate.

getUriInfo

public UriInfo getUriInfo()
Specified by:
getUriInfo in interface ContainerRequestContext

setUriInfo

public void setUriInfo(UriInfo uriInfo)
Set the request scoped UriInfo instance.

Parameters:
uriInfo - request scoped UriInfo instance.

getBaseUri

public URI getBaseUri()
Get base request URI.

Returns:
base request URI.

getRequestUri

public URI getRequestUri()
Get request URI.

Returns:
request URI.

setRequestUri

public void setRequestUri(URI requestUri)
                   throws IllegalStateException
Specified by:
setRequestUri in interface ContainerRequestContext
Throws:
IllegalStateException

setRequestUri

public void setRequestUri(URI baseUri,
                          URI requestUri)
                   throws IllegalStateException
Specified by:
setRequestUri in interface 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 ContainerRequestContext
Specified by:
getMethod in interface Request

setMethod

public void setMethod(String method)
               throws IllegalStateException
Specified by:
setMethod in interface 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 SecurityContext getSecurityContext()
Specified by:
getSecurityContext in interface ContainerRequestContext

setSecurityContext

public void setSecurityContext(SecurityContext context)
Specified by:
setSecurityContext in interface ContainerRequestContext

getRequest

public Request getRequest()
Specified by:
getRequest in interface ContainerRequestContext

abortWith

public void abortWith(Response response)
Specified by:
abortWith in interface ContainerRequestContext

getAbortResponse

public 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,Cookie> getCookies()
Specified by:
getCookies in interface ContainerRequestContext
Specified by:
getCookies in interface HttpHeaders

getAcceptableMediaTypes

public List<MediaType> getAcceptableMediaTypes()
Specified by:
getAcceptableMediaTypes in interface ContainerRequestContext
Specified by:
getAcceptableMediaTypes in interface HttpHeaders

getAcceptableLanguages

public List<Locale> getAcceptableLanguages()
Specified by:
getAcceptableLanguages in interface ContainerRequestContext
Specified by:
getAcceptableLanguages in interface HttpHeaders

selectVariant

public Variant selectVariant(List<Variant> variants)
                      throws IllegalArgumentException
Specified by:
selectVariant in interface 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 Response.ResponseBuilder evaluatePreconditions(EntityTag eTag)
Specified by:
evaluatePreconditions in interface Request

evaluatePreconditions

public Response.ResponseBuilder evaluatePreconditions(Date lastModified)
Specified by:
evaluatePreconditions in interface Request

evaluatePreconditions

public Response.ResponseBuilder evaluatePreconditions(Date lastModified,
                                                      EntityTag eTag)
Specified by:
evaluatePreconditions in interface Request

evaluatePreconditions

public Response.ResponseBuilder evaluatePreconditions()
Specified by:
evaluatePreconditions in interface 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 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 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 HttpHeaders
Returns:
a read-only map of header names and values.
Throws:
IllegalStateException - if called outside the scope of a request.


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.