org.apache.struts2.interceptor.httpmethod

## Class HttpMethodInterceptor

- java.lang.Object
- - org.apache.struts2.interceptor.AbstractInterceptor
  - - com.opensymphony.xwork2.interceptor.AbstractInterceptor
    - - org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor

- All Implemented Interfaces:
    Serializable, ConditionalInterceptor, Interceptor

      public class HttpMethodInterceptor
      extends AbstractInterceptor

  Interceptor is used to control with what http methods action can be called, if request with not allowed method was performed, `badRequestResultName` will be returned or if action implements `HttpMethodAware` and `HttpMethodAware.getBadRequestResultName()` returns non-null result name, thus value will be used instead.

  To limit allowed http methods, annotate action class with `AllowedHttpMethod` and specify, which methods are allowed. You can also use shorter versions `HttpGet`, `HttpPost`, `HttpPut`, `HttpDelete` and `HttpGetOrPost`

  You can combine any of these annotations to achieve required allowed methods' filtering.

  Since:
    6.2.0
  See Also:
    `HttpMethodAware`, `HttpMethod`, `AllowedHttpMethod`, `HttpGet`, `HttpPost`, `HttpPut`, `HttpDelete`, `HttpGetOrPost`, Serialized Form

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `ConditionalInterceptor.LegacyAdapter`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `HttpMethodInterceptor()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected String` | `doIntercept(ActionInvocation invocation, AnnotatedElement element)`
    `protected String` | `getBadRequestResultName(ActionInvocation invocation)`
    `String` | `intercept(ActionInvocation invocation)` Override to handle interception
    `protected List<HttpMethod>` | `readAllowedMethods(AnnotatedElement element)`
    `void` | `setBadRequestResultName(String badRequestResultName)`

    - ### Methods inherited from class com.opensymphony.xwork2.interceptor.AbstractInterceptor

      `intercept, shouldIntercept, shouldIntercept`

    - ### Methods inherited from class org.apache.struts2.interceptor.AbstractInterceptor

      `destroy, init, setDisabled`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.ConditionalInterceptor

      `adapt`

    - ### Methods inherited from interface com.opensymphony.xwork2.interceptor.Interceptor

      `adapt`

    - ### Methods inherited from interface org.apache.struts2.interceptor.Interceptor

      `destroy, init`

- - ### Constructor Detail

    - #### HttpMethodInterceptor

          public HttpMethodInterceptor()

  - ### Method Detail

    - #### intercept

          public String intercept(ActionInvocation invocation)
                           throws Exception

      Description copied from class: `AbstractInterceptor`
      Override to handle interception
      Specified by:
        `intercept` in class `AbstractInterceptor`
      Throws:
        `Exception`

    - #### doIntercept

          protected String doIntercept(ActionInvocation invocation,
                                       AnnotatedElement element)
                                throws Exception

      Throws:
        `Exception`

    - #### readAllowedMethods

          protected List<HttpMethod> readAllowedMethods(AnnotatedElement element)

    - #### getBadRequestResultName

          protected String getBadRequestResultName(ActionInvocation invocation)

    - #### setBadRequestResultName

          public void setBadRequestResultName(String badRequestResultName)

Copyright © 2000–2026 Apache Software Foundation. All rights reserved.