@PreMatching @Priority(value=3000) public final class UriConnegFilter extends Object implements ContainerRequestFilter
Acceptheader or a language that is the value of the
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
If a suffix of "atom" is registered with a media type of "application/atom+xml" then a GET request of:
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:
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|
|Constructor and Description|
Create a filter that reads the configuration (media type and language mappings) from the provided
Create a filter with suffix to media type mappings and suffix to language mappings.
|Modifier and Type||Method and Description|
Filter method called before a request has been dispatched to a resource.
public UriConnegFilter(@Context Configuration rc)
ResourceConfiginstance. This constructor will be called by the Jersey runtime when the filter class is returned from
ResourceConfiginstance 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 void filter(ContainerRequestContext rc) throws IOException
Filters in the filter chain are ordered according to their
class-level annotation value.
If a request filter produces a response by calling
method, the execution of the (either pre-match or post-match) request filter
chain is stopped and the response is passed to the corresponding response
filter chain (either pre-match or post-match). For example, a pre-match
caching filter may produce a response in this way, which would effectively
skip any post-match request filters as well as post-match response filters.
Note however that a responses produced in this manner would still be processed
by the pre-match response filter chain.
Copyright © 2007-2017, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.