@PreMatching @Priority(value=3050) public final class HttpMethodOverrideFilter extends Object implements ContainerRequestFilter
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.
Modifier and Type | Class and Description |
---|---|
static class |
HttpMethodOverrideFilter.Source
Enumeration representing possible sources of information about the method overriding
the filter should look for.
|
Constructor and Description |
---|
HttpMethodOverrideFilter(Configuration rc)
Create a filter that reads the configuration (
ServerProperties.HTTP_METHOD_OVERRIDE )
from the provided ResourceConfig instance. |
HttpMethodOverrideFilter(HttpMethodOverrideFilter.Source... sources)
Initializes this filter setting the sources of information the filter should look for.
|
Modifier and Type | Method and Description |
---|---|
static void |
enableFor(ResourceConfig rc,
HttpMethodOverrideFilter.Source... sources)
Registers this filter into the passed
ResourceConfig instance and
configures it. |
void |
filter(ContainerRequestContext request)
Filter method called before a request has been dispatched to a resource.
|
public HttpMethodOverrideFilter(@Context Configuration rc)
ServerProperties.HTTP_METHOD_OVERRIDE
)
from the provided 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 HttpMethodOverrideFilter(HttpMethodOverrideFilter.Source... sources)
sources
- Sources of method override information. If empty, both
HttpMethodOverrideFilter.Source.HEADER
and
HttpMethodOverrideFilter.Source.QUERY
will
be added to the config by default.public static void enableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)
ResourceConfig
instance and
configures it.rc
- Resource config.sources
- Sources of method override information. If empty, both
HttpMethodOverrideFilter.Source.HEADER
and
HttpMethodOverrideFilter.Source.QUERY
will
be added to the config by default.public void filter(ContainerRequestContext request)
ContainerRequestFilter
Filters in the filter chain are ordered according to their javax.annotation.Priority
class-level annotation value.
If a request filter produces a response by calling ContainerRequestContext.abortWith(javax.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.
filter
in interface ContainerRequestFilter
request
- request context.PreMatching
Copyright © 2007-2015, Oracle and/or its affiliates. All Rights Reserved. Use is subject to license terms.