com.sun.jersey.api.container.filter
Class PostReplaceFilter

java.lang.Object
  extended by com.sun.jersey.api.container.filter.PostReplaceFilter
All Implemented Interfaces:
ContainerRequestFilter

public class PostReplaceFilter
extends java.lang.Object
implements ContainerRequestFilter

A 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.

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.

Author:
[email protected], Martin Matula, Fredy Nagy, Florian Hars ([email protected])
See Also:
com.sun.jersey.api.container.filter

Nested Class Summary
static class PostReplaceFilter.ConfigFlag
          Enum representing configuration flags that can be set on the filter.
 
Field Summary
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 Summary
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.
 
Method Summary
 ContainerRequest filter(ContainerRequest request)
          Filter the request.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PROPERTY_POST_REPLACE_FILTER_CONFIG

public static final 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. 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:

     <init-param>
         <param-name>com.sun.jersey.api.container.filter.PostReplaceFilterConfig</param-name>
         <param-value>HEADER</param-value>
     </init-param>
 
The above setting would cause the filter would only look at the X-HTTP-Method-Override header and ignore _method query parameter.

See Also:
Constant Field Values
Constructor Detail

PostReplaceFilter

public PostReplaceFilter(@Context
                         ResourceConfig rc)
Initializes this filter with 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.

Parameters:
rc - resource config (injected by Jersey)

PostReplaceFilter

public PostReplaceFilter(PostReplaceFilter.ConfigFlag... configFlags)
Initializes this filter with config flags.

Parameters:
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.
Method Detail

filter

public ContainerRequest filter(ContainerRequest request)
Description copied from interface: ContainerRequestFilter
Filter the request.

An implementation may modify the state of the request or create a new instance.

Specified by:
filter in interface ContainerRequestFilter
Parameters:
request - the request.
Returns:
the request.


Copyright © 2011 Oracle Corporation. All Rights Reserved.