You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by lu...@apache.org on 2023/01/22 10:25:02 UTC

[struts] branch http-interceptor created (now 650d33c81)

This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a change to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git


      at 650d33c81 Updates JavaDocs

This branch includes the following new commits:

     new da57a0402 Defined enum with all http methods
     new b3ff475e1 Defines annotations to control access based on http method Defines main annotation AllowedMethod and helper annotations used in most common situation, eg. GetOnly, PostOnly, etc.
     new 80c7005be Adds new http interceptor to allow block access based on method type
     new 68ded66f8 Adds new interface to allow action cooperate with HttpMethodInterceptor
     new 88ea4419c Adds JavaDoc
     new 7fa5133b1 Adds support for annotations on methods
     new 8ea9e9920 Adds test cases
     new e6f4cc5da Updates JavaDocs in annotations
     new 2bc0158df Renames basic annotation to better express its meaning
     new 5cf1bfc16 Adds httpInterceptor to stacks
     new 33f63cee3 Renames annotation to have more explicit meaning
     new a576d628d Adjusts better formatting
     new f48a4c60e Defines another annotation shortcuts
     new b24c40712 Extends interceptor to allow use combination of different Http methods
     new 650d33c81 Updates JavaDocs

The 15 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[struts] 10/15: Adds httpInterceptor to stacks

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 5cf1bfc16696d50788aee0ae0534bf1cf9bc6442
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Apr 20 22:35:18 2014 +0200

    Adds httpInterceptor to stacks
---
 core/src/main/resources/struts-default.xml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/core/src/main/resources/struts-default.xml b/core/src/main/resources/struts-default.xml
index aec2e0278..90657630e 100644
--- a/core/src/main/resources/struts-default.xml
+++ b/core/src/main/resources/struts-default.xml
@@ -89,6 +89,7 @@
             <interceptor name="multiselect" class="org.apache.struts2.interceptor.MultiselectInterceptor"/>
             <interceptor name="noop" class="org.apache.struts2.interceptor.NoOpInterceptor"/>
             <interceptor name="fetchMetadata" class="org.apache.struts2.interceptor.FetchMetadataInterceptor"/>
+            <interceptor name="httpMethod" class="org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor" />
 
             <!-- Empty stack - performs no operations -->
             <interceptor-stack name="emptyStack">
@@ -99,6 +100,7 @@
             <interceptor-stack name="basicStack">
                 <interceptor-ref name="exception"/>
                 <interceptor-ref name="servletConfig"/>
+                <interceptor-ref name="httpMethod"/>
                 <interceptor-ref name="prepare"/>
                 <interceptor-ref name="checkbox"/>
                 <interceptor-ref name="datetime"/>
@@ -160,6 +162,7 @@
                 <interceptor-ref name="multiselect"/>
                 <interceptor-ref name="params"/>
                 <interceptor-ref name="servletConfig"/>
+                <interceptor-ref name="httpMethod"/>
                 <interceptor-ref name="prepare"/>
                 <interceptor-ref name="chain"/>
                 <interceptor-ref name="modelDriven"/>
@@ -191,6 +194,7 @@
                 <interceptor-ref name="exception"/>
                 <interceptor-ref name="alias"/>
                 <interceptor-ref name="servletConfig"/>
+                <interceptor-ref name="httpMethod"/>
                 <interceptor-ref name="i18n"/>
                 <interceptor-ref name="csp">
                     <param name="disabled">false</param>


[struts] 14/15: Extends interceptor to allow use combination of different Http methods

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit b24c407125cfdfcd46d0cde92909c642f0b29bbd
Author: Lukasz Lenart <lu...@gmail.com>
AuthorDate: Sun Sep 21 22:04:53 2014 +0200

    Extends interceptor to allow use combination of different Http methods
---
 .../httpmethod/HttpMethodInterceptor.java          | 17 ++++--
 .../org/apache/struts2/HttpMethodsTestAction.java  | 12 ++++
 .../httpmethod/HttpMethodInterceptorTest.java      | 69 ++++++++++++++++++++++
 3 files changed, 93 insertions(+), 5 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index 668f39ce0..300e203f2 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -10,6 +10,7 @@ import org.apache.struts2.ServletActionContext;
 import javax.servlet.http.HttpServletRequest;
 import java.lang.reflect.AnnotatedElement;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -94,18 +95,24 @@ public class HttpMethodInterceptor extends AbstractInterceptor {
     }
 
     protected List<HttpMethod> readAllowedMethods(AnnotatedElement element) {
-        List<HttpMethod> allowedMethods = Collections.emptyList();
+        List<HttpMethod> allowedMethods = new ArrayList<HttpMethod>();
         if (AnnotationUtils.isAnnotatedBy(element, AllowedHttpMethod.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(AllowedHttpMethod.class).value());
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(AllowedHttpMethod.class).value()));
         }
         if (AnnotationUtils.isAnnotatedBy(element, HttpGet.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(HttpGet.class).value());
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(HttpGet.class).value()));
         }
         if (AnnotationUtils.isAnnotatedBy(element, HttpPost.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(HttpPost.class).value());
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(HttpPost.class).value()));
+        }
+        if (AnnotationUtils.isAnnotatedBy(element, HttpPut.class)) {
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(HttpPut.class).value()));
+        }
+        if (AnnotationUtils.isAnnotatedBy(element, HttpDelete.class)) {
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(HttpDelete.class).value()));
         }
         if (AnnotationUtils.isAnnotatedBy(element, HttpGetOrPost.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(HttpGetOrPost.class).value());
+            allowedMethods.addAll(Arrays.asList(element.getAnnotation(HttpGetOrPost.class).value()));
         }
         return Collections.unmodifiableList(allowedMethods);
     }
