org.glassfish.jersey.server.filter
Class HttpMethodOverrideFilter

java.lang.Object
  extended by org.glassfish.jersey.server.filter.HttpMethodOverrideFilter
All Implemented Interfaces:
ContainerRequestFilter

@PreMatching
public 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_REQUEST response.

The filter behavior can be configured using ServerProperties.HTTP_METHOD_OVERRIDE property.

Author:
Paul Sandoz (paul.sandoz at oracle.com), Martin Matula (martin.matula at oracle.com), Fredy Nagy, Florian Hars (florian at hars.de)

Nested Class Summary
static class HttpMethodOverrideFilter.Source
          Enumeration representing possible sources of information about the method overriding the filter should look for.
 
Constructor Summary
HttpMethodOverrideFilter(HttpMethodOverrideFilter.Source... sources)
          Initializes this filter setting the sources of information the filter should look for.
HttpMethodOverrideFilter(ResourceConfig rc)
          Create a filter that reads the configuration (ServerProperties.HTTP_METHOD_OVERRIDE) from the provided ResourceConfig instance.
 
Method Summary
static void enableFor(ResourceConfig rc, HttpMethodOverrideFilter.Source... sources)
          Registers this filter into the passed ResourceConfig instance and configures it.
 void filter(ContainerRequestContext request)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpMethodOverrideFilter

public HttpMethodOverrideFilter(@Context
                                ResourceConfig rc)
Create a filter that reads the configuration (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.

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, both HttpMethodOverrideFilter.Source.HEADER and HttpMethodOverrideFilter.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 passed ResourceConfig instance and configures it.

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

filter

public void filter(ContainerRequestContext request)
Specified by:
filter in interface ContainerRequestFilter


Copyright © 2007-2012 Oracle Corporation. All Rights Reserved. Use is subject to license terms.