com.sun.jersey.server.impl.application
Class WebApplicationContext

java.lang.Object
  extended by com.sun.jersey.server.impl.application.WebApplicationContext
All Implemented Interfaces:
ExtendedUriInfo, HttpContext, Traceable, UriMatchResultContext, UriRuleContext, UriInfo

public final class WebApplicationContext
extends Object
implements UriRuleContext, ExtendedUriInfo

Author:
Paul.Sandoz@Sun.Com

Field Summary
static String HTTP_METHOD_MATCH_RESOURCE
           
 
Constructor Summary
WebApplicationContext(WebApplicationImpl app, ContainerRequest request, ContainerResponse response)
           
 
Method Summary
 WebApplicationContext createMatchResourceContext(URI u)
           
 URI getAbsolutePath()
          Get the absolute path of the request.
 UriBuilder getAbsolutePathBuilder()
          Get the absolute path of the request in the form of a UriBuilder.
 URI getBaseUri()
          Get the base URI of the application.
 UriBuilder getBaseUriBuilder()
          Get the base URI of the application in the form of a UriBuilder.
 ContainerRequest getContainerRequest()
          Get the container request.
 ContainerResponse getContainerResponse()
          Get the container response.
 Throwable getMappedThrowable()
          Get the throwable that was mapped to a response.
 AbstractResourceMethod getMatchedMethod()
          Get get matched resource method that was invoked.
 List<Object> getMatchedResources()
          Get a read-only list of the currently matched resource class instances.
 List<MatchResult> getMatchedResults()
          Get a read-only list of MatchResult for matched resources.
 List<UriTemplate> getMatchedTemplates()
          Get a read-only list of UriTemplate for matched resources.
 List<String> getMatchedURIs()
          Get a read-only list of URIs for matched resources.
 List<String> getMatchedURIs(boolean decode)
          Get a read-only list of URIs for matched resources.
 MatchResult getMatchResult()
          Get the match result
 String getPath()
          Get the path of the current request relative to the base URI as a string.
 String getPath(boolean decode)
          Get the path of the current request relative to the base URI as a string.
 MultivaluedMap<String,String> getPathParameters()
          Get the values of any embedded URI template parameters.
 MultivaluedMap<String,String> getPathParameters(boolean decode)
          Get the values of any embedded URI template parameters.
 List<PathSegment> getPathSegments()
          Get the path of the current request relative to the base URI as a list of PathSegment.
 List<PathSegment> getPathSegments(boolean decode)
          Get the path of the current request relative to the base URI as a list of PathSegment.
 List<PathSegment> getPathSegments(String name)
          Get the path segments that contains a template variable.
 List<PathSegment> getPathSegments(String name, boolean decode)
          Get the path segments that contains a template variable.
 Map<String,Object> getProperties()
          Get the mutable properties.
 MultivaluedMap<String,String> getQueryParameters()
          Get the URI query parameters of the current request.
 MultivaluedMap<String,String> getQueryParameters(boolean decode)
          Get the URI query parameters of the current request.
 HttpRequestContext getRequest()
          Get the HTTP request information.
 URI getRequestUri()
          Get the absolute request URI including any query parameters.
 UriBuilder getRequestUriBuilder()
          Get the absolute request URI in the form of a UriBuilder.
 Object getResource(Class resourceClass)
          Get the resource instance from a resource class.
 HttpResponseContext getResponse()
          Get the HTTP response information.
 List<ContainerResponseFilter> getResponseFilters()
           
 UriRules<UriRule> getRules(Class resourceClass)
          Get the rules for a resource class.
 ExtendedUriInfo getUriInfo()
          Get the extended URI information.
 boolean isTracingEnabled()
          Check if tracing is enabled.
 void pushContainerResponseFilters(List<ContainerResponseFilter> filters)
          Push a list of container response filters to apply after the container response has been produced.
 void pushMatch(UriTemplate template, List<String> names)
          Push a match.
 void pushMethod(AbstractResourceMethod arm)
          Push the matching resource method.
 void pushResource(Object resource)
          Push a matching resource.
 void pushRightHandPathLength(int rhpathlen)
          Push the right hand path length to calculate the entry for the list of matching (ancestor) URI paths.
 void setContainerRequest(ContainerRequest request)
          Set the container request.
 void setContainerResponse(ContainerResponse response)
          Set the container response.
 void setMatchResult(MatchResult matchResult)
          Set the match result
 void trace(String message)
          Add a trace message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

