Announcement Announcement Module
Collapse
No announcement yet.
schema aop spring 2 struts actions Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • schema aop spring 2 struts actions

    I am trying to create an aspect that can be cut across my spring loaded struts actions. My struts actions work in spring, but my aop logging example does not.

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
    <display-name>
    Example1</display-name>
    <!-- Spring integration -->
    <listener>
    <display-name>spring-applicationContext</display-name>
    <listener-class>org.springframework.web.context.ContextLoade rListener</listener-class>
    </listener>

    <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/applicationContext*.xml</param-value>
    </context-param>
    <!-- Spring integration end-->

    <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>
    org.apache.struts.action.ActionServlet</servlet-class>
    <init-param>
    <param-name>config</param-name>
    <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
    <param-name>debug</param-name>
    <param-value>2</param-value>
    </init-param>
    <init-param>
    <param-name>detail</param-name>
    <param-value>2</param-value>
    </init-param>
    <init-param>
    <param-name>validate</param-name>
    <param-value>true</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    </web-app>

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>

    <!-- Data Sources -->
    <data-sources></data-sources>

    <!-- Form Beans -->
    <form-beans>
    <form-bean name="form" type="example1.forms.Form"></form-bean>
    <form-bean name="form2" type="example1.forms.Form2"></form-bean>
    </form-beans>

    <!-- Global Exceptions -->
    <global-exceptions></global-exceptions>

    <!-- Global Forwards -->
    <global-forwards></global-forwards>


    <!-- Action Mappings -->
    <action-mappings>
    <action path="/action1" type="org.springframework.web.struts.DelegatingAct ionProxy"
    name="form" scope="request" input="/input.jsp">
    <forward name="success" path="/output.jsp"></forward>
    <forward name="failure" path="/input.jsp"></forward>
    </action>
    <action path="/action2" type="org.springframework.web.struts.DelegatingAct ionProxy"
    scope="request" input="/output.jsp" name="form2">
    <forward name="success" path="/final.jsp"></forward>
    <forward name="failure" path="/output.jsp"></forward>
    </action>
    </action-mappings>

    <!-- Message Resources -->
    <message-resources
    parameter="example1.resources.ApplicationResources " />


    <plug-in className="org.apache.struts.validator.ValidatorPl ugIn">
    <set-property property="pathnames"
    value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml" />
    </plug-in>

    <!-- Spring stuff -->

    <plug-in
    className="org.springframework.web.struts.ContextL oaderPlugIn">
    <set-property property="csntextConfigLocation"
    value="/WEB-INF/action-servlet.xml,/WEB-INF/applicationContext-web.xml" />
    </plug-in>
    <!-- End of Spring Stuff -->

    </struts-config>


    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="
    http://www.springframework.org/schema/beans
    http://www.springframework.org/schem...-beans-2.0.xsd
    http://www.springframework.org/schema/aop
    http://www.springframework.org/schem...ng-aop-2.0.xsd ">

    <aop:config proxy-target-class="true">
    <aop:aspect ref="logging">
    <aopointcut id="test1"
    expression="execution(* example1.actions.*.*(..))" />
    <aop:before pointcut-ref="test1" method="logBefore" />
    <aop:after-returning pointcut-ref="test1" method="logAfter" />
    </aop:aspect>
    </aop:config>

    <bean id="logging" class="example1.logging.LoggingExample" />

    </beans>

    package example1.logging;

    public class LoggingExample {

    public void logBefore () {
    System.out.println("before an action");
    }

    public void logAfter () {
    System.out.println("After an action");
    }

    }

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
    "http://www.springframework.org/dtd/spring-beans.dtd">

    <beans>

    <bean name="/action1" class="example1.actions.Action1Action"></bean>
    <bean name="/action2" class="example1.actions.Action2Action"></bean>

    </beans>

    Any assistance would be appreciated.

    Mike

  • #2
    It's the same issue as in this thread ? http://forum.springframework.org/showthread.php?t=36504

    Also, is much more easier to follow if you put your code inside [ CODE][ /CODE] tags.

    Comment


    • #3
      maybe

      If you mean I should use

      Code:
      <aop:config proxy-target-class="true">
      then well, I've already tried that.

      It is similar to the issue posted by Javier Rivas except I am using xml aop config rather than aspectj, I'm not getting an error message, and It's not working.

      Mike

      Comment


      • #4
        I tried to do what you're are doing and it didn't work either, and as I didnt have much more time I gave up.

        Although I think I was very to close to get it working when I defined the action beans as AutoproxyCreators in the Spring applicationContext file.

        Take a look at Section 7.9. ot the Reference Documentation:"Using the "autoproxy" facility", I might help you.

        And please, If you get it working post it. I'll try to do some more work this weekend, and if I came up with a solution Ill let you know.

        Regards, Javier Rivas.

        Comment


        • #5
          still trying

          Javier,

          I'm still working on this. I'm trying to get it all done through XML although that is seeming much less likely. I am personally not pressed for time on a solution. I am attempting to write a tutorial on how to use the new features.

          Mike

          Comment


          • #6
            solved...I think

            Javier,

            It looks to me like action-servlet.xml is loaded into a different container than application-context*.xml. When I moved my aop definitions over to action-servlet.xml, they worked just fine.


            Mike

            Comment


            • #7
              Hi Mike,

              Nice one, Ill try that this weekend.

              Comment


              • #8
                I dont get it working

                Mike, I tried to work out your example doing what you said, but still nothing.

                I agree with you that the action-servlet.xml is loaded into a different container than application-context*.xml., because when I get the Action bean (struts one) from the factory bean in the application-context, the advice is called, and the AOP works as it has to.

                However, when struts is controlling the actions, the AOP advices arent called.

                I have been doing some research and I think that the final classes cant be used with AOP, because as far as I know the CGLIB cant proxy them.
                I dont know, the more I read about the topic, the more confused I am.

                7.5.5. Proxying classes
                CGLIB proxying should generally be transparent to users. However, there are some issues to consider:
                * Final methods can't be advised, as they can't be overridden.

                But on the other hand, as I said, I think that the problem is in which context the beans are loaded, although, putting altogether in the action-servlet.xml didnt work for me.

                Could you post your whole example, so I can see if I am missing something?
                Cheers!
                Last edited by Javier Rivas; May 12th, 2007, 10:02 AM.

                Comment


                • #9
                  half-solved?

                  Mike, Ive just posted a new thread http://forum.springframework.org/showthread.php?t=38663

                  please take a look

                  P.D. What is that tutorial you're trying to write? Is it an open source tutorial? Well, if you need some help, I wouldnt mind collaborating with you.

                  Regards, Javier

                  Comment


                  • #10
                    tutorial

                    Javier,

                    I am writing the tutorial for my client with Rational Application Developer 7 as the IDE. I can pass that on to you when I get it done, and you can adapt it as you see fit, or I can post it. I am going to post the contents of my working application on a separate message.

                    Mike

                    Comment


                    • #11
                      files from tutorial

                      Hopefully, the attachment will have what you need Javier.

                      Mike

                      Comment


                      • #12
                        I am trying to do the same thing but with no luck.

                        Here's my thread:
                        http://forum.springframework.org/showthread.php?t=44324

                        I'm basically doing the same thing but it's not working for me.

                        One thing the example posted above is doing differently is repeating the aspect configuration and advice bean in both the struts-config.xml and the applicationContext-web.xml. Not only is it repeated in both but both are loaded in the struts-config.xml plugin part - that I don't understand at all. Why repeat it and why load both ????

                        This is in the struts-config.xml in the attachment from the post above:
                        Code:
                        	<plug-in
                        		className="org.springframework.web.struts.ContextLoaderPlugIn">
                        		<set-property property="csntextConfigLocation"
                        			value="/WEB-INF/action-servlet.xml,/WEB-INF/applicationContext-web.xml" />
                        	</plug-in>
                        Note how we're loading both - I don't get it.
                        Last edited by LordHalbert; Sep 28th, 2007, 07:23 PM.

                        Comment

                        Working...
                        X