@PreMatching public class UriConnegFilter extends Object implements ContainerRequestFilter
Accept header
or a language that is the value of the Accept-Language header.
This filter may be used when the acceptable media type and acceptable language need to be declared in the URI.
This class may be extended to declare the mappings and the extending class,
foo.MyUriConnegFilter say, can be registered as a container request
filter.
If a suffix of "atom" is registered with a media type of "application/atom+xml" then a GET request of:
GET /resource.atom
is transformed to:
GET /resource Accept: application/atom+xmlAny existing "Accept" header value will be replaced.
If a suffix of "english" is registered with a language of "en" then a GET request of:
GET /resource.english
is transformed to:
GET /resource Accept-Language: enAny existing "Accept-Language"header value will be replaced.
The media type mappings are processed before the language type mappings.
| Modifier and Type | Field and Description |
|---|---|
protected Map<String,String> |
languageMappings |
protected Map<String,MediaType> |
mediaTypeMappings |
| Constructor and Description |
|---|
UriConnegFilter(Configuration rc)
Create a filter that reads the configuration (media type and language mappings)
from the provided
ResourceConfig instance. |
UriConnegFilter(Map<String,MediaType> mediaTypeMappings,
Map<String,String> languageMappings)
Create a filter with suffix to media type mappings and suffix to
language mappings.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
enableFor(ResourceConfig rc,
Map<String,MediaType> mediaTypeMappings,
Map<String,String> languageMappings)
Registers this filter into the passed
ResourceConfig instance and
configures it. |
static void |
enableFor(ResourceConfig rc,
String mediaTypeMappings,
String languageMappings) |
void |
filter(ContainerRequestContext rc) |
public UriConnegFilter(@Context Configuration rc)
ResourceConfig instance.
This constructor will be called by the Jersey runtime when the filter
class is returned from Application.getClasses().
The ResourceConfig instance will get auto-injected.rc - ResourceConfig instance that holds the configuration for the filter.public UriConnegFilter(Map<String,MediaType> mediaTypeMappings, Map<String,String> languageMappings)
mediaTypeMappings - the suffix to media type mappings.languageMappings - the suffix to language mappings.public static void enableFor(ResourceConfig rc, Map<String,MediaType> mediaTypeMappings, Map<String,String> languageMappings)
ResourceConfig instance and
configures it.rc - ResourceConfig instance where the filter should be registered.mediaTypeMappings - the suffix to media type mappings.languageMappings - the suffix to language mappings.public static void enableFor(ResourceConfig rc, String mediaTypeMappings, String languageMappings)
public void filter(ContainerRequestContext rc) throws IOException
filter in interface ContainerRequestFilterIOExceptionCopyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.