HTTP_METHOD_MATCH_RESOURCE

public static final String HTTP_METHOD_MATCH_RESOURCE
See Also:
Constant Field Values
Constructor Detail

WebApplicationContext

public WebApplicationContext(WebApplicationImpl app,
                             ContainerRequest request,
                             ContainerResponse response)
Method Detail

createMatchResourceContext

public WebApplicationContext createMatchResourceContext(URI u)

getResponseFilters

public List<ContainerResponseFilter> getResponseFilters()

getRequest

public HttpRequestContext getRequest()
Description copied from interface: HttpContext
Get the HTTP request information.

Specified by:
getRequest in interface HttpContext
Returns:
the HTTP request information

getResponse

public HttpResponseContext getResponse()
Description copied from interface: HttpContext
Get the HTTP response information.

Specified by:
getResponse in interface HttpContext
Returns:
the HTTP response information

getUriInfo

public ExtendedUriInfo getUriInfo()
Description copied from interface: HttpContext
Get the extended URI information.

Specified by:
getUriInfo in interface HttpContext
Returns:
the extended URI information.

getProperties

public Map<String,Object> getProperties()
Description copied from interface: HttpContext
Get the mutable properties.

Care should be taken not to clear the properties or remove properties that are unknown otherwise unspecified behaviour may result.

Specified by:
getProperties in interface HttpContext
Returns:
the properties.

isTracingEnabled

public boolean isTracingEnabled()
Description copied from interface: Traceable
Check if tracing is enabled.

Specified by:
isTracingEnabled in interface Traceable
Returns:
true if tracing is enabled, otherwise false.

trace

public void trace(String message)
Description copied from interface: Traceable
Add a trace message.

A trace message will be added if Traceable.isTracingEnabled() returns true and tracing contraints are satisfied.

Specified by:
trace in interface Traceable
Parameters:
message - the trace message to add.

getMatchResult

public MatchResult getMatchResult()
Description copied from interface: UriMatchResultContext
Get the match result

Specified by:
getMatchResult in interface UriMatchResultContext
Returns:
the match result.

setMatchResult

public void setMatchResult(MatchResult matchResult)
Description copied from interface: UriMatchResultContext
Set the match result

Specified by:
setMatchResult in interface UriMatchResultContext
Parameters:
matchResult - the match result.

getContainerRequest

public ContainerRequest getContainerRequest()
Description copied from interface: UriRuleContext
Get the container request.

Specified by:
getContainerRequest in interface UriRuleContext
Returns:
the container request.

setContainerRequest

public void setContainerRequest(ContainerRequest request)
Description copied from interface: UriRuleContext
Set the container request.

Specified by:
setContainerRequest in interface UriRuleContext
Parameters:
request - the container request.

getContainerResponse

public ContainerResponse getContainerResponse()
Description copied from interface: UriRuleContext
Get the container response.

Specified by:
getContainerResponse in interface UriRuleContext
Returns:
the container response.

setContainerResponse

public void setContainerResponse(ContainerResponse response)
Description copied from interface: UriRuleContext
Set the container response.

Specified by:
setContainerResponse in interface UriRuleContext
Parameters:
response - the container response.

pushContainerResponseFilters

public void pushContainerResponseFilters(List<ContainerResponseFilter> filters)
Description copied from interface: UriRuleContext
Push a list of container response filters to apply after the container response has been produced.

The list of response filters is processed in reverse order of last to first.

Specified by:
pushContainerResponseFilters in interface UriRuleContext
Parameters:
filters - the list container response filters

