javax.ws.rs.container
Interface ContainerRequestContext


public interface ContainerRequestContext

Container request filter context. A mutable class that provides request-specific information for the filter, such as request URI, message headers, message entity or request-scoped properties. The exposed setters allow modification of the exposed request-specific information.

Since:
2.0
Author:
Marek Potociar

Method Summary
 void abortWith(Response response)
          Abort the filter chain with a response.
 java.util.List<java.util.Locale> getAcceptableLanguages()
          Get a list of languages that are acceptable for the response.
 java.util.List<MediaType> getAcceptableMediaTypes()
          Get a list of media types that are acceptable for the response.
 java.util.Map<java.lang.String,Cookie> getCookies()
          Get any cookies that accompanied the request.
 java.util.Date getDate()
          Get message date.
 java.io.InputStream getEntityStream()
          Get the entity input stream.
 MultivaluedMap<java.lang.String,java.lang.String> getHeaders()
          Get the mutable request headers multivalued map.
 java.lang.String getHeaderString(java.lang.String name)
          Get a message header as a single string value.
 java.util.Locale getLanguage()
          Get the language of the entity.
 int getLength()
          Get Content-Length value.
 MediaType getMediaType()
          Get the media type of the entity.
 java.lang.String getMethod()
          Get the request method.
 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.Enumeration<java.lang.String> getPropertyNames()
          Returns an enumeration containing the property names available within the context of the current request/response exchange context.
 Request getRequest()
          Get the injectable request information.
 SecurityContext getSecurityContext()
          Get the injectable security context information for the current request.
 UriInfo getUriInfo()
          Get request URI information.
 boolean hasEntity()
          Check if there is a non-empty entity input stream available in the request message.
 void removeProperty(java.lang.String name)
          Removes a property with the given name from the current request/response exchange context.
 void setEntityStream(java.io.InputStream input)
          Set a new entity input stream.
 void setMethod(java.lang.String method)
          Set the request method.
 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 setRequestUri(java.net.URI requestUri)
          Set a new request URI using the current base URI of the application to resolve the application-specific request URI part.
 void setRequestUri(java.net.URI baseUri, java.net.URI requestUri)
          Set a new request URI using a new base URI to resolve the application-specific request URI part.
 void setSecurityContext(SecurityContext context)
          Set a new injectable security context information for the current request.
 

Method Detail

getProperty

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.

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 getPropertyNames(). Custom property names should follow the same convention as package names.

In a Servlet container, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Parameters:
name - a String specifying the name of the property.
Returns:
an Object containing the value of the property, or null if no property exists matching the given name.
See Also:
getPropertyNames()

getPropertyNames

java.util.Enumeration<java.lang.String> getPropertyNames()
Returns an enumeration containing the property names available within the context of the current request/response exchange context.

Use the getProperty(java.lang.String) method with a property name to get the value of a property.

In a Servlet container, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Returns:
an enumeration of property names.
See Also:
getProperty(java.lang.String)

setProperty

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. 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 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 removeProperty(String) method.

In a Servlet container, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Parameters:
name - a String specifying the name of the property.
object - an Object representing the property to be bound.

removeProperty

void removeProperty(java.lang.String name)
Removes a property with the given name from the current request/response exchange context. After removal, subsequent calls to getProperty(java.lang.String) to retrieve the property value will return null.

In a Servlet container, the properties are backed by the ServletRequest and contain all the attributes available in the ServletRequest.

Parameters:
name - a String specifying the name of the property to be removed.

getUriInfo

UriInfo getUriInfo()
Get request URI information. The returned object contains "live" view of the request URI information in a sense that any changes made to the request URI using one of the setRequestUri(...) methods will be reflected in the previously returned UriInfo instance.

Returns:
request URI information.

setRequestUri

void setRequestUri(java.net.URI requestUri)
                   throws java.lang.IllegalStateException
Set a new request URI using the current base URI of the application to resolve the application-specific request URI part.

Note that the method is usable only in pre-matching filters, prior to the resource matching occurs. Trying to invoke the method in a filter bound to a resource method results in an IllegalStateException being thrown.

Parameters:
requestUri - new URI of the request.
Throws:
java.lang.IllegalStateException - in case the method is not invoked from a pre-matching request filter.
See Also:
setRequestUri(java.net.URI, java.net.URI)

setRequestUri

