com.sun.jersey.api.core
Class ResourceConfig

java.lang.Object
  extended by javax.ws.rs.core.Application
      extended by com.sun.jersey.api.core.ResourceConfig
All Implemented Interfaces:
FeaturesAndProperties
Direct Known Subclasses:
DefaultResourceConfig

public abstract class ResourceConfig
extends Application
implements FeaturesAndProperties

The resource configuration for configuring a web application.


Field Summary
static java.lang.String COMMON_DELIMITERS
          Common delimiters used by various properties.
static java.lang.String FEATURE_CANONICALIZE_URI_PATH
          If true the request URI path component will be canonicalized by removing contiguous slashes (i.e.
static java.lang.String FEATURE_DISABLE_WADL
          If true then disable WADL generation.
static java.lang.String FEATURE_IMPLICIT_VIEWABLES
          If true then the matching algorithm will attempt to match and accept any static content or templates associated with a resource that were not explicitly declared by that resource.
static java.lang.String FEATURE_MATCH_MATRIX_PARAMS
          If true then matrix parameters (if present) in the request URI path component will not be ignored when matching the path to URI templates declared by resource classes.
static java.lang.String FEATURE_NORMALIZE_URI
          If true and FEATURE_CANONICALIZE_URI_PATH is true then the request URI will be normalized as specified by URI.normalize().
static java.lang.String FEATURE_REDIRECT
          If true, and #CANONICALIZE_URI_PATH is true, and the canonicalization/normalization operations on the request URI result in a new URI that is not equal to the request URI, then the client is (temporarily) redirected to the new URI.
static java.lang.String FEATURE_TRACE
          If true then enable tracing.
static java.lang.String FEATURE_TRACE_PER_REQUEST
          If true then enable tracing on a per-request basis.
static java.lang.String PROPERTY_CONTAINER_NOTIFIER
          If set the instance of ContainerNotifier to register ContainerListener instances.
static java.lang.String PROPERTY_CONTAINER_REQUEST_FILTERS
          If set the list of ContainerRequestFilter that are applied to filter the request.
static java.lang.String PROPERTY_CONTAINER_RESPONSE_FILTERS
          If set the list of ContainerResponseFilter that are applied to filter the response.
static java.lang.String PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS
          If set the default resource component provider factory for the life-cycle of resource classes.
static java.lang.String PROPERTY_LANGUAGE_MAPPINGS
          If set the map of file extension to langauge mappings that will be added to the map that is returned from getLanguageMappings().
static java.lang.String PROPERTY_MEDIA_TYPE_MAPPINGS
          If set the map of file extension to media type mappings that will be added to the map that is returned from getMediaTypeMappings().
static java.lang.String PROPERTY_RESOURCE_FILTER_FACTORIES
          If set the list of ResourceFilterFactory that are applied to resources.
static java.lang.String PROPERTY_WADL_GENERATOR_CONFIG
          If set the wadl generator configuration that provides a WadlGenerator.
 
Fields inherited from interface com.sun.jersey.core.util.FeaturesAndProperties
FEATURE_DISABLE_XML_SECURITY, FEATURE_FORMATTED, FEATURE_PRE_1_4_PROVIDER_PRECEDENCE, FEATURE_XMLROOTELEMENT_PROCESSING
 
Constructor Summary
ResourceConfig()
           
 
Method Summary
 void add(Application app)
          Add the state of an Application to this instance.
 ResourceConfig clone()
          Clone this resource configuration.
 java.util.List getContainerRequestFilters()
          Get the list of container request filters.
 java.util.List getContainerResponseFilters()
          Get the list of container response filters.
static java.lang.String[] getElements(java.lang.String[] elements)
          Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by ';'.
static java.lang.String[] getElements(java.lang.String[] elements, java.lang.String delimiters)
          Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by characters in delimiters string.
 java.util.Map<java.lang.String,java.lang.Object> getExplicitRootResources()
          Get a map of explicit root resource classes and root resource singleton instances.
abstract  boolean getFeature(java.lang.String featureName)
          Get the value of a feature.
abstract  java.util.Map<java.lang.String,java.lang.Boolean> getFeatures()
          Get the map of features associated with the Web application.
 java.util.Map<java.lang.String,java.lang.String> getLanguageMappings()
          Get a map of file extension to language.
 java.util.Map<java.lang.String,MediaType> getMediaTypeMappings()
          Get a map of file extension to media type.
abstract  java.util.Map<java.lang.String,java.lang.Object> getProperties()
          Get the map of properties associated with the Web application.
abstract  java.lang.Object getProperty(java.lang.String propertyName)
          Get the value of a property.
 java.util.Set<java.lang.Class<?>> getProviderClasses()
          Get the set of provider classes.
 java.util.Set<java.lang.Object> getProviderSingletons()
          Get the set of provider singleton instances.
 java.util.List getResourceFilterFactories()
          Get the list of resource filter factories.
 java.util.Set<java.lang.Class<?>> getRootResourceClasses()
          Get the set of root resource classes.
 java.util.Set<java.lang.Object> getRootResourceSingletons()
          Get the set of root resource singleton instances.
static boolean isProviderClass(java.lang.Class<?> c)
          Determine if a class is a provider class.
static boolean isRootResourceClass(java.lang.Class<?> c)
          Determine if a class is a root resource class.
 void setPropertiesAndFeatures(java.util.Map<java.lang.String,java.lang.Object> entries)
          Set the properties and features given a map of entries.
 void validate()
          Validate the set of classes and singletons.
 
Methods inherited from class javax.ws.rs.core.Application
getClasses, getSingletons
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FEATURE_NORMALIZE_URI

public static final java.lang.String FEATURE_NORMALIZE_URI
If true and FEATURE_CANONICALIZE_URI_PATH is true then the request URI will be normalized as specified by URI.normalize(). If not true the request URI is not modified.

The default value is false.

See Also:
Constant Field Values

FEATURE_CANONICALIZE_URI_PATH

public static final java.lang.String FEATURE_CANONICALIZE_URI_PATH
If true the request URI path component will be canonicalized by removing contiguous slashes (i.e. all /+ will be replaced by /). If not true the request URI path component is mot modified.

The default value is false.

See Also:
Constant Field Values

FEATURE_REDIRECT

public static final java.lang.String FEATURE_REDIRECT
If true, and #CANONICALIZE_URI_PATH is true, and the canonicalization/normalization operations on the request URI result in a new URI that is not equal to the request URI, then the client is (temporarily) redirected to the new URI.

If true, and the path value of a Path annotation ends in a slash, the request URI path does not end in a '/' and would otherwise match the path value if it did, then the client is (temporarily) redirected to a new URI that is the request URI with a '/' appended to the the end of the path.

The default value is false.

See Also:
Constant Field Values

FEATURE_MATCH_MATRIX_PARAMS

public static final java.lang.String FEATURE_MATCH_MATRIX_PARAMS
If true then matrix parameters (if present) in the request URI path component will not be ignored when matching the path to URI templates declared by resource classes.

The default value is false.

See Also:
Constant Field Values

FEATURE_IMPLICIT_VIEWABLES

public static final java.lang.String FEATURE_IMPLICIT_VIEWABLES
If true then the matching algorithm will attempt to match and accept any static content or templates associated with a resource that were not explicitly declared by that resource.

If a template is matched then the model for the viewable will be the resource instance associated with the template.

The default value is false.

See Also:
Constant Field Values

FEATURE_DISABLE_WADL

public static final java.lang.String FEATURE_DISABLE_WADL
If true then disable WADL generation.

By default WADL generation is automatically enabled, if JAXB is present in the classpath.

The default value is false.

See Also:
Constant Field Values

FEATURE_TRACE

public static final java.lang.String FEATURE_TRACE
If true then enable tracing.

Tracing provides useful information that describes how a request is processed and dispatched to JAX-RS/Jersey components. This can aid debugging when the application is not behaving as expected either because of a bug in the application code or in the Jersey code.

Trace messages will be primarily output as response headers with a header name of the form "X-Jersey-Trace-XXX", where XXX is a decimal value corresponding to the trace message number, and a header value that is the trace message.

In certain cases trace messages will be logged on the server-side if such messages are not suitable as response headers, for example if such messages are too verbose.

Trace messages will be output in the same order as traces occur.

To log response header trace messages on the server-side enable response logging, see LoggingFilter.

The default value is false.

See Also:
Constant Field Values

FEATURE_TRACE_PER_REQUEST

public static final java.lang.String FEATURE_TRACE_PER_REQUEST
If true then enable tracing on a per-request basis.

Tracing provides useful information that describes how a request is processed and dispatched to JAX-RS/Jersey components. This can aid debugging when the application is not behaving as expected either because of a bug in the application code or in the Jersey code.

Trace messages will be output if a request header is present with a header name of "X-Jersey-Trace-Accept" (the header value is ignored).

Trace messages will be primarily output as response headers with a header name of the form "X-Jersey-Trace-XXX", where XXX is a decimal value corresponding to the trace message number, and a header value that is the trace message.

In certain cases trace messages will be logged on the server-side if such messages are not suitable as response headers, for example if such messages are too verbose.

Trace messages will be output in the same order as traces occur.

To log response header trace messages on the server-side enable response logging, see LoggingFilter.

The default value is false.

See Also:
Constant Field Values

PROPERTY_MEDIA_TYPE_MAPPINGS

public static final java.lang.String PROPERTY_MEDIA_TYPE_MAPPINGS
If set the map of file extension to media type mappings that will be added to the map that is returned from getMediaTypeMappings().

This type of this property must be a String or String[] that contains one or more comma separated key value pairs of the form "<key> : <value>, <key> : <value>" where the key is the file extension and the value is the media type. For example, the following declares two mappings for XML and JSON: "xml : application/xml, json : application/json"

The value of this property will be validated, and keys/values added to map returned from getMediaTypeMappings(), when the validate() method is invoked.

Validation will verify that media types are valid.

See Also:
Constant Field Values

PROPERTY_LANGUAGE_MAPPINGS

public static final java.lang.String PROPERTY_LANGUAGE_MAPPINGS
If set the map of file extension to langauge mappings that will be added to the map that is returned from getLanguageMappings().

This type of this property must be a String or String[] that contains one or more comma separated key value pairs of the form "<key> : <value>, <key> : <value>" where the key is the file extension and the value is the language tag. For example, the following declares two mappings for the languages "en" and "en-US: "english : en, american : en-US".

The value of this property will be validated, and keys/values added to map returned from getMediaTypeMappings(), when the validate() method is invoked.

Validation will verify that language tags are valid according to HTTP/1.1 and are of the form:

   language-tag  = primary-tag *( "-" subtag )
   primary-tag   = 1*8ALPHA
   subtag        = 1*8ALPHA
 

See Also:
Constant Field Values

PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS

public static final java.lang.String PROPERTY_DEFAULT_RESOURCE_COMPONENT_PROVIDER_FACTORY_CLASS
If set the default resource component provider factory for the life-cycle of resource classes.

The type of this property must be a Class or a String that is a Class name, and the Class must a sub-class of ResourceComponentProviderFactory.

If not set the default resource component provider factory will be the per-request resource component provider factory.

See Also:
Constant Field Values

PROPERTY_CONTAINER_NOTIFIER

public static final java.lang.String PROPERTY_CONTAINER_NOTIFIER
If set the instance of ContainerNotifier to register ContainerListener instances.

If the instance does not implement the ContainerNotifier then the property is ignored.

See Also:
Constant Field Values

PROPERTY_CONTAINER_REQUEST_FILTERS

public static final java.lang.String PROPERTY_CONTAINER_REQUEST_FILTERS
If set the list of ContainerRequestFilter that are applied to filter the request. When applying the list of request filters to a request each request filter is applied, in order, from the first to the last entry in the list.

The instance may be a String[] or String that contains one or more fully qualified class name of a request filter class separated by ';', ',' or ' ' (space). Otherwise the instance may be List containing instances of String, String[], Class<? extends ContainerRequestFilter;> or instances of ContainerRequestFilter.

If a String[] or String of fully qualified class names or a Class then each class is instantiated as a singleton. Thus, if there is more than one class registered for this property or the same class is also registered for the PROPERTY_CONTAINER_RESPONSE_FILTERS property then only one instance will be instatiated.

See Also:
com.sun.jersey.api.container.filter, Constant Field Values

PROPERTY_CONTAINER_RESPONSE_FILTERS

public static final java.lang.String PROPERTY_CONTAINER_RESPONSE_FILTERS
If set the list of ContainerResponseFilter that are applied to filter the response. When applying the list of response filters to a response each response filter is applied, in order, from the first to the last entry in the list.

The instance may be a String[] or String that contains one or more fully qualified class name of a request filter class separated by ';', ',' or ' ' (space). Otherwise the instance may be List containing instances of String, String[], Class<? extends ContainerResponseFilter;> or instances of ContainerResponseFilter.

If a String[] or String of fully qualified class names or a Class then each class is instantiated as a singleton. Thus, if there is more than one class registered for this property or the same class is also registered for the PROPERTY_CONTAINER_REQUEST_FILTERS property then only one instance will be instatiated.

See Also:
com.sun.jersey.api.container.filter, Constant Field Values

PROPERTY_RESOURCE_FILTER_FACTORIES

public static final java.lang.String PROPERTY_RESOURCE_FILTER_FACTORIES
If set the list of ResourceFilterFactory that are applied to resources. When applying the list of resource filters factories to a request each resource filter factory is applied, in order, from the first to last entry in the list.

The instance may be a String[] or String that contains one or more fully qualified class name of a response filter class separated by ';', ',' or ' ' (space). Otherwise the instance may be List containing instances of String, String[], Class<? extends ResourceFilterFactory;> or instances of ResourceFilterFactory.

If a String[] or String of fully qualified class names or a Class then each class is instantiated as a singleton. Thus, if there is more than one class registered for this property one instance will be instatiated.

See Also:
com.sun.jersey.api.container.filter, Constant Field Values

PROPERTY_WADL_GENERATOR_CONFIG

public static final java.lang.String PROPERTY_WADL_GENERATOR_CONFIG
If set the wadl generator configuration that provides a WadlGenerator.

The type of this property must be a subclass or an instance of a subclass of WadlGeneratorConfig.

If this property is not set the default wadl generator will be used for generating wadl.

See Also:
Constant Field Values

COMMON_DELIMITERS

public static final java.lang.String COMMON_DELIMITERS
Common delimiters used by various properties.

See Also:
Constant Field Values
Constructor Detail

ResourceConfig

public ResourceConfig()
Method Detail

getFeatures

public abstract java.util.Map<java.lang.String,java.lang.Boolean> getFeatures()
Get the map of features associated with the Web application.

Specified by:
getFeatures in interface FeaturesAndProperties
Returns:
the features. The returned value shall never be null.

getFeature

public abstract boolean getFeature(java.lang.String featureName)
Get the value of a feature.

Specified by:
getFeature in interface FeaturesAndProperties
Parameters:
featureName - the feature name.
Returns:
true if the feature is present and set to true, otherwise false if the feature is present and set to false or the feature is not present.

getProperties

public abstract java.util.Map<java.lang.String,java.lang.Object> getProperties()
Get the map of properties associated with the Web application.

Specified by:
getProperties in interface FeaturesAndProperties
Returns:
the properties. The returned value shall never be null.

getProperty

public abstract java.lang.Object getProperty(java.lang.String propertyName)
Get the value of a property.

Specified by:
getProperty in interface FeaturesAndProperties
Parameters:
propertyName - the property name.
Returns:
the property, or null if there is no property present for the given property name.

getMediaTypeMappings

public java.util.Map<java.lang.String,MediaType> getMediaTypeMappings()
Get a map of file extension to media type. This is used to drive URI-based content negotiation such that, e.g.:
GET /resource.atom

is equivalent to:

GET /resource
Accept: application/atom+xml

The default implementation returns an empty map.

Returns:
a map of file extension to media type

getLanguageMappings

public java.util.Map<java.lang.String,java.lang.String> getLanguageMappings()
Get a map of file extension to language. This is used to drive URI-based content negotiation such that, e.g.:
GET /resource.english

is equivalent to:

GET /resource
Accept-Language: en

The default implementation returns an empty map.

Returns:
a map of file extension to language

getExplicitRootResources

public java.util.Map<java.lang.String,java.lang.Object> getExplicitRootResources()
Get a map of explicit root resource classes and root resource singleton instances. The default lifecycle for root resource class instances is per-request.

The root resource path template is declared using the key in the map. This is a substitute for the declaration of a Path annotation on a root resource class or singleton instance. The key has the same semantics as the Path.value(). If such a Path annotation is present it will be ignored.

For example, the following will register two root resources, first a root resource class at the path "class" and a root resource singleton at the path "singleton":

     getExplicitRootResources().put("class", RootResourceClass.class);
     getExplicitRootResources().put("singleton", new RootResourceSingleton());
 

Returns:
a map of explicit root resource classes and root resource singleton instances.

validate

public void validate()
Validate the set of classes and singletons.

A registered class is removed from the set of registered classes if an instance of that class is a member of the set of registered singletons.

A registered class that is an interface or an abstract class is removed from the registered classes.

File extension to media type and language mappings in the properties PROPERTY_MEDIA_TYPE_MAPPINGS and PROPERTY_LANGUAGE_MAPPINGS, respectively, are processed and key/values pairs added to the maps returned from getMediaTypeMappings() and getLanguageMappings(), respectively. The characters of file extension values will be contextually encoded according to the set of valid characters defined for a path segment.

Throws:
java.lang.IllegalArgumentException - if the set of registered singletons contains more than one instance of the same root resource class, or validation of media type and language mappings failed.

getRootResourceClasses

public java.util.Set<java.lang.Class<?>> getRootResourceClasses()
Get the set of root resource classes.

A root resource class is a registered class that is annotated with Path.

Returns:
the set of root resource classes.

getProviderClasses

public java.util.Set<java.lang.Class<?>> getProviderClasses()
Get the set of provider classes.

A provider class is a registered class that is not annotated with Path.

Returns:
the set of provider classes.

getRootResourceSingletons

public java.util.Set<java.lang.Object> getRootResourceSingletons()
Get the set of root resource singleton instances.

A root resource singleton instance is a registered instance whose class is annotated with Path.

Returns:
the set of root resource singleton instances.

getProviderSingletons

public java.util.Set<java.lang.Object> getProviderSingletons()
Get the set of provider singleton instances.

A provider singleton instances is a registered instance whose class is not annotated with Path.

Returns:
the set of provider singleton instances.

isRootResourceClass

public static boolean isRootResourceClass(java.lang.Class<?> c)
Determine if a class is a root resource class.

Parameters:
c - the class.
Returns:
true if the class is a root resource class, otherwise false (including if the class is null).

isProviderClass

public static boolean isProviderClass(java.lang.Class<?> c)
Determine if a class is a provider class.

Parameters:
c - the class.
Returns:
true if the class is a provider class, otherwise false (including if the class is null)

getContainerRequestFilters

public java.util.List getContainerRequestFilters()
Get the list of container request filters.

This list may be modified to add or remove filter elements. See PROPERTY_CONTAINER_REQUEST_FILTERS for the valid elements of the list.

Returns:
the list of container request filters. An empty list will be returned if no filters are present.

getContainerResponseFilters

public java.util.List getContainerResponseFilters()
Get the list of container response filters.

This list may be modified to add or remove filter elements. See PROPERTY_CONTAINER_RESPONSE_FILTERS for the valid elements of the list.

Returns:
the list of container response filters. An empty list will be returned if no filters are present.

getResourceFilterFactories

public java.util.List getResourceFilterFactories()
Get the list of resource filter factories.

This list may be modified to add or remove filter elements. See PROPERTY_RESOURCE_FILTER_FACTORIES for the valid elements of the list.

Returns:
the list of resource filter factories. An empty list will be returned if no filters are present.

setPropertiesAndFeatures

public void setPropertiesAndFeatures(java.util.Map<java.lang.String,java.lang.Object> entries)
Set the properties and features given a map of entries.

Parameters:
entries - the map of entries. All entries are added as properties. Properties are only added if an existing property does not currently exist. Any entry with a value that is an instance of Boolean is added as a feature with the feature name set to the entry name and the feature value set to the entry value. Any entry with a value that is an instance String and is equal (ignoring case and white space) to "true" or "false" is added as a feature with the feature name set to the entry name and the feature value set to the Boolean value of the entry value. Features are only added if an existing feature does not currently exist.

add

public void add(Application app)
Add the state of an Application to this instance.

Parameters:
app - the application.

clone

public ResourceConfig clone()
Clone this resource configuration.

The set of classes, set of singletons, map of explicit root resources, map of language mappings, map of media type mappings, map of features and map of properties will be cloned.

Overrides:
clone in class java.lang.Object
Returns:
a cloned instance of this resource configuration.

getElements

public static java.lang.String[] getElements(java.lang.String[] elements)
Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by ';'.

Parameters:
elements - an array where each String entry may contain zero or more ';' separated elements.
Returns:
the array of elements, each element is trimmed, the array will not contain any empty or null entries.

getElements

public static java.lang.String[] getElements(java.lang.String[] elements,
                                             java.lang.String delimiters)
Get a canonical array of String elements from a String array where each entry may contain zero or more elements separated by characters in delimiters string.

Parameters:
elements - an array where each String entry may contain zero or more delimiters separated elements.
delimiters - string with delimiters, every character represents one delimiter.
Returns:
the array of elements, each element is trimmed, the array will not contain any empty or null entries.


Copyright © 2010 Oracle Corporation. All Rights Reserved.