diff --git a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
index ba93d7df3..067213a0c 100644
--- a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
+++ b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
@@ -2,11 +2,13 @@ package org.apache.struts2;
 
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.interceptor.httpmethod.AllowedHttpMethod;
+import org.apache.struts2.interceptor.httpmethod.HttpDelete;
 import org.apache.struts2.interceptor.httpmethod.HttpGet;
 import org.apache.struts2.interceptor.httpmethod.HttpGetOrPost;
 import org.apache.struts2.interceptor.httpmethod.HttpMethod;
 import org.apache.struts2.interceptor.httpmethod.HttpMethodAware;
 import org.apache.struts2.interceptor.httpmethod.HttpPost;
+import org.apache.struts2.interceptor.httpmethod.HttpPut;
 
 import static org.apache.struts2.interceptor.httpmethod.HttpMethod.POST;
 
@@ -37,6 +39,16 @@ public class HttpMethodsTestAction extends ActionSupport implements HttpMethodAw
         return "onGetPostOnly";
     }
 
+    @HttpPut @HttpPost
+    public String onPutOrPost() {
+        return "onPutOrPost";
+    }
+
+    @HttpDelete
+    public String onDelete() {
+        return "onDelete";
+    }
+
     public void setMethod(HttpMethod httpMethod) {
 
     }
diff --git a/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java
index 34303ea9b..3445c4de4 100644
--- a/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java
+++ b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java
@@ -183,4 +183,73 @@ public class HttpMethodInterceptorTest extends StrutsInternalTestCase {
         assertEquals("onGetPostOnly", resultName);
     }
 
+    public void testDeleteOnMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onDelete");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onDelete");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("DELETE", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onDelete", resultName);
+    }
+
+    public void testPutOnPutOrPostMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onPutOrPost");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onPutOrPost");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("PUT", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onPutOrPost", resultName);
+    }
+
+    public void testPostOnPutOrPostMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onPutOrPost");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onPutOrPost");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onPutOrPost", resultName);
+    }
+
 }


[struts] 15/15: Updates JavaDocs

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 650d33c81b2223f4dd0c452669f97905516b5230
Author: Lukasz Lenart <lu...@gmail.com>
AuthorDate: Sun Sep 21 22:16:09 2014 +0200

    Updates JavaDocs
---
 .../struts2/interceptor/httpmethod/AllowedHttpMethod.java      |  2 +-
 .../org/apache/struts2/interceptor/httpmethod/HttpDelete.java  |  2 +-
 .../org/apache/struts2/interceptor/httpmethod/HttpGet.java     |  2 +-
 .../apache/struts2/interceptor/httpmethod/HttpGetOrPost.java   |  2 +-
 .../org/apache/struts2/interceptor/httpmethod/HttpMethod.java  |  2 +-
 .../apache/struts2/interceptor/httpmethod/HttpMethodAware.java |  6 +++---
 .../struts2/interceptor/httpmethod/HttpMethodInterceptor.java  | 10 +++++++---
 .../org/apache/struts2/interceptor/httpmethod/HttpPost.java    |  2 +-
 .../org/apache/struts2/interceptor/httpmethod/HttpPut.java     |  2 +-
 9 files changed, 17 insertions(+), 13 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
index 7438c457c..185932086 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to limit with what http method action or action's method can be called
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java
index 19ac1ea49..51dee4024 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to allow call action or action's method via DELETE request only
  *
  * @see org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
index 893bee1d2..fa93bcfcc 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to allow call action or action's method via GET request only
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
index f831fcb29..1f2c221a8 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to allow call action or action's method via GET or POST request only
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
index e1437f4bd..0467ffc4f 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
@@ -4,7 +4,7 @@ package org.apache.struts2.interceptor.httpmethod;
  * Enum represents possible http request types
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 public enum HttpMethod {
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
index d6561f7ac..757ead20d 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
@@ -2,13 +2,13 @@ package org.apache.struts2.interceptor.httpmethod;
 
 /**
  * Action when implements this interface is notified about what method was used to perform request,
- * it works in connection with {@link org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor}
+ * it works in connection with {@link HttpMethodInterceptor}
  *
  * Another function of this interface is to return result which should be returned when action
  * was called with wrong http method
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 public interface HttpMethodAware {
 
@@ -22,7 +22,7 @@ public interface HttpMethodAware {
     /**
      * Action name to use when action was requested with wrong http method
      * can return null and then default result name will be used instead defined
-     * in {@link org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor}
+     * in {@link HttpMethodInterceptor}
      *
      * @return result name or null
      */
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index 300e203f2..ba2619315 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -23,16 +23,20 @@ import java.util.List;
  * thus value will be used instead.
  * <p/>
  * To limit allowed http methods, annotate action class with {@link AllowedHttpMethod} and specify
- * which methods are allowed. You can also use shorter versions {@link HttpGet}, {@link HttpPost}
- * and {@link HttpGetOrPost}
+ * which methods are allowed. You can also use shorter versions {@link HttpGet}, {@link HttpPost},
+ * {@link HttpPut}, {@link HttpDelete} and {@link HttpGetOrPost}
+ *
+ * You can combine any of these annotations to achieve required allowed methods' filtering.
  *
  * @see HttpMethodAware
  * @see HttpMethod
  * @see AllowedHttpMethod
  * @see HttpGet
  * @see HttpPost
+ * @see HttpPut
+ * @see HttpDelete
  * @see HttpGetOrPost
- * @since 2.3.18
+ * @since 2.5
  */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
index 7c9ff4a0e..8dcd9260d 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to allow call action or action's method via POST request only
  *
  * @see HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java
index 735b9e128..031217f0b 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java
@@ -9,7 +9,7 @@ import java.lang.annotation.Target;
  * Use this annotation to allow call action or action's method via PUT request only
  *
  * @see org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor
- * @since 2.3.18
+ * @since 2.5
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)


[struts] 06/15: Adds support for annotations on methods

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 7fa5133b1df1cee6d5a0061a59e14876facc2582
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 21:51:01 2014 +0200

    Adds support for annotations on methods
---
 .../httpmethod/HttpMethodInterceptor.java          | 50 +++++++++++++---------
 1 file changed, 30 insertions(+), 20 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index e22e6a771..1a57af426 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -8,6 +8,8 @@ import com.opensymphony.xwork2.util.logging.LoggerFactory;
 import org.apache.struts2.ServletActionContext;
 
 import javax.servlet.http.HttpServletRequest;
