Class HttpMethodOverrideFilter
- java.lang.Object
-
- org.glassfish.jersey.server.filter.HttpMethodOverrideFilter
-
- All Implemented Interfaces:
javax.ws.rs.container.ContainerRequestFilter
@PreMatching @Priority(3050) public final class HttpMethodOverrideFilter extends java.lang.Object implements javax.ws.rs.container.ContainerRequestFilter
A pre-matching filter to support HTTP method replacing of a POST request to a request utilizing another HTTP method for the case where proxies or HTTP servers would otherwise block that HTTP method.This filter may be used to replace a POST request with a PUT, DELETE or GET request.
Replacement will occur if the request method is POST and there exists either a request header "X-HTTP-Method-Override", or a query parameter "_method" with a non-empty value. That value will be the HTTP method that replaces the POST method. In addition to that, when replacing the POST method with GET, the filter will convert the form parameters to query parameters. If the filter is configured to look for both the X-HTTP-Method-Override header as well as the _method query parameter (the default setting), both are present in the request and they differ, the filter returns
Response.Status.BAD_REQUEST
response.The filter behavior can be configured using
ServerProperties.HTTP_METHOD_OVERRIDE
property.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
HttpMethodOverrideFilter.Source
Enumeration representing possible sources of information about the method overriding the filter should look for.
-
Field Summary
Fields Modifier and Type Field Description (package private) int
config
Configuration flags.
-
Constructor Summary
Constructors Constructor Description HttpMethodOverrideFilter(javax.ws.rs.core.Configuration rc)
Create a filter that reads the configuration (ServerProperties.HTTP_METHOD_OVERRIDE
) from the providedResourceConfig
instance.HttpMethodOverrideFilter(HttpMethodOverrideFilter.Source... sources)
Initializes this filter setting the sources of information the filter should look for.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
enableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)
Registers this filter into the passedResourceConfig
instance and configures it.void
filter(javax.ws.rs.container.ContainerRequestContext request)
private java.lang.String
getParamValue(HttpMethodOverrideFilter.Source source, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> paramsMap, java.lang.String paramName)
Returns parameter value in a normalized form (uppercase, trimmed andnull
if empty string) considering the config flags.private static HttpMethodOverrideFilter.Source[]
parseConfig(java.lang.Object config)
Converts configuration property value to an array ofHttpMethodOverrideFilter.Source
literals.
-
-
-
Constructor Detail
-
HttpMethodOverrideFilter
public HttpMethodOverrideFilter(@Context javax.ws.rs.core.Configuration rc)
Create a filter that reads the configuration (ServerProperties.HTTP_METHOD_OVERRIDE
) from the providedResourceConfig
instance. This constructor will be called by the Jersey runtime when the filter class is returned fromApplication.getClasses()
. TheResourceConfig
instance will get auto-injected.- Parameters:
rc
- ResourceConfig instance that holds the configuration for the filter.
-
HttpMethodOverrideFilter
public HttpMethodOverrideFilter(HttpMethodOverrideFilter.Source... sources)
Initializes this filter setting the sources of information the filter should look for.- Parameters:
sources
- Sources of method override information. If empty, bothHttpMethodOverrideFilter.Source.HEADER
andHttpMethodOverrideFilter.Source.QUERY
will be added to the config by default.
-
-
Method Detail
-
enableFor
public static void enableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)
Registers this filter into the passedResourceConfig
instance and configures it.- Parameters:
rc
- Resource config.sources
- Sources of method override information. If empty, bothHttpMethodOverrideFilter.Source.HEADER
andHttpMethodOverrideFilter.Source.QUERY
will be added to the config by default.
-
parseConfig
private static HttpMethodOverrideFilter.Source[] parseConfig(java.lang.Object config)
Converts configuration property value to an array ofHttpMethodOverrideFilter.Source
literals.- Parameters:
config
-configuration property
value- Returns:
- array of
Source
objects.
-
getParamValue
private java.lang.String getParamValue(HttpMethodOverrideFilter.Source source, javax.ws.rs.core.MultivaluedMap<java.lang.String,java.lang.String> paramsMap, java.lang.String paramName)
Returns parameter value in a normalized form (uppercase, trimmed andnull
if empty string) considering the config flags.- Parameters:
source
- Config flag to look for (if set in the config, this method returns the param value, if not set, this method returnsnull
).paramsMap
- Map to retrieve the parameter from.paramName
- Name of the parameter to retrieve.- Returns:
- Normalized parameter value. Never returns an empty string - converts it to
null
.
-
filter
public void filter(javax.ws.rs.container.ContainerRequestContext request)
- Specified by:
filter
in interfacejavax.ws.rs.container.ContainerRequestFilter
-
-