public class PostReplaceFilter extends java.lang.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.
When an application is deployed as a Servlet or Filter this Jersey filter can be registered using the following initialization parameter:
<init-param> <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name> <param-value>com.sun.jersey.api.container.filter.PostReplaceFilter</param-value> </init-param>
The filter can be configured using the com.sun.jersey.api.container.filter.PostReplaceFilterConfig property.
See PROPERTY_POST_REPLACE_FILTER_CONFIG
for the supported property values.
com.sun.jersey.api.container.filter
Modifier and Type | Class and Description |
---|---|
static class |
PostReplaceFilter.ConfigFlag
Enum representing configuration flags that can be set on the filter.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
PROPERTY_POST_REPLACE_FILTER_CONFIG
Property that may contain a comma-separated list of the configuration flags to be set on this filter.
|
Constructor and Description |
---|
PostReplaceFilter(PostReplaceFilter.ConfigFlag... configFlags)
Initializes this filter with config flags.
|
PostReplaceFilter(ResourceConfig rc)
Initializes this filter with
PROPERTY_POST_REPLACE_FILTER_CONFIG property value from the application resource config. |
Modifier and Type | Method and Description |
---|---|
ContainerRequest |
filter(ContainerRequest request)
Filter the request.
|
public static final java.lang.String PROPERTY_POST_REPLACE_FILTER_CONFIG
PostReplaceFilter.ConfigFlag
enum lists the allowed config flags.
If this property is not set, the default value "HEADER,QUERY" will be used to initialize the filter.
When an application is deployed as a servlet or filter this property can be set using the following initialization parameter:
The above setting would cause the filter would only look at the X-HTTP-Method-Override header and ignore _method query parameter.<init-param> <param-name>com.sun.jersey.api.container.filter.PostReplaceFilterConfig</param-name> <param-value>HEADER</param-value> </init-param>
public PostReplaceFilter(@Context ResourceConfig rc)
PROPERTY_POST_REPLACE_FILTER_CONFIG
property value from the application resource config.
If the property has no value, both PostReplaceFilter.ConfigFlag.HEADER
and PostReplaceFilter.ConfigFlag.QUERY
will be added to the config.rc
- resource config (injected by Jersey)public PostReplaceFilter(PostReplaceFilter.ConfigFlag... configFlags)
configFlags
- Config flags to initialize the filter with. If no config flags are passed,
both PostReplaceFilter.ConfigFlag.HEADER
and PostReplaceFilter.ConfigFlag.QUERY
will be added to the config.public ContainerRequest filter(ContainerRequest request)
ContainerRequestFilter
An implementation may modify the state of the request or create a new instance.
filter
in interface ContainerRequestFilter
request
- the request.Copyright © 2016 Oracle Corporation. All Rights Reserved.