void setRequestUri(java.net.URI baseUri,
                   java.net.URI requestUri)
                   throws java.lang.IllegalStateException
Set a new request URI using a new base URI to resolve the application-specific request URI part.

Note that the method is usable only in pre-matching filters, prior to the resource matching occurs. Trying to invoke the method in a filter bound to a resource method results in an IllegalStateException being thrown.

Parameters:
baseUri - base URI that will be used to resolve the application-specific part of the request URI.
requestUri - new URI of the request.
Throws:
java.lang.IllegalStateException - in case the method is not invoked from a pre-matching request filter.
See Also:
setRequestUri(java.net.URI)

getRequest

Request getRequest()
Get the injectable request information.

Returns:
injectable request information.

getMethod

java.lang.String getMethod()
Get the request method.

Returns:
the request method.
See Also:
HttpMethod

setMethod

void setMethod(java.lang.String method)
               throws java.lang.IllegalStateException
Set the request method.

Note that the method is usable only in pre-matching filters, prior to the resource matching occurs. Trying to invoke the method in a filter bound to a resource method results in an IllegalStateException being thrown.

Parameters:
method - new request method.
Throws:
java.lang.IllegalStateException - in case the method is not invoked from a pre-matching request filter.
See Also:
HttpMethod

getHeaders

MultivaluedMap<java.lang.String,java.lang.String> getHeaders()
Get the mutable request headers multivalued map.

Returns:
mutable multivalued map of request headers.
See Also:
getHeaderString(String)

getHeaderString

java.lang.String getHeaderString(java.lang.String name)
Get a message header as a single string value.

Parameters:
name - the message header.
Returns:
the message header value. If the message header is not present then null is returned. If the message header is present but has no value then the empty string is returned. If the message header is present more than once then the values of joined together and separated by a ',' character.
See Also:
getHeaders()

getDate

java.util.Date getDate()
Get message date.

Returns:
the message date, otherwise null if not present.

getLanguage

java.util.Locale getLanguage()
Get the language of the entity.

Returns:
the language of the entity or null if not specified

getLength

int getLength()
Get Content-Length value.

Returns:
Content-Length as integer if present and valid number. In other cases returns -1.

getMediaType

MediaType getMediaType()
Get the media type of the entity.

Returns:
the media type or null if not specified (e.g. there's no request entity).

getAcceptableMediaTypes

java.util.List<MediaType> getAcceptableMediaTypes()
Get a list of media types that are acceptable for the response.

Returns:
a read-only list of requested response media types sorted according to their q-value, with highest preference first.

getAcceptableLanguages

java.util.List<java.util.Locale> getAcceptableLanguages()
Get a list of languages that are acceptable for the response.

Returns:
a read-only list of acceptable languages sorted according to their q-value, with highest preference first.

getCookies

java.util.Map<java.lang.String,Cookie> getCookies()
Get any cookies that accompanied the request.

Returns:
a read-only map of cookie name (String) to Cookie.

hasEntity

boolean hasEntity()
Check if there is a non-empty entity input stream available in the request message. The method returns true if the entity is present, returns false otherwise.

Returns:
true if there is an entity present in the message, false otherwise.

getEntityStream

java.io.InputStream getEntityStream()
Get the entity input stream.

Returns:
entity input stream.

setEntityStream

void setEntityStream(java.io.InputStream input)
                     throws java.lang.IllegalStateException
Set a new entity input stream.

Parameters:
input - new entity input stream.
Throws:
java.lang.IllegalStateException - in case the method is invoked from a response filter.

getSecurityContext

SecurityContext getSecurityContext()
Get the injectable security context information for the current request. The SecurityContext.getUserPrincipal() must return null if the current request has not been authenticated.

Returns:
injectable request security context information.

setSecurityContext

void setSecurityContext(SecurityContext context)
                        throws java.lang.IllegalStateException
Set a new injectable security context information for the current request. The SecurityContext.getUserPrincipal() must return null if the current request has not been authenticated.

Parameters:
context - new injectable request security context information.
Throws:
java.lang.IllegalStateException - in case the method is invoked from a response filter.

abortWith

void abortWith(Response response)
               throws java.lang.IllegalStateException
Abort the filter chain with a response. This method breaks the filter chain processing and returns the provided response back to the client. The provided response goes through the chain of applicable response filters.

Parameters:
response - response to be sent back to the client.
Throws:
java.lang.IllegalStateException - in case the method is invoked from a response filter.


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