getResource

public Object getResource(Class resourceClass)
Description copied from interface: UriRuleContext
Get the resource instance from a resource class.

Specified by:
getResource in interface UriRuleContext
Parameters:
resourceClass - the resource class
Returns:
the resource instance

getRules

public UriRules<UriRule> getRules(Class resourceClass)
Description copied from interface: UriRuleContext
Get the rules for a resource class.

Specified by:
getRules in interface UriRuleContext
Parameters:
resourceClass - the resource class that has rules
Returns:
the rules

pushMatch

public void pushMatch(UriTemplate template,
                      List<String> names)
Description copied from interface: UriRuleContext
Push a match.

Specified by:
pushMatch in interface UriRuleContext
Parameters:
template - the matching URI template.
names - the parameter names associated with the capturing group values.

pushResource

public void pushResource(Object resource)
Description copied from interface: UriRuleContext
Push a matching resource.

Specified by:
pushResource in interface UriRuleContext
Parameters:
resource - the matching resource

pushMethod

public void pushMethod(AbstractResourceMethod arm)
Description copied from interface: UriRuleContext
Push the matching resource method.

Specified by:
pushMethod in interface UriRuleContext
Parameters:
arm - the matching resource method.

pushRightHandPathLength

public void pushRightHandPathLength(int rhpathlen)
Description copied from interface: UriRuleContext
Push the right hand path length to calculate the entry for the list of matching (ancestor) URI paths.

Specified by:
pushRightHandPathLength in interface UriRuleContext
Parameters:
rhpathlen - the right hand length

getBaseUri

public URI getBaseUri()
Description copied from interface: UriInfo
Get the base URI of the application. URIs of root resource classes are all relative to this base URI.

Specified by:
getBaseUri in interface UriInfo
Returns:
the base URI of the application

getBaseUriBuilder

public UriBuilder getBaseUriBuilder()
Description copied from interface: UriInfo
Get the base URI of the application in the form of a UriBuilder.

Specified by:
getBaseUriBuilder in interface UriInfo
Returns:
a UriBuilder initialized with the base URI of the application.

getAbsolutePath

public URI getAbsolutePath()
Description copied from interface: UriInfo
Get the absolute path of the request. This includes everything preceding the path (host, port etc) but excludes query parameters. This is a shortcut for uriInfo.getBase().resolve(uriInfo.getPath()).

Specified by:
getAbsolutePath in interface UriInfo
Returns:
the absolute path of the request

getAbsolutePathBuilder

public UriBuilder getAbsolutePathBuilder()
Description copied from interface: UriInfo
Get the absolute path of the request in the form of a UriBuilder. This includes everything preceding the path (host, port etc) but excludes query parameters.

Specified by:
getAbsolutePathBuilder in interface UriInfo
Returns:
a UriBuilder initialized with the absolute path of the request

getRequestUri

public URI getRequestUri()
Description copied from interface: UriInfo
Get the absolute request URI including any query parameters.

Specified by:
getRequestUri in interface UriInfo
Returns:
the absolute request URI

getRequestUriBuilder

public UriBuilder getRequestUriBuilder()
Description copied from interface: UriInfo
Get the absolute request URI in the form of a UriBuilder.

Specified by:
getRequestUriBuilder in interface UriInfo
Returns:
a UriBuilder initialized with the absolute request URI

getPath

public String getPath()
Description copied from interface: UriInfo
Get the path of the current request relative to the base URI as a string. All sequences of escaped octets are decoded, equivalent to getPath(true).

Specified by:
getPath in interface UriInfo
Returns:
the relative URI path

getPath

public String getPath(boolean decode)
Description copied from interface: UriInfo
Get the path of the current request relative to the base URI as a string.

Specified by:
getPath in interface UriInfo
Parameters:
decode - controls whether sequences of escaped octets are decoded (true) or not (false).
Returns:
the relative URI path

getPathSegments

