Uploaded image for project: 'Struts 2'
  1. Struts 2
  2. WW-4694

AnnotationWorkflowInterceptor doesn't work with spring proxied action

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.5.12
    • Component/s: Core
    • Labels:
      None

      Description

          public String intercept(ActionInvocation invocation) throws Exception {
              final Object action = invocation.getAction();
              invocation.addPreResultListener(this);
              List<Method> methods = new ArrayList<>(AnnotationUtils.getAnnotatedMethods(action.getClass(), Before.class));
      

      if action is annotated with @Transactional , AnnotationUtils.getAnnotatedMethods() will always return empty collection.
      here is my quick fix

      	public static Collection<Method> getAnnotatedMethods(Class clazz, Class<? extends Annotation>... annotation){
      		if( SpringProxy.class.isAssignableFrom(clazz) )
      			clazz = clazz.getSuperclass();
      

      but it will add spring dependence, I hope there is an elegant way.

        Issue Links

          Activity

          Hide
          quaff Yanming Zhou added a comment -

          I'm open an issue for spring https://jira.spring.io/browse/SPR-14770

          Show
          quaff Yanming Zhou added a comment - I'm open an issue for spring https://jira.spring.io/browse/SPR-14770
          Hide
          lukaszlenart Lukasz Lenart added a comment -

          This isn't a good practise to annotated actions with @Transactional - do you want to have more than one action involved in a transaction?

          Show
          lukaszlenart Lukasz Lenart added a comment - This isn't a good practise to annotated actions with @Transactional - do you want to have more than one action involved in a transaction?
          Hide
          quaff Yanming Zhou added a comment -

          I know @Transactional is not recommanded, It's just an example, AOP Proxy by spring is the point.

          Show
          quaff Yanming Zhou added a comment - I know @Transactional is not recommanded, It's just an example, AOP Proxy by spring is the point.
          Hide
          yasser.zamani Yasser Zamani added a comment -

          Spring has to do a lot of annotation processing itself in order to navigate its way around proxies, superclasses, interfaces and so. The logic for doing this is encapsulated and exposed in the org.springframework.core.annotation.AnnotationUtils class. In your case, it sounds like we can rewrite something like Spring's findAnnotation utility method and use it inside iteration of our getAnnotatedMethods to navigate around proxies and so like Spring itself do.

          I will be working on it, Lukasz Lenart.

          Show
          yasser.zamani Yasser Zamani added a comment - Spring has to do a lot of annotation processing itself in order to navigate its way around proxies, superclasses, interfaces and so. The logic for doing this is encapsulated and exposed in the org.springframework.core.annotation.AnnotationUtils class. In your case, it sounds like we can rewrite something like Spring's findAnnotation utility method and use it inside iteration of our getAnnotatedMethods to navigate around proxies and so like Spring itself do. I will be working on it, Lukasz Lenart .
          Hide
          githubbot ASF GitHub Bot added a comment -

          GitHub user yasserzamani opened a pull request:

          https://github.com/apache/struts/pull/117

          WW-4694 annotation processing improved

          With these changes, [AnnotationUtils](https://github.com/apache/struts/blob/master/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java) can navigate around proxies, superclasses and interfaces.
          known issue: for keep it simple, currently it does not support [Bridge Methods](https://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html).

          You can merge this pull request into a Git repository by running:

          $ git pull https://github.com/yasserzamani/struts WW-4694

          Alternatively you can review and apply these changes as the patch at:

          https://github.com/apache/struts/pull/117.patch

          To close this pull request, make a commit to your master/trunk branch
          with (at least) the following in the commit message:

          This closes #117


          commit c84b7967e9eb2f6307466b1644977423831d2ef1
          Author: Yasser Zamani <yasser.zamani@live.com>
          Date: 2017-02-05T14:24:28Z

          WW-4694 annotation processing improved in order to navigate around
          proxies, superclasses and interfaces


          Show
          githubbot ASF GitHub Bot added a comment - GitHub user yasserzamani opened a pull request: https://github.com/apache/struts/pull/117 WW-4694 annotation processing improved With these changes, [AnnotationUtils] ( https://github.com/apache/struts/blob/master/core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java ) can navigate around proxies, superclasses and interfaces. known issue: for keep it simple, currently it does not support [Bridge Methods] ( https://docs.oracle.com/javase/tutorial/java/generics/bridgeMethods.html ). You can merge this pull request into a Git repository by running: $ git pull https://github.com/yasserzamani/struts WW-4694 Alternatively you can review and apply these changes as the patch at: https://github.com/apache/struts/pull/117.patch To close this pull request, make a commit to your master/trunk branch with (at least) the following in the commit message: This closes #117 commit c84b7967e9eb2f6307466b1644977423831d2ef1 Author: Yasser Zamani <yasser.zamani@live.com> Date: 2017-02-05T14:24:28Z WW-4694 annotation processing improved in order to navigate around proxies, superclasses and interfaces
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user lukaszlenart commented on the issue:

          https://github.com/apache/struts/pull/117

          I have one general issue: indentation in some files are too big, it should be `4 spaces`

          Show
          githubbot ASF GitHub Bot added a comment - Github user lukaszlenart commented on the issue: https://github.com/apache/struts/pull/117 I have one general issue: indentation in some files are too big, it should be `4 spaces`
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user yasserzamani commented on the issue:

          https://github.com/apache/struts/pull/117

          Thank you. I got it and will fix it by update my eclipse Preferences.

          And what about the new codes and comments? some of them are copied from `Spring` framework which itself has `Apache License 2.0` license like Struts2. Do you recommend to rewrite them to something different with same functionality or no, those do not cause any legal issues?

          And finally, these changes are needed to fix WW-4472. Could you please add this issue id to the title to automatically linking and resolving that issue too?

          Thanks in advance!

          Show
          githubbot ASF GitHub Bot added a comment - Github user yasserzamani commented on the issue: https://github.com/apache/struts/pull/117 Thank you. I got it and will fix it by update my eclipse Preferences. And what about the new codes and comments? some of them are copied from `Spring` framework which itself has `Apache License 2.0` license like Struts2. Do you recommend to rewrite them to something different with same functionality or no, those do not cause any legal issues? And finally, these changes are needed to fix WW-4472 . Could you please add this issue id to the title to automatically linking and resolving that issue too? Thanks in advance!
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user lukaszlenart commented on the issue:

          https://github.com/apache/struts/pull/117

          Cool, this look great and I don't mind copping code from other libraries if they match license

          Regarding issue linkage I think you can update the description and put an issue ID there, e.g. `Fixes WW-4472` should be enough

          Show
          githubbot ASF GitHub Bot added a comment - Github user lukaszlenart commented on the issue: https://github.com/apache/struts/pull/117 Cool, this look great and I don't mind copping code from other libraries if they match license Regarding issue linkage I think you can update the description and put an issue ID there, e.g. `Fixes WW-4472 ` should be enough
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit c84b7967e9eb2f6307466b1644977423831d2ef1 in struts's branch refs/heads/master from Yasser Zamani
          [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=c84b796 ]

          WW-4694 annotation processing improved in order to navigate around
          proxies, superclasses and interfaces

          Show
          jira-bot ASF subversion and git services added a comment - Commit c84b7967e9eb2f6307466b1644977423831d2ef1 in struts's branch refs/heads/master from Yasser Zamani [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=c84b796 ] WW-4694 annotation processing improved in order to navigate around proxies, superclasses and interfaces
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 534dfc6bd8840bc2aa64022570b2225977ece5f6 in struts's branch refs/heads/master from Lukasz Lenart
          [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=534dfc6 ]

          WW-4694 WW-4472 Imroves annotation processing

          Show
          jira-bot ASF subversion and git services added a comment - Commit 534dfc6bd8840bc2aa64022570b2225977ece5f6 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=534dfc6 ] WW-4694 WW-4472 Imroves annotation processing
          Hide
          githubbot ASF GitHub Bot added a comment -

          Github user asfgit closed the pull request at:

          https://github.com/apache/struts/pull/117

          Show
          githubbot ASF GitHub Bot added a comment - Github user asfgit closed the pull request at: https://github.com/apache/struts/pull/117
          Hide
          lukaszlenart Lukasz Lenart added a comment -

          PR merged, thanks Yasser Zamani

          Show
          lukaszlenart Lukasz Lenart added a comment - PR merged, thanks Yasser Zamani
          Hide
          hudson Hudson added a comment -

          SUCCESS: Integrated in Jenkins build Struts-JDK7-master #592 (See https://builds.apache.org/job/Struts-JDK7-master/592/)
          WW-4694 annotation processing improved in order to navigate around (yasser.zamani: rev c84b7967e9eb2f6307466b1644977423831d2ef1)

          • (edit) core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java
          • (add) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyInterface.java
          • (add) core/src/test/java/com/opensymphony/xwork2/util/annotation/MyAnnotationI.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClassExt.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClass.java
          Show
          hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #592 (See https://builds.apache.org/job/Struts-JDK7-master/592/ ) WW-4694 annotation processing improved in order to navigate around (yasser.zamani: rev c84b7967e9eb2f6307466b1644977423831d2ef1) (edit) core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java (add) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyInterface.java (add) core/src/test/java/com/opensymphony/xwork2/util/annotation/MyAnnotationI.java (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClassExt.java (edit) core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClass.java
          Hide
          quaff Yanming Zhou added a comment - - edited

          I have created a related issue WW-4744

          Show
          quaff Yanming Zhou added a comment - - edited I have created a related issue WW-4744
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 33e1eeb386c98beeaeff51504a2ff156098f2c01 in struts's branch refs/heads/master from Yasser Zamani
          [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=33e1eeb ]

          WW-4744 WW-4694 Removes annotation search to commons lang 3.6

          Show
          jira-bot ASF subversion and git services added a comment - Commit 33e1eeb386c98beeaeff51504a2ff156098f2c01 in struts's branch refs/heads/master from Yasser Zamani [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=33e1eeb ] WW-4744 WW-4694 Removes annotation search to commons lang 3.6
          Hide
          jira-bot ASF subversion and git services added a comment -

          Commit 8f53b6f59efe0f713e4689ef10fe6bae5e4c0cb7 in struts's branch refs/heads/master from Lukasz Lenart
          [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=8f53b6f ]

          WW-4744 WW-4694 Removes annotation search to commons lang 3.6

          Show
          jira-bot ASF subversion and git services added a comment - Commit 8f53b6f59efe0f713e4689ef10fe6bae5e4c0cb7 in struts's branch refs/heads/master from Lukasz Lenart [ https://git-wip-us.apache.org/repos/asf?p=struts.git;h=8f53b6f ] WW-4744 WW-4694 Removes annotation search to commons lang 3.6
          Hide
          hudson Hudson added a comment -

          SUCCESS: Integrated in Jenkins build Struts-JDK7-master #640 (See https://builds.apache.org/job/Struts-JDK7-master/640/)
          WW-4744 WW-4694 Removes annotation search to commons lang 3.6 (yasser.zamani: rev 33e1eeb386c98beeaeff51504a2ff156098f2c01)

          • (edit) core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java
          • (edit) core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java
          • (delete) core/src/test/java/com/opensymphony/xwork2/util/annotation/MyAnnotationI.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClassExt.java
          • (edit) core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java
          • (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClass.java
          • (delete) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyInterface.java
          • (edit) core/src/main/java/org/apache/struts2/components/Component.java
          • (edit) plugins/bean-validation/src/main/java/org/apache/struts/beanvalidation/validation/interceptor/BeanValidationInterceptor.java
          • (edit) core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java
          • (edit) pom.xml
          Show
          hudson Hudson added a comment - SUCCESS: Integrated in Jenkins build Struts-JDK7-master #640 (See https://builds.apache.org/job/Struts-JDK7-master/640/ ) WW-4744 WW-4694 Removes annotation search to commons lang 3.6 (yasser.zamani: rev 33e1eeb386c98beeaeff51504a2ff156098f2c01) (edit) core/src/main/java/com/opensymphony/xwork2/util/AnnotationUtils.java (edit) core/src/test/java/com/opensymphony/xwork2/util/AnnotationUtilsTest.java (edit) core/src/main/java/com/opensymphony/xwork2/interceptor/annotations/AnnotationWorkflowInterceptor.java (delete) core/src/test/java/com/opensymphony/xwork2/util/annotation/MyAnnotationI.java (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClassExt.java (edit) core/src/main/java/com/opensymphony/xwork2/interceptor/DefaultWorkflowInterceptor.java (edit) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyClass.java (delete) core/src/test/java/com/opensymphony/xwork2/util/annotation/DummyInterface.java (edit) core/src/main/java/org/apache/struts2/components/Component.java (edit) plugins/bean-validation/src/main/java/org/apache/struts/beanvalidation/validation/interceptor/BeanValidationInterceptor.java (edit) core/src/main/java/org/apache/struts2/interceptor/validation/AnnotationValidationInterceptor.java (edit) pom.xml

            People

            • Assignee:
              Unassigned
              Reporter:
              quaff Yanming Zhou
            • Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development