+import java.lang.reflect.AnnotatedElement;
+import java.lang.reflect.Method;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
@@ -18,7 +20,7 @@ import java.util.List;
  * will be returned or if action implements {@link HttpMethodAware}
  * and {@link HttpMethodAware#getBadRequestResultName()} returns non-null result name,
  * thus value will be used instead.
- *
+ * <p/>
  * To limit allowed http methods, annotate action class with {@link AllowedMethod} and specify
  * which methods are allowed. You can also use shorter versions {@link GetOnly}, {@link PostOnly}
  * and {@link GetPostOnly}
@@ -29,12 +31,11 @@ import java.util.List;
  * @see GetOnly
  * @see PostOnly
  * @see GetPostOnly
- *
  * @since 2.3.18
  */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
-    public static final Class[] HTTP_METHOD_ANNOTATIONS = { AllowedMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class };
+    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class};
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpMethodInterceptor.class);
 
@@ -49,48 +50,57 @@ public class HttpMethodInterceptor extends AbstractInterceptor {
                 LOG.debug("Action #0 implements #1, setting request method #3",
                         action, HttpMethodAware.class.getSimpleName(), request.getMethod());
             }
-            ((HttpMethodAware) (action)).setMethod(HttpMethod.valueOf(request.getMethod()));
+            ((HttpMethodAware) (action)).setMethod(HttpMethod.parse(request.getMethod()));
         }
-        if (AnnotationUtils.isAnnotatedBy(action.getClass(), HTTP_METHOD_ANNOTATIONS)) {
+        if (invocation.getProxy().isMethodSpecified()) {
+            Method method = action.getClass().getMethod(invocation.getProxy().getMethod(), new Class[0]);
+            if (AnnotationUtils.isAnnotatedBy(method, HTTP_METHOD_ANNOTATIONS)) {
+                if (LOG.isDebugEnabled()) {
+                    LOG.debug("Action's method #0 annotated with #1, checking if request #2 meets allowed methods!",
+                            invocation.getProxy().getMethod(), AllowedMethod.class.getSimpleName(), request.getMethod());
+                }
+                return doIntercept(invocation, method);
+            }
+        } else if (AnnotationUtils.isAnnotatedBy(action.getClass(), HTTP_METHOD_ANNOTATIONS)) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Action #0 annotated with #1, checking if request #2 meets allowed methods!",
                         action, AllowedMethod.class.getSimpleName(), request.getMethod());
             }
-            return doIntercept(invocation);
+            return doIntercept(invocation, action.getClass());
         }
         return invocation.invoke();
     }
 
