Class UriConnegFilter
- java.lang.Object
-
- org.glassfish.jersey.server.filter.UriConnegFilter
-
- All Implemented Interfaces:
javax.ws.rs.container.ContainerRequestFilter
@PreMatching @Priority(3000) public final class UriConnegFilter extends java.lang.Object implements javax.ws.rs.container.ContainerRequestFilterA URI-based content negotiation filter mapping a dot-declared suffix in URI to media type that is the value of theAcceptheader or a language that is the value of theAccept-Languageheader.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.MyUriConnegFiltersay, 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+xml
Any 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: en
Any existing "Accept-Language"header value will be replaced. The media type mappings are processed before the language type mappings.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interfaceUriConnegFilter.TypeParser<T>
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.lang.String>languageMappingsprotected java.util.Map<java.lang.String,javax.ws.rs.core.MediaType>mediaTypeMappings
-
Constructor Summary
Constructors Constructor Description UriConnegFilter(java.util.Map<java.lang.String,javax.ws.rs.core.MediaType> mediaTypeMappings, java.util.Map<java.lang.String,java.lang.String> languageMappings)Create a filter with suffix to media type mappings and suffix to language mappings.UriConnegFilter(javax.ws.rs.core.Configuration rc)Create a filter that reads the configuration (media type and language mappings) from the providedResourceConfiginstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static <T> voidencodeKeys(java.util.Map<java.lang.String,T> map)private static java.util.Map<java.lang.String,java.lang.String>extractLanguageMappings(java.lang.Object mappings)private static java.util.Map<java.lang.String,javax.ws.rs.core.MediaType>extractMediaTypeMappings(java.lang.Object mappings)voidfilter(javax.ws.rs.container.ContainerRequestContext rc)private static <T> java.util.Map<java.lang.String,T>parseAndValidateMappings(java.lang.String property, java.lang.Object mappings, UriConnegFilter.TypeParser<T> parser)private static <T> voidparseMappings(java.lang.String property, java.lang.String mappings, java.util.Map<java.lang.String,T> mappingsMap, UriConnegFilter.TypeParser<T> parser)
-
-
-
Constructor Detail
-
UriConnegFilter
public UriConnegFilter(@Context javax.ws.rs.core.Configuration rc)Create a filter that reads the configuration (media type and language mappings) from the providedResourceConfiginstance. This constructor will be called by the Jersey runtime when the filter class is returned fromApplication.getClasses(). TheResourceConfiginstance will get auto-injected.- Parameters:
rc- ResourceConfig instance that holds the configuration for the filter.
-
UriConnegFilter
public UriConnegFilter(java.util.Map<java.lang.String,javax.ws.rs.core.MediaType> mediaTypeMappings, java.util.Map<java.lang.String,java.lang.String> languageMappings)Create a filter with suffix to media type mappings and suffix to language mappings.- Parameters:
mediaTypeMappings- the suffix to media type mappings.languageMappings- the suffix to language mappings.
-
-
Method Detail
-
filter
public void filter(javax.ws.rs.container.ContainerRequestContext rc) throws java.io.IOException- Specified by:
filterin interfacejavax.ws.rs.container.ContainerRequestFilter- Throws:
java.io.IOException
-
extractMediaTypeMappings
private static java.util.Map<java.lang.String,javax.ws.rs.core.MediaType> extractMediaTypeMappings(java.lang.Object mappings)
-
extractLanguageMappings
private static java.util.Map<java.lang.String,java.lang.String> extractLanguageMappings(java.lang.Object mappings)
-
parseAndValidateMappings
private static <T> java.util.Map<java.lang.String,T> parseAndValidateMappings(java.lang.String property, java.lang.Object mappings, UriConnegFilter.TypeParser<T> parser)
-
parseMappings
private static <T> void parseMappings(java.lang.String property, java.lang.String mappings, java.util.Map<java.lang.String,T> mappingsMap, UriConnegFilter.TypeParser<T> parser)
-
encodeKeys
private static <T> void encodeKeys(java.util.Map<java.lang.String,T> map)
-
-