public List<PathSegment> getPathSegments()
Description copied from interface: UriInfo
Get the path of the current request relative to the base URI as a list of PathSegment. This method is useful when the path needs to be parsed, particularly when matrix parameters may be present in the path. All sequences of escaped octets in path segments and matrix parameter values are decoded, equivalent to getPathSegments(true).

Specified by:
getPathSegments in interface UriInfo
Returns:
an unmodifiable list of PathSegment. The matrix parameter map of each path segment is also unmodifiable.
See Also:
PathSegment, Matrix URIs

getPathSegments

public List<PathSegment> getPathSegments(boolean decode)
Description copied from interface: UriInfo
Get the path of the current request relative to the base URI as a list of PathSegment. This method is useful when the path needs to be parsed, particularly when matrix parameters may be present in the path.

Specified by:
getPathSegments in interface UriInfo
Parameters:
decode - controls whether sequences of escaped octets in path segments and matrix parameter values are decoded (true) or not (false).
Returns:
an unmodifiable list of PathSegment. The matrix parameter map of each path segment is also unmodifiable.
See Also:
PathSegment, Matrix URIs

getQueryParameters

public MultivaluedMap<String,String> getQueryParameters()
Description copied from interface: UriInfo
Get the URI query parameters of the current request. The map keys are the names of the query parameters with any escaped characters decoded. All sequences of escaped octets in parameter values are decoded, equivalent to getQueryParameters(true).

Specified by:
getQueryParameters in interface UriInfo
Returns:
an unmodifiable map of query parameter names and values

getQueryParameters

public MultivaluedMap<String,String> getQueryParameters(boolean decode)
Description copied from interface: UriInfo
Get the URI query parameters of the current request. The map keys are the names of the query parameters with any escaped characters decoded.

Specified by:
getQueryParameters in interface UriInfo
Parameters:
decode - controls whether sequences of escaped octets in parameter values are decoded (true) or not (false).
Returns:
an unmodifiable map of query parameter names and values

getPathParameters

public MultivaluedMap<String,String> getPathParameters()
Description copied from interface: UriInfo
Get the values of any embedded URI template parameters. All sequences of escaped octets are decoded, equivalent to getPathParameters(true).

Specified by:
getPathParameters in interface UriInfo
Returns:
an unmodifiable map of parameter names and values
See Also:
Path, PathParam

getPathParameters

public MultivaluedMap<String,String> getPathParameters(boolean decode)
Description copied from interface: UriInfo
Get the values of any embedded URI template parameters.

Specified by:
getPathParameters in interface UriInfo
Parameters:
decode - controls whether sequences of escaped octets are decoded (true) or not (false).
Returns:
an unmodifiable map of parameter names and values
See Also:
Path, PathParam

getMatchedURIs

public List<String> getMatchedURIs()
Description copied from interface: UriInfo
Get a read-only list of URIs for matched resources. Each entry is a relative URI that matched a resource class, a sub-resource method or a sub-resource locator. All sequences of escaped octets are decoded, equivalent to getMatchedURIs(true). Entries do not include query parameters but do include matrix parameters if present in the request URI. Entries are ordered in reverse request URI matching order, with the current resource URI first. E.g. given the following resource classes:
@Path("foo")
public class FooResource {
  @GET
  public String getFoo() {...}
 
  @Path("bar")
  public BarResource getBarResource() {...}
}
 
public class BarResource {
  @GET
  public String getBar() {...}
}
 

The values returned by this method based on request uri and where the method is called from are:

Request Called from Value(s)
GET /foo FooResource.getFoo foo
GET /foo/bar FooResource.getBarResource foo/bar, foo
GET /foo/bar BarResource.getBar foo/bar, foo

Specified by:
getMatchedURIs in interface UriInfo
Returns:
a read-only list of URI paths for matched resources.

getMatchedURIs