-    protected String doIntercept(ActionInvocation invocation) throws Exception {
-        List<HttpMethod> allowedMethods = readAllowedMethods(invocation.getAction().getClass());
+    protected String doIntercept(ActionInvocation invocation, AnnotatedElement element) throws Exception {
+        List<HttpMethod> allowedMethods = readAllowedMethods(element);
         HttpServletRequest request = ServletActionContext.getRequest();
-        HttpMethod requestedMethod = HttpMethod.valueOf(request.getMethod());
+        HttpMethod requestedMethod = HttpMethod.parse(request.getMethod());
         if (allowedMethods.contains(requestedMethod)) {
-            if(LOG.isTraceEnabled()) {
+            if (LOG.isTraceEnabled()) {
                 LOG.trace("Request method #0 matches allowed methods #1, continuing invocation!", requestedMethod, allowedMethods);
             }
             return invocation.invoke();
         } else {
-            if(LOG.isTraceEnabled()) {
+            if (LOG.isTraceEnabled()) {
                 LOG.trace("Request method #0 doesn't match allowed methods #1, continuing invocation!", requestedMethod, allowedMethods);
             }
             return getBadRequestResultName(invocation);
         }
     }
 
-    protected List<HttpMethod> readAllowedMethods(Class<? extends Object> klass) {
+    protected List<HttpMethod> readAllowedMethods(AnnotatedElement element) {
         List<HttpMethod> allowedMethods = Collections.emptyList();
-        if (AnnotationUtils.isAnnotatedBy(klass, AllowedMethod.class)) {
-            allowedMethods = Arrays.asList(klass.getAnnotation(AllowedMethod.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, AllowedMethod.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(AllowedMethod.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(klass, GetOnly.class)) {
-            allowedMethods = Arrays.asList(klass.getAnnotation(GetOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, GetOnly.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(GetOnly.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(klass, PostOnly.class)) {
-            allowedMethods = Arrays.asList(klass.getAnnotation(PostOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, PostOnly.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(PostOnly.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(klass, GetPostOnly.class)) {
-            allowedMethods = Arrays.asList(klass.getAnnotation(GetPostOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, GetPostOnly.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(GetPostOnly.class).value());
         }
         return Collections.unmodifiableList(allowedMethods);
     }


[struts] 13/15: Defines another annotation shortcuts

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit f48a4c60ed71518297af41a9e01ec9911685c549
Author: Lukasz Lenart <lu...@gmail.com>
AuthorDate: Sun Sep 21 21:57:31 2014 +0200

    Defines another annotation shortcuts
---
 .../struts2/interceptor/httpmethod/HttpDelete.java   | 20 ++++++++++++++++++++
 .../struts2/interceptor/httpmethod/HttpPut.java      | 20 ++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java
new file mode 100644
index 000000000..19ac1ea49
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpDelete.java
@@ -0,0 +1,20 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Use this annotation to allow call action or action's method via DELETE request only
+ *
+ * @see org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor
+ * @since 2.3.18
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HttpDelete {
+
+    HttpMethod[] value() default { HttpMethod.DELETE };
+
+}
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java
new file mode 100644
index 000000000..735b9e128
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPut.java
@@ -0,0 +1,20 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Use this annotation to allow call action or action's method via PUT request only
+ *
+ * @see org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor
+ * @since 2.3.18
+ */
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface HttpPut {
+
+    HttpMethod[] value() default { HttpMethod.PUT };
+
+}


[struts] 04/15: Adds new interface to allow action cooperate with HttpMethodInterceptor

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 68ded66f82aa0d1af9ba3b00abe9de782480fc9e
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 18:05:58 2014 +0200

    Adds new interface to allow action cooperate with HttpMethodInterceptor
---
 .../interceptor/httpmethod/HttpMethodAware.java    | 30 ++++++++++++++++++++++
 1 file changed, 30 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
new file mode 100644
index 000000000..cfdc7826c
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
@@ -0,0 +1,30 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+/**
+ * Action when implements this interface is notified about what method was used to perform request,
+ * it works in connection with {@link org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor}
+ *
+ * Another function of this interface is to return result which should be returned when action
+ * was called with wrong http method
+ *
+ * @since 2.3.18
+ */
+public interface HttpMethodAware {
+
+    /**
+     * Notifies action about http method used to perform request
+     *
+     * @param httpMethod {@link javax.servlet.http.HttpServletRequest#getMethod()} translated to enum
+     */
+    public void setMethod(HttpMethod httpMethod);
+
+    /**
+     * Action name to use when action was requested with wrong http method
+     * can return null and then default result name will be used instead defined
+     * in {@link org.apache.struts2.interceptor.httpmethod.HttpMethodInterceptor}
+     *
+     * @return result name or null
+     */
+    public String getBadRequestResultName();
+
+}


[struts] 12/15: Adjusts better formatting

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit a576d628d3455c014be49f885aeb969eaadfa161
Author: Lukasz Lenart <lu...@gmail.com>
AuthorDate: Sun Sep 21 21:53:19 2014 +0200

    Adjusts better formatting
---
 .../struts2/interceptor/httpmethod/HttpMethodInterceptor.java      | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index 706046061..668f39ce0 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -35,7 +35,12 @@ import java.util.List;
  */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
-    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedHttpMethod.class, HttpPost.class, HttpGet.class, HttpGetOrPost.class};
+    public static final Class[] HTTP_METHOD_ANNOTATIONS = {
+            AllowedHttpMethod.class,
+            HttpPost.class,
+            HttpGet.class,
+            HttpGetOrPost.class
+    };
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpMethodInterceptor.class);
 


[struts] 07/15: Adds test cases

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 8ea9e992078e1a53ad5e93b11e161eb622e6175f
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 21:51:10 2014 +0200

    Adds test cases
---
 .../org/apache/struts2/HttpMethodsTestAction.java  |  47 ++++++
 .../httpmethod/HttpMethodInterceptorTest.java      | 186 +++++++++++++++++++++
 .../interceptor/httpmethod/HttpMethodTest.java     |  35 ++++
 3 files changed, 268 insertions(+)

diff --git a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
new file mode 100644
index 000000000..79dd16e54
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
@@ -0,0 +1,47 @@
+package org.apache.struts2;
+
+import com.opensymphony.xwork2.ActionSupport;
+import org.apache.struts2.interceptor.httpmethod.AllowedMethod;
+import org.apache.struts2.interceptor.httpmethod.GetOnly;
+import org.apache.struts2.interceptor.httpmethod.GetPostOnly;
+import org.apache.struts2.interceptor.httpmethod.HttpMethod;
+import org.apache.struts2.interceptor.httpmethod.HttpMethodAware;
+import org.apache.struts2.interceptor.httpmethod.PostOnly;
+
+import static org.apache.struts2.interceptor.httpmethod.HttpMethod.POST;
+
+@AllowedMethod(POST)
+public class HttpMethodsTestAction extends ActionSupport implements HttpMethodAware {
+
+    private String resultName = null;
+
+    public HttpMethodsTestAction() {
+    }
+
+    public HttpMethodsTestAction(String resultName) {
+        this.resultName = resultName;
+    }
+
+    @GetOnly
+    public String onGetOnly() {
+        return "onGetOnly";
+    }
+
+    @PostOnly
+    public String onPostOnly() {
+        return "onPostOnly";
+    }
+
+    @GetPostOnly
+    public String onGetPostOnly() {
+        return "onGetPostOnly";
+    }
+
+    public void setMethod(HttpMethod httpMethod) {
+
+    }
+
+    public String getBadRequestResultName() {
+        return resultName;
+    }
+}
diff --git a/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java
new file mode 100644
index 000000000..34303ea9b
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptorTest.java
@@ -0,0 +1,186 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import org.apache.struts2.HttpMethodsTestAction;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsInternalTestCase;
+import org.apache.struts2.TestAction;
+import org.springframework.mock.web.MockHttpServletRequest;
+
+public class HttpMethodInterceptorTest extends StrutsInternalTestCase {
+
+    public void testNotAnnotatedAction() throws Exception {
+        // given
+        TestAction action = new TestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        invocation.setProxy(new MockActionProxy());
+
+        invocation.setResultCode("success");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("post", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("success", resultName);
+    }
+
+    public void testActionWithPostAllowed() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        invocation.setProxy(new MockActionProxy());
+
+        invocation.setResultCode("success");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("post", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("success", resultName);
+    }
+
+    public void testGetIsNotAllowed() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        invocation.setProxy(new MockActionProxy());
+
+        invocation.setResultCode("success");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("get", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("bad-request", resultName);
+    }
+
+    public void testGetIsNotAllowedWithCustomResultName() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        interceptor.setBadRequestResultName("custom-bad-request");
+
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        invocation.setProxy(new MockActionProxy());
+
+        invocation.setResultCode("success");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("get", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("custom-bad-request", resultName);
+    }
+
+    public void testGetIsNotAllowedWithActionDefinedResultName() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction("action-bad-request");
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        interceptor.setBadRequestResultName("custom-bad-request");
+
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        invocation.setProxy(new MockActionProxy());
+
+        invocation.setResultCode("success");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("get", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("action-bad-request", resultName);
+    }
+
+    public void testGetOnlyOnMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onGetOnly");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onGetOnly");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("get", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onGetOnly", resultName);
+    }
+
+    public void testPostOnlyOnMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onPostOnly");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onPostOnly");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("post", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onPostOnly", resultName);
+    }
+
+    public void testGetPostOnlyOnMethod() throws Exception {
+        // given
+        HttpMethodsTestAction action = new HttpMethodsTestAction();
+        HttpMethodInterceptor interceptor = new HttpMethodInterceptor();
+        MockActionInvocation invocation = new MockActionInvocation();
+        invocation.setAction(action);
+        MockActionProxy proxy = new MockActionProxy();
+        proxy.setMethod("onGetPostOnly");
+        proxy.setMethodSpecified(true);
+        invocation.setProxy(proxy);
+
+        invocation.setResultCode("onGetPostOnly");
+
+        MockHttpServletRequest request = new MockHttpServletRequest("post", "/action");
+        ServletActionContext.setRequest(request);
+
+        // when
+        String resultName = interceptor.intercept(invocation);
+
+        // then
+        assertEquals("onGetPostOnly", resultName);
+    }
+
+}
diff --git a/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodTest.java b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodTest.java
new file mode 100644
index 000000000..4de4a409f
--- /dev/null
+++ b/core/src/test/java/org/apache/struts2/interceptor/httpmethod/HttpMethodTest.java
@@ -0,0 +1,35 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import junit.framework.TestCase;
+
+public class HttpMethodTest extends TestCase {
+
+    public void testConvertHttpRequestMethod() throws Exception {
+        // given
+        String httpRequestMethod = "post";
+
+        // when
+        HttpMethod httpMethod = HttpMethod.parse(httpRequestMethod);
+
+        // then
+        assertEquals(HttpMethod.POST, httpMethod);
+    }
+
+    public void testValueOfThrowsException() throws Exception {
+        // given
+        String httpRequestMethod = "post";
+
+        // when
+        IllegalArgumentException expected = null;
+        try {
+            HttpMethod.valueOf(httpRequestMethod);
+        } catch (IllegalArgumentException e) {
+            expected = e;
+        }
+
+        // then
+        assertNotNull(expected);
+        assertEquals(expected.getClass(), IllegalArgumentException.class);
+    }
+
+}


[struts] 09/15: Renames basic annotation to better express its meaning

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 2bc0158dfb0108649128cc43885a1f6e93aa1236
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Apr 20 22:35:01 2014 +0200

    Renames basic annotation to better express its meaning
---
 .../{AllowedMethod.java => AllowedHttpMethod.java}         |  2 +-
 .../interceptor/httpmethod/HttpMethodInterceptor.java      | 14 +++++++-------
 .../java/org/apache/struts2/HttpMethodsTestAction.java     |  4 ++--
 3 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
similarity index 92%
rename from core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
rename to core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
index 435e60e9a..7438c457c 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedHttpMethod.java
@@ -13,7 +13,7 @@ import java.lang.annotation.Target;
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
-public @interface AllowedMethod {
+public @interface AllowedHttpMethod {
 
     HttpMethod[] value() default {};
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index 1a57af426..ac64050cc 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -21,13 +21,13 @@ import java.util.List;
  * and {@link HttpMethodAware#getBadRequestResultName()} returns non-null result name,
  * thus value will be used instead.
  * <p/>
- * To limit allowed http methods, annotate action class with {@link AllowedMethod} and specify
+ * To limit allowed http methods, annotate action class with {@link AllowedHttpMethod} and specify
  * which methods are allowed. You can also use shorter versions {@link GetOnly}, {@link PostOnly}
  * and {@link GetPostOnly}
  *
  * @see HttpMethodAware
  * @see HttpMethod
- * @see AllowedMethod
+ * @see AllowedHttpMethod
  * @see GetOnly
  * @see PostOnly
  * @see GetPostOnly
@@ -35,7 +35,7 @@ import java.util.List;
  */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
-    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class};
+    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedHttpMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class};
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpMethodInterceptor.class);
 
@@ -57,14 +57,14 @@ public class HttpMethodInterceptor extends AbstractInterceptor {
             if (AnnotationUtils.isAnnotatedBy(method, HTTP_METHOD_ANNOTATIONS)) {
                 if (LOG.isDebugEnabled()) {
                     LOG.debug("Action's method #0 annotated with #1, checking if request #2 meets allowed methods!",
-                            invocation.getProxy().getMethod(), AllowedMethod.class.getSimpleName(), request.getMethod());
+                            invocation.getProxy().getMethod(), AllowedHttpMethod.class.getSimpleName(), request.getMethod());
                 }
                 return doIntercept(invocation, method);
             }
         } else if (AnnotationUtils.isAnnotatedBy(action.getClass(), HTTP_METHOD_ANNOTATIONS)) {
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Action #0 annotated with #1, checking if request #2 meets allowed methods!",
-                        action, AllowedMethod.class.getSimpleName(), request.getMethod());
+                        action, AllowedHttpMethod.class.getSimpleName(), request.getMethod());
             }
             return doIntercept(invocation, action.getClass());
         }
@@ -90,8 +90,8 @@ public class HttpMethodInterceptor extends AbstractInterceptor {
 
     protected List<HttpMethod> readAllowedMethods(AnnotatedElement element) {
         List<HttpMethod> allowedMethods = Collections.emptyList();
-        if (AnnotationUtils.isAnnotatedBy(element, AllowedMethod.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(AllowedMethod.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, AllowedHttpMethod.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(AllowedHttpMethod.class).value());
         }
         if (AnnotationUtils.isAnnotatedBy(element, GetOnly.class)) {
             allowedMethods = Arrays.asList(element.getAnnotation(GetOnly.class).value());
diff --git a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
index 79dd16e54..c67ec39c0 100644
--- a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
+++ b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
@@ -1,7 +1,7 @@
 package org.apache.struts2;
 
 import com.opensymphony.xwork2.ActionSupport;
-import org.apache.struts2.interceptor.httpmethod.AllowedMethod;
+import org.apache.struts2.interceptor.httpmethod.AllowedHttpMethod;
 import org.apache.struts2.interceptor.httpmethod.GetOnly;
 import org.apache.struts2.interceptor.httpmethod.GetPostOnly;
 import org.apache.struts2.interceptor.httpmethod.HttpMethod;
@@ -10,7 +10,7 @@ import org.apache.struts2.interceptor.httpmethod.PostOnly;
 
 import static org.apache.struts2.interceptor.httpmethod.HttpMethod.POST;
 
-@AllowedMethod(POST)
+@AllowedHttpMethod(POST)
 public class HttpMethodsTestAction extends ActionSupport implements HttpMethodAware {
 
     private String resultName = null;


[struts] 03/15: Adds new http interceptor to allow block access based on method type

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 80c7005bea37c5f62a68c4e5678cab2c2b9c67f5
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 17:50:32 2014 +0200

    Adds new http interceptor to allow block access based on method type
---
 .../httpmethod/HttpMethodInterceptor.java          | 97 ++++++++++++++++++++++
 1 file changed, 97 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
new file mode 100644
index 000000000..36efb5266
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -0,0 +1,97 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
+import com.opensymphony.xwork2.util.AnnotationUtils;
+import com.opensymphony.xwork2.util.logging.Logger;
+import com.opensymphony.xwork2.util.logging.LoggerFactory;
+import org.apache.struts2.ServletActionContext;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+public class HttpMethodInterceptor extends AbstractInterceptor {
+
+    public static final Class[] HTTP_METHOD_ANNOTATIONS = { AllowedMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class };
+
+    private static final Logger LOG = LoggerFactory.getLogger(HttpMethodInterceptor.class);
+
+    private String badRequestResultName = "bad-request";
+
+    @Override
+    public String intercept(ActionInvocation invocation) throws Exception {
+        Object action = invocation.getAction();
+        HttpServletRequest request = ServletActionContext.getRequest();
+        if (action instanceof HttpMethodAware) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Action #0 implements #1, setting request method #3",
+                        action, HttpMethodAware.class.getSimpleName(), request.getMethod());
+            }
+            ((HttpMethodAware) (action)).setMethod(HttpMethod.valueOf(request.getMethod()));
+        }
+        if (AnnotationUtils.isAnnotatedBy(action.getClass(), HTTP_METHOD_ANNOTATIONS)) {
+            if (LOG.isDebugEnabled()) {
+                LOG.debug("Action #0 annotated with #1, checking if request #2 meets allowed methods!",
+                        action, AllowedMethod.class.getSimpleName(), request.getMethod());
+            }
+            return doIntercept(invocation);
+        }
+        return invocation.invoke();
+    }
+
+    protected String doIntercept(ActionInvocation invocation) throws Exception {
+        List<HttpMethod> allowedMethods = readAllowedMethods(invocation.getAction().getClass());
+        HttpServletRequest request = ServletActionContext.getRequest();
+        HttpMethod requestedMethod = HttpMethod.valueOf(request.getMethod());
+        if (allowedMethods.contains(requestedMethod)) {
+            if(LOG.isTraceEnabled()) {
+                LOG.trace("Request method #0 matches allowed methods #1, continuing invocation!", requestedMethod, allowedMethods);
+            }
+            return invocation.invoke();
+        } else {
+            if(LOG.isTraceEnabled()) {
+                LOG.trace("Request method #0 doesn't match allowed methods #1, continuing invocation!", requestedMethod, allowedMethods);
+            }
+            return getBadRequestResultName(invocation);
+        }
+    }
+
+    protected List<HttpMethod> readAllowedMethods(Class<? extends Object> klass) {
+        List<HttpMethod> allowedMethods = Collections.emptyList();
+        if (AnnotationUtils.isAnnotatedBy(klass, AllowedMethod.class)) {
+            allowedMethods = Arrays.asList(klass.getAnnotation(AllowedMethod.class).value());
+        }
+        if (AnnotationUtils.isAnnotatedBy(klass, GetOnly.class)) {
+            allowedMethods = Arrays.asList(klass.getAnnotation(GetOnly.class).value());
+        }
+        if (AnnotationUtils.isAnnotatedBy(klass, PostOnly.class)) {
+            allowedMethods = Arrays.asList(klass.getAnnotation(PostOnly.class).value());
+        }
+        if (AnnotationUtils.isAnnotatedBy(klass, GetPostOnly.class)) {
+            allowedMethods = Arrays.asList(klass.getAnnotation(GetPostOnly.class).value());
+        }
+        return Collections.unmodifiableList(allowedMethods);
+    }
+
+    protected String getBadRequestResultName(ActionInvocation invocation) {
+        Object action = invocation.getAction();
+        String resultName = badRequestResultName;
+        if (action instanceof HttpMethodAware) {
+            String actionResultName = ((HttpMethodAware) action).getBadRequestResultName();
+            if (actionResultName != null) {
+                resultName = actionResultName;
+            }
+        }
+        if (LOG.isTraceEnabled()) {
+            LOG.trace("Bad request result name is #0", resultName);
+        }
+        return resultName;
+    }
+
+    public void setBadRequestResultName(String badRequestResultName) {
+        this.badRequestResultName = badRequestResultName;
+    }
+
+}


[struts] 02/15: Defines annotations to control access based on http method Defines main annotation AllowedMethod and helper annotations used in most common situation, eg. GetOnly, PostOnly, etc.

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit b3ff475e1cf5ef07edeb6322d300c74b32b0a15f
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 17:49:50 2014 +0200

    Defines annotations to control access based on http method
    Defines main annotation AllowedMethod and helper annotations used in
    most common situation, eg. GetOnly, PostOnly, etc.
---
 .../struts2/interceptor/httpmethod/AllowedMethod.java      | 14 ++++++++++++++
 .../org/apache/struts2/interceptor/httpmethod/GetOnly.java | 14 ++++++++++++++
 .../apache/struts2/interceptor/httpmethod/GetPostOnly.java | 14 ++++++++++++++
 .../apache/struts2/interceptor/httpmethod/PostOnly.java    | 14 ++++++++++++++
 4 files changed, 56 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
new file mode 100644
index 000000000..05d3795f9
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
@@ -0,0 +1,14 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface AllowedMethod {
+
+    HttpMethod[] value() default {};
+
+}
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
new file mode 100644
index 000000000..2c782bd5c
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
@@ -0,0 +1,14 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface GetOnly {
+
+    HttpMethod[] value() default { HttpMethod.GET };
+
+}
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
new file mode 100644
index 000000000..9f8df0230
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
@@ -0,0 +1,14 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface GetPostOnly {
+
+    HttpMethod[] value() default { HttpMethod.GET, HttpMethod.POST };
+
+}
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
new file mode 100644
index 000000000..1163188f1
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
@@ -0,0 +1,14 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+@Target({ElementType.METHOD, ElementType.TYPE})
+@Retention(RetentionPolicy.RUNTIME)
+public @interface PostOnly {
+
+    HttpMethod[] value() default { HttpMethod.POST };
+
+}


[struts] 01/15: Defined enum with all http methods

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit da57a04025e009e8036e5e7e068971e49d9df545
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 17:46:59 2014 +0200

    Defined enum with all http methods
---
 .../struts2/interceptor/httpmethod/HttpMethod.java    | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
new file mode 100644
index 000000000..30f4ea3d6
--- /dev/null
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
@@ -0,0 +1,19 @@
+package org.apache.struts2.interceptor.httpmethod;
+
+public enum HttpMethod {
+
+    GET,
+    HEAD,
+    POST,
+    PUT,
+    DELETE,
+    TRACE,
+    OPTIONS,
+    CONNECT,
+    PATCH;
+
+    public static HttpMethod parse(String httpRequestMethod) {
+        return valueOf(httpRequestMethod.toUpperCase());
+    }
+
+}


[struts] 11/15: Renames annotation to have more explicit meaning

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 33f63cee3cf2dbf2dffc3cfae96687ed707eef1f
Author: Lukasz Lenart <lu...@gmail.com>
AuthorDate: Sun Sep 21 21:52:54 2014 +0200

    Renames annotation to have more explicit meaning
---
 .../httpmethod/{GetOnly.java => HttpGet.java}      |  2 +-
 .../{GetPostOnly.java => HttpGetOrPost.java}       |  2 +-
 .../httpmethod/HttpMethodInterceptor.java          | 24 +++++++++++-----------
 .../httpmethod/{PostOnly.java => HttpPost.java}    |  2 +-
 .../org/apache/struts2/HttpMethodsTestAction.java  | 12 +++++------
 5 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
similarity index 94%
rename from core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
rename to core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
index 6cf2dc6d4..893bee1d2 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGet.java
@@ -13,7 +13,7 @@ import java.lang.annotation.Target;
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
-public @interface GetOnly {
+public @interface HttpGet {
 
     HttpMethod[] value() default { HttpMethod.GET };
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
similarity index 93%
rename from core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
rename to core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
index 0668784b5..f831fcb29 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpGetOrPost.java
@@ -13,7 +13,7 @@ import java.lang.annotation.Target;
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
-public @interface GetPostOnly {
+public @interface HttpGetOrPost {
 
     HttpMethod[] value() default { HttpMethod.GET, HttpMethod.POST };
 
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index ac64050cc..706046061 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -22,20 +22,20 @@ import java.util.List;
  * thus value will be used instead.
  * <p/>
  * To limit allowed http methods, annotate action class with {@link AllowedHttpMethod} and specify
- * which methods are allowed. You can also use shorter versions {@link GetOnly}, {@link PostOnly}
- * and {@link GetPostOnly}
+ * which methods are allowed. You can also use shorter versions {@link HttpGet}, {@link HttpPost}
+ * and {@link HttpGetOrPost}
  *
  * @see HttpMethodAware
  * @see HttpMethod
  * @see AllowedHttpMethod
- * @see GetOnly
- * @see PostOnly
- * @see GetPostOnly
+ * @see HttpGet
+ * @see HttpPost
+ * @see HttpGetOrPost
  * @since 2.3.18
  */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
-    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedHttpMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class};
+    public static final Class[] HTTP_METHOD_ANNOTATIONS = {AllowedHttpMethod.class, HttpPost.class, HttpGet.class, HttpGetOrPost.class};
 
     private static final Logger LOG = LoggerFactory.getLogger(HttpMethodInterceptor.class);
 
@@ -93,14 +93,14 @@ public class HttpMethodInterceptor extends AbstractInterceptor {
         if (AnnotationUtils.isAnnotatedBy(element, AllowedHttpMethod.class)) {
             allowedMethods = Arrays.asList(element.getAnnotation(AllowedHttpMethod.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(element, GetOnly.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(GetOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, HttpGet.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(HttpGet.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(element, PostOnly.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(PostOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, HttpPost.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(HttpPost.class).value());
         }
-        if (AnnotationUtils.isAnnotatedBy(element, GetPostOnly.class)) {
-            allowedMethods = Arrays.asList(element.getAnnotation(GetPostOnly.class).value());
+        if (AnnotationUtils.isAnnotatedBy(element, HttpGetOrPost.class)) {
+            allowedMethods = Arrays.asList(element.getAnnotation(HttpGetOrPost.class).value());
         }
         return Collections.unmodifiableList(allowedMethods);
     }
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
similarity index 94%
rename from core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
rename to core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
index 0f3bcd537..7c9ff4a0e 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpPost.java
@@ -13,7 +13,7 @@ import java.lang.annotation.Target;
  */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
-public @interface PostOnly {
+public @interface HttpPost {
 
     HttpMethod[] value() default { HttpMethod.POST };
 
diff --git a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
index c67ec39c0..ba93d7df3 100644
--- a/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
+++ b/core/src/test/java/org/apache/struts2/HttpMethodsTestAction.java
@@ -2,11 +2,11 @@ package org.apache.struts2;
 
 import com.opensymphony.xwork2.ActionSupport;
 import org.apache.struts2.interceptor.httpmethod.AllowedHttpMethod;
-import org.apache.struts2.interceptor.httpmethod.GetOnly;
-import org.apache.struts2.interceptor.httpmethod.GetPostOnly;
+import org.apache.struts2.interceptor.httpmethod.HttpGet;
+import org.apache.struts2.interceptor.httpmethod.HttpGetOrPost;
 import org.apache.struts2.interceptor.httpmethod.HttpMethod;
 import org.apache.struts2.interceptor.httpmethod.HttpMethodAware;
-import org.apache.struts2.interceptor.httpmethod.PostOnly;
+import org.apache.struts2.interceptor.httpmethod.HttpPost;
 
 import static org.apache.struts2.interceptor.httpmethod.HttpMethod.POST;
 
@@ -22,17 +22,17 @@ public class HttpMethodsTestAction extends ActionSupport implements HttpMethodAw
         this.resultName = resultName;
     }
 
-    @GetOnly
+    @HttpGet
     public String onGetOnly() {
         return "onGetOnly";
     }
 
-    @PostOnly
+    @HttpPost
     public String onPostOnly() {
         return "onPostOnly";
     }
 
-    @GetPostOnly
+    @HttpGetOrPost
     public String onGetPostOnly() {
         return "onGetPostOnly";
     }


[struts] 08/15: Updates JavaDocs in annotations

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit e6f4cc5dafa82fa5e19338e0daaa9b4b6aa1b9e0
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sun Apr 20 22:13:58 2014 +0200

    Updates JavaDocs in annotations
---
 .../org/apache/struts2/interceptor/httpmethod/AllowedMethod.java    | 6 ++++++
 .../java/org/apache/struts2/interceptor/httpmethod/GetOnly.java     | 6 ++++++
 .../java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java | 6 ++++++
 .../java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java  | 6 ++++++
 .../org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java  | 1 +
 .../java/org/apache/struts2/interceptor/httpmethod/PostOnly.java    | 6 ++++++
 6 files changed, 31 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
index 05d3795f9..435e60e9a 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/AllowedMethod.java
@@ -5,6 +5,12 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Use this annotation to limit with what http method action or action's method can be called
+ *
+ * @see HttpMethodInterceptor
+ * @since 2.3.18
+ */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface AllowedMethod {
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
index 2c782bd5c..6cf2dc6d4 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetOnly.java
@@ -5,6 +5,12 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Use this annotation to allow call action or action's method via GET request only
+ *
+ * @see HttpMethodInterceptor
+ * @since 2.3.18
+ */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface GetOnly {
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
index 9f8df0230..0668784b5 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/GetPostOnly.java
@@ -5,6 +5,12 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Use this annotation to allow call action or action's method via GET or POST request only
+ *
+ * @see HttpMethodInterceptor
+ * @since 2.3.18
+ */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface GetPostOnly {
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
index 30f4ea3d6..e1437f4bd 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethod.java
@@ -1,5 +1,11 @@
 package org.apache.struts2.interceptor.httpmethod;
 
+/**
+ * Enum represents possible http request types
+ *
+ * @see HttpMethodInterceptor
+ * @since 2.3.18
+ */
 public enum HttpMethod {
 
     GET,
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
index cfdc7826c..d6561f7ac 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodAware.java
@@ -7,6 +7,7 @@ package org.apache.struts2.interceptor.httpmethod;
  * Another function of this interface is to return result which should be returned when action
  * was called with wrong http method
  *
+ * @see HttpMethodInterceptor
  * @since 2.3.18
  */
 public interface HttpMethodAware {
diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
index 1163188f1..0f3bcd537 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/PostOnly.java
@@ -5,6 +5,12 @@ import java.lang.annotation.Retention;
 import java.lang.annotation.RetentionPolicy;
 import java.lang.annotation.Target;
 
+/**
+ * Use this annotation to allow call action or action's method via POST request only
+ *
+ * @see HttpMethodInterceptor
+ * @since 2.3.18
+ */
 @Target({ElementType.METHOD, ElementType.TYPE})
 @Retention(RetentionPolicy.RUNTIME)
 public @interface PostOnly {


[struts] 05/15: Adds JavaDoc

Posted by lu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

lukaszlenart pushed a commit to branch http-interceptor
in repository https://gitbox.apache.org/repos/asf/struts.git

commit 88ea4419ce90565255b2ea53262fec69e050b29f
Author: Lukasz Lenart <lu...@apache.org>
AuthorDate: Sat Apr 19 21:12:49 2014 +0200

    Adds JavaDoc
---
 .../httpmethod/HttpMethodInterceptor.java            | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
index 36efb5266..e22e6a771 100644
--- a/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
+++ b/core/src/main/java/org/apache/struts2/interceptor/httpmethod/HttpMethodInterceptor.java
@@ -12,6 +12,26 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.List;
 
+/**
+ * Interceptor is used to control with what http methods action can be called,
+ * if request with not allowed method was performed, {@link #badRequestResultName}
+ * will be returned or if action implements {@link HttpMethodAware}
+ * and {@link HttpMethodAware#getBadRequestResultName()} returns non-null result name,
+ * thus value will be used instead.
+ *
+ * To limit allowed http methods, annotate action class with {@link AllowedMethod} and specify
+ * which methods are allowed. You can also use shorter versions {@link GetOnly}, {@link PostOnly}
+ * and {@link GetPostOnly}
+ *
+ * @see HttpMethodAware
+ * @see HttpMethod
+ * @see AllowedMethod
+ * @see GetOnly
+ * @see PostOnly
+ * @see GetPostOnly
+ *
+ * @since 2.3.18
+ */
 public class HttpMethodInterceptor extends AbstractInterceptor {
 
     public static final Class[] HTTP_METHOD_ANNOTATIONS = { AllowedMethod.class, PostOnly.class, GetOnly.class, GetPostOnly.class };