Class HttpMethodOverrideFilter
- java.lang.Object
-
- org.glassfish.jersey.server.filter.HttpMethodOverrideFilter
-
- All Implemented Interfaces:
ContainerRequestFilter
@PreMatching @Priority(3050) public final class HttpMethodOverrideFilter extends Object implements 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_REQUESTresponse.The filter behavior can be configured using
ServerProperties.HTTP_METHOD_OVERRIDEproperty.- Author:
- Paul Sandoz, Martin Matula, Fredy Nagy, Florian Hars (florian at hars.de)
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classHttpMethodOverrideFilter.SourceEnumeration representing possible sources of information about the method overriding the filter should look for.
-
Constructor Summary
Constructors Constructor Description HttpMethodOverrideFilter(Configuration rc)Create a filter that reads the configuration (ServerProperties.HTTP_METHOD_OVERRIDE) from the providedResourceConfiginstance.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 voidenableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)Registers this filter into the passedResourceConfiginstance and configures it.voidfilter(ContainerRequestContext request)Filter method called before a request has been dispatched to a resource.
-
-
-
Constructor Detail
-
HttpMethodOverrideFilter
public HttpMethodOverrideFilter(@Context Configuration rc)
Create a filter that reads the configuration (ServerProperties.HTTP_METHOD_OVERRIDE) 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.
-
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.HEADERandHttpMethodOverrideFilter.Source.QUERYwill be added to the config by default.
-
-
Method Detail
-
enableFor
public static void enableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)
Registers this filter into the passedResourceConfiginstance and configures it.- Parameters:
rc- Resource config.sources- Sources of method override information. If empty, bothHttpMethodOverrideFilter.Source.HEADERandHttpMethodOverrideFilter.Source.QUERYwill be added to the config by default.
-
filter
public void filter(ContainerRequestContext request)
Description copied from interface:ContainerRequestFilterFilter method called before a request has been dispatched to a resource.Filters in the filter chain are ordered according to their
jakarta.annotation.Priorityclass-level annotation value. If a request filter produces a response by callingContainerRequestContext.abortWith(jakarta.ws.rs.core.Response)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.- Specified by:
filterin interfaceContainerRequestFilter- Parameters:
request- request context.- See Also:
PreMatching
-
-