public List<String> getMatchedURIs(boolean decode)
Description copied from interface: UriInfo
Get a read-only list of URIs for matched resources. Each entry is a relative URI that matched a resource class, a sub-resource method or a sub-resource locator. Entries do not include query parameters but do include matrix parameters if present in the request URI. Entries are ordered in reverse request URI matching order, with the current resource URI first. See UriInfo.getMatchedURIs() for an example.

Specified by:
getMatchedURIs in interface UriInfo
Parameters:
decode - controls whether sequences of escaped octets are decoded (true) or not (false).
Returns:
a read-only list of URI paths for matched resources.

getMatchedResources

public List<Object> getMatchedResources()
Description copied from interface: UriInfo
Get a read-only list of the currently matched resource class instances. Each entry is a resource class instance that matched the request URI either directly or via a sub-resource method or a sub-resource locator. Entries are ordered according to reverse request URI matching order, with the current resource first. E.g. given the following resource classes:
@Path("foo")
public class FooResource {
  @GET
  public String getFoo() {...}
 
  @Path("bar")
  public BarResource getBarResource() {...}
}
 
public class BarResource {
  @GET
  public String getBar() {...}
}
 

The values returned by this method based on request uri and where the method is called from are:

Request Called from Value(s)
GET /foo FooResource.getFoo FooResource
GET /foo/bar FooResource.getBarResource FooResource
GET /foo/bar BarResource.getBar BarResource, FooResource

Specified by:
getMatchedResources in interface UriInfo
Returns:
a read-only list of matched resource class instances.

getMatchedMethod

public AbstractResourceMethod getMatchedMethod()
Description copied from interface: ExtendedUriInfo
Get get matched resource method that was invoked.

Specified by:
getMatchedMethod in interface ExtendedUriInfo
Returns:
the matched resource method, otherwise null if no resource method was invoked.

getMappedThrowable

public Throwable getMappedThrowable()
Description copied from interface: ExtendedUriInfo
Get the throwable that was mapped to a response.

A response filter or a message body writer may utilize this method to determine if a resource method was invoked but did not return a response because an exception was thrown from the resource method, or the resource method returned but a response filter threw an exception.

Specified by:
getMappedThrowable in interface ExtendedUriInfo
Returns:
the throwable that was mapped to a response, otherwise null if no throwable was mapped to a response.
See Also:
ContainerResponse.getMappedThrowable()

getMatchedResults

public List<MatchResult> getMatchedResults()
Description copied from interface: ExtendedUriInfo
Get a read-only list of MatchResult for matched resources. Entries are ordered in reverse request URI matching order, with the root resource match result last.

Specified by:
getMatchedResults in interface ExtendedUriInfo
Returns:
a read-only list of match results for matched resources.

getMatchedTemplates

public List<UriTemplate> getMatchedTemplates()
Description copied from interface: ExtendedUriInfo
Get a read-only list of UriTemplate for matched resources. Each entry is a URI template that is the value of the Path that is a partial path that matched a resource class, a sub-resource method or a sub-resource locator. Entries are ordered in reverse request URI matching order, with the root resource URI template last.

Specified by:
getMatchedTemplates in interface ExtendedUriInfo
Returns:
a read-only list of URI templates for matched resources.

getPathSegments

public List<PathSegment> getPathSegments(String name)
Description copied from interface: ExtendedUriInfo
Get the path segments that contains a template variable. All sequences of escaped octets are decoded, equivalent to getPathSegments(true).

Specified by:
getPathSegments in interface ExtendedUriInfo
Parameters:
name - the template variable name
Returns:
the path segments, the list will be empty the matching path does not contain the template

getPathSegments

public List<PathSegment> getPathSegments(String name,
                                         boolean decode)
Description copied from interface: ExtendedUriInfo
Get the path segments that contains a template variable.

Specified by:
getPathSegments in interface ExtendedUriInfo
Parameters:
name - the template variable name
decode - controls whether sequences of escaped octets are decoded (true) or not (false).
Returns:
the path segments, the list will be empty the matching path does not contain the template


Copyright © 2013 Oracle Corporation. All Rights Reserved.