8 Replies Latest reply on Dec 21, 2004 10:37 AM by fredatwork

    JBoss 4 with JBoss AOP V1.0

    Tally Tsabary Newbie

      Hello,

      I am trying to use the AOP as follows, but it is not working for me. I would appreciate any advice.

      My environment is:
      JBoss 4
      The Teller WebService example is working fine.
      I want to print a notification whenever one of the TellerBean methods is working.
      I deployed the AOP.
      I added a file named: TestAOP-aop.xml to the
      jboss-4.0.0\server\default\deploy\jboss-aop.deployer folder.
      Its content is:

      <aop>
       <aspect class="com.test.TestAspect" scope="PER_VM"/>
      
       <pointcut expr="execution(public java.lang.String[] com.jboss.ebank.TellerBean->getAccountsOfCustomer(java.lang.String))" name="getAccountsOfCustomer"/>
       <bind pointcut="getAccountsOfCustomer">
       <advice aspect="com.test.TestAspect" name="trace1"/>
       </bind>
      
       <pointcut expr="execution(public com.jboss.ebank.TellerBean->new(..))" name="TellerBeanConst"/>
       <bind pointcut="TellerBeanConst">
       <advice aspect="com.test.TestAspect" name="trace2"/>
       </bind>
      </aop>


      I put a jar with the Aspect program at the
      jboss-4.0.0\server\default\deploy folder. Its content is:

      public class TestAspect {
      
       //Advice 1: Trace methods invocation
       public Object trace1(MethodInvocation invocation)
       throws Throwable {
       try {
       System.out.println("TestAspect: trace: START of "+invocation.getMethod());
       return invocation.invokeNext();
       } finally {
       System.out.println("TestAspect: trace: END of "+invocation.getMethod());
       }
       }
      
      // Advice 2: Trace constructors invocation
       public Object trace2(ConstructorInvocation invocation)
       throws Throwable {
       try {
       System.out.println("TestAspect: trace: START of "+invocation.getConstructor());
       return invocation.invokeNext();
       } finally {
       System.out.println("TestAspect: trace: END of "+invocation.getConstructor());
       }
      }
      
      
      
      }


      I set the jboss-4.0.0\server\default\deploy\jboss-aop.deployer\META-INF\jboss-service.xml file to be:
      <server>
      
       <mbean code="org.jboss.aop.deployment.AspectManagerService"
       name="jboss.aop:service=AspectManager">
       <attribute name="EnableTransformer">true</attribute>
       <attribute name="SuppressTransformationErrors">true</attribute>
       <attribute name="Optimized">true</attribute>
       <attribute name="Verbose">true</attribute>
       </mbean>
      
       <mbean code="org.jboss.aop.deployment.AspectDeployer"
       name="jboss.aop:service=AspectDeployer">
       </mbean>
      
      </server>



      Thanks

        • 1. 3736846
          fredatwork Newbie

          Ok. Let's assume that I would fix a possible bug, then test it with the testsuite, and finally contribute it to the cvs.
          Is that it? After that the small piece of code would be part of future stable releases? (assuming it doesn't break anything) 8-\

          • 2. Re: JBoss 4 with JBoss AOP V1.0
            Kabir Khan Master

            Hi,

            Please take a look at the "injboss" tutorial example for an example of how to package aop apps to be run in JBoss.

            Cheers,

            Kabir

            • 3. Re: JBoss 4 with JBoss AOP V1.0
              Tally Tsabary Newbie

              Hi Kabir,

              Thank you, I read the document, but I still need some help.
              My goal is to create "statistics" interceptor, that will count how many time a specific method has been called. - The specific method/methods should be configurable, and most of the times, they will be part of applications which I cannot recompile or even re-package.

              I thought it would be possible to have a generic interceptor that will perform the counting, and that the watched methods will be configured via the *-aop.xml file.
              Is it possible at all?
              If so, please help me to understand how exactly I should set the App Server and the *-aop.xml file. I attached the "statistics" interceptor and the other configuration files at my first email.

              Thanks for your patient
              SuDing

              • 4. Re: JBoss 4 with JBoss AOP V1.0
                Tally Tsabary Newbie

                Well, It is working now.

                I changed the *-aop.xml file to be:

                <aop>
                
                 <bind pointcut="execution(* com.jboss.ebank.TellerBean->*(..))">
                 <interceptor class="com.test.TestInterceptor"/>
                 </bind>
                
                
                
                </aop>

                The Interceptor class is:
                public class TestInterceptor implements Interceptor
                {
                 public String getName() {
                 return "TestInterceptor";
                 }
                
                 public Object invoke(Invocation invocation) throws Throwable
                 {
                 try
                 {
                 MethodInvocation mi = (MethodInvocation)invocation;
                 System.out.println("@@@ Start TestInterceptor for: " + mi.getMethod().toString());
                 return invocation.invokeNext();
                 }
                 finally
                 {
                 System.out.println("@@@ End TestInterceptor");
                 }
                 }
                }


                I created a jar file that includes the TestInterceptor class, and put it under the jboss-4.0.0\server\default\lib folder. (I am using the default server)

                I added the following system property definition to the JBoss run.bat:
                set JAVA_OPTS=%JAVA_OPTS% -Djboss.aop.path=%JBOSS_HOME%\server\default\deploy\jboss-aop.deployer

                Thanks
                SuDing


                • 5. Re: JBoss 4 with JBoss AOP V1.0
                  fredatwork Newbie

                  Kabir made a reference to a 'injboss' tutorial.

                  Where is this tutorial that may help me ? An URL zould be appreciated.

                  Fred


                  --->
                  Hi,

                  Please take a look at the "injboss" tutorial example for an example of how to package aop apps to be run in JBoss.

                  Cheers,

                  Kabir

                  • 6. Re: JBoss 4 with JBoss AOP V1.0
                    Kabir Khan Master

                    You can access the docs here: http://www.jboss.org/docs/index#aop

                    If you have downloaded the distribution, it is under:

                    jboss-aop_1.0.0-FINAL/docs/aspect-framework/examples/injboss

                    Kabir

                    • 7. Re: JBoss 4 with JBoss AOP V1.0
                      fredatwork Newbie

                      Kabir,

                      I installed the 'injboss' example and built it successfully (running 'ant deploy-ear-aop').

                      Hozever, JBoss fails deploying the resulting ear file. It's missing a class ClassFileFilter :
                      java.lang.NoClassDefFoundError: org/jboss/util/file/ClassFileFilter

                      For your information, I'm running JBoss 4.0.0 RC2 with 'default' configuration. As requested, I modified ${JBOSSS_HOME}\server\default\deploy\jboss-aop-jdk50.deployer\META-INF\jboss-service.xml to turn loadtime transformations on :
                      true

                      Any idea what I'm missing ?

                      Fred

                      • 8. Re: JBoss 4 with JBoss AOP V1.0
                        Kabir Khan Master

                        Use the proper JBoss 4.0 release and not the RC2 one.

                        Kabir