-
1. Re: Deploy AOP to jboss 5.1
kabirkhan Aug 24, 2009 3:01 PM (in response to kgreene)You need to deploy the aspects and -aop.xml before you deploy your application. You might already be doing this, but you did not mention it.
It sounds like you have loadtime weaving set up correctly, but try the 'injboss' tutorial example that comes with the AOP download to verify. -
2. Re: Deploy AOP to jboss 5.1
kgreene Aug 24, 2009 3:19 PM (in response to kgreene)Thanks for the quick response. Yes. I did deploy the aspects and aop before the application.
I tried to find the injboss tutorial earlier and downloaded jboss-aop-2.1.3.GA.zip, but could not find it. Is there something else I need to download? -
3. Re: Deploy AOP to jboss 5.1
kabirkhan Aug 24, 2009 3:28 PM (in response to kgreene)jboss-aop-2.1.3.zip/docs/aspect-framework/examples/injboss
-
4. Re: Deploy AOP to jboss 5.1
kgreene Aug 24, 2009 5:38 PM (in response to kgreene)Ok, I deployed docs\aspect-framework\examples\injboss example using deploy-basic-lt-war. When I bring up index.jsp I get the following the errors below indicating the SimpleInterceptor class cannot be found even though I can look at the jar inside the war and can see the class.
At any rate, it appears that jboss is trying to at least apply the aop. I have AspectManager verbose set to true. I understand that this is supposed to output info when aop is applied. When I deploy my jars that use the aop, there is absolutely no output. I don't think jboss is applying the aop in the code I am deploying (in that I see that there is output in the errors regarding joinpoints). I really appreciate your help as I have trying to resolve this issue for a couple days and cannot determine I am doing wrong.
I have a JobFlow.jar that includes:
- JobFlow.java
- JobFlowAspect.java
- A few additional classes the aspect uses
I have a jboss-aop.xml that indicates to call the JobFlowAspect whenever the JobFlow annotation is used on a method
I have another jar that includes a classes that use the JobFlow annotation on the method.
I deployed the JobFlow.jar and jboss-aop.xml to farm, then I deploy the jars that use the annotation. When I deploy the jars that use the annotation there is no output that the aspect is being applied.Here is the JobFlow and JobFlowAspect (Note that I deleted most of the logic in the aspect class for brevity sake). I also tried annotations instead of jboss-aop.xml, but that did not work either. Here is JobFlow.java @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface JobFlow {} Here is JobFlowAspect.java //@Aspect(scope = Scope.PER_VM) public class JobFlowAspect { private static Logger log = Logger.getLogger(JobFlowAspect.class); //@Bind(pointcut="execution(* *->@com.jpmc.etl.jobflow.aspect.JobFlow(..))") public Object executeFlow(MethodInvocation invocation) throws Throwable { try { System.out.println("JobFlowAspect: Calling method " + invocation.getMethod().getName()); return invocation.invokeNext(); } finally { System.out.println("JobFlowAspect: Done"); } } }
=========== Here is the output I get from deploying the injboss example ====
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 7
root cause
java.lang.RuntimeException: Error generating joinpoint class for joinpoint Method[method=public java.lang.String org.jboss.injbossaop.lib.ExampleValue.getMessage()]
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.injbossaop.lib.SimpleInterceptor -
5. Re: Deploy AOP to jboss 5.1
kgreene Aug 24, 2009 5:44 PM (in response to kgreene)Please ignore the previous post as there was a statement that was incorrect.
Ok, I deployed docs\aspect-framework\examples\injboss example using deploy-basic-lt-war. When I bring up index.jsp I get the following the errors below indicating the SimpleInterceptor class cannot be found even though I can look at the jar inside the war and can see the class.
At any rate, it appears that jboss is trying to at least apply the aop (in that I see that there is output in the errors regarding joinpoints).
I have AspectManager verbose set to true. I understand that this is supposed to output info when aop is applied. When I deploy my jars that use the aop, there is absolutely no output. I don't think jboss is applying the aop in the code I am deploying . I really appreciate your help as I have trying to resolve this issue for a couple days and cannot determine I am doing wrong.
I have a JobFlow.jar that includes:
- JobFlow.java
- JobFlowAspect.java
- A few additional classes the aspect uses
I have a jboss-aop.xml that indicates to call the JobFlowAspect whenever the JobFlow annotation is used on a method
I have another jar that includes a classes that use the JobFlow annotation on the method.
I deployed the JobFlow.jar and jboss-aop.xml to farm, then I deploy the jars that use the annotation. When I deploy the jars that use the annotation there is no output that the aspect is being applied.Here is the JobFlow and JobFlowAspect (Note that I deleted most of the logic in the aspect class for brevity sake). I also tried annotations instead of jboss-aop.xml, but that did not work either. Here is JobFlow.java @Target({ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) public @interface JobFlow {} Here is JobFlowAspect.java //@Aspect(scope = Scope.PER_VM) public class JobFlowAspect { private static Logger log = Logger.getLogger(JobFlowAspect.class); //@Bind(pointcut="execution(* *->@com.jpmc.etl.jobflow.aspect.JobFlow(..))") public Object executeFlow(MethodInvocation invocation) throws Throwable { try { System.out.println("JobFlowAspect: Calling method " + invocation.getMethod().getName()); return invocation.invokeNext(); } finally { System.out.println("JobFlowAspect: Done"); } } }
=========== Here is the output I get from deploying the injboss example ====
org.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 7
root cause
java.lang.RuntimeException: Error generating joinpoint class for joinpoint Method[method=public java.lang.String org.jboss.injbossaop.lib.ExampleValue.getMessage()]
java.lang.RuntimeException: java.lang.ClassNotFoundException: org.jboss.injbossaop.lib.SimpleInterceptor -
6. Re: Deploy AOP to jboss 5.1
kgreene Aug 24, 2009 6:04 PM (in response to kgreene)I resolved the classnotfound error. The aop is being applied to the injbossaop example as I see the output below.
Still trying to figure out why the aop for my classes are not being applied. Is there something different that needs to be done if the aop is being triggered via an annotation? If you have any insights, it would be most appreciated. The annotation, aspect and jboss-aop.xml is in previous replies.
17:52:19,670 INFO [STDOUT] **** ExampleValue empty Constructor
17:52:19,717 INFO [STDOUT] <<< Entering SimpleInterceptor:
invocation class: org.jboss.injbossaop.lib.JoinPoint_getMessage5353407034680111516_1
type: Method Invocation
method: getMessage
Class containing method: org.jboss.injbossaop.lib.ExampleValue
17:52:19,717 INFO [STDOUT] **** ExampleValue.getMessage()
17:52:19,717 INFO [STDOUT] >>> Leaving SimpleInterceptor
17:54:08,753 INFO [STDOUT] <<< Entering SimpleInterceptor:
invocation class: org.jboss.injbossaop.web.JoinPoint_service8586428322187484014_2
type: Method Invocation
method: service
Class containing method: org.jboss.injbossaop.web.BasicExampleServlet
17:54:08,769 INFO [STDOUT] **** BasicExampleServlet.service()
17:54:08,816 INFO [STDOUT] <<< Entering SimpleInterceptor:
invocation class: org.jboss.injbossaop.lib.JoinPoint_constructor_ExampleValue_1_3
type: Constructor Invocation
constructor: public org.jboss.injbossaop.lib.ExampleValue(java.lang.String)
17:54:08,816 INFO [STDOUT] **** ExampleValue String Constructor
17:54:08,816 INFO [STDOUT] >>> Leaving SimpleInterceptor
17:54:08,910 INFO [STDOUT] <<< Entering SimpleInterceptor:
invocation class: org.jboss.injbossaop.lib.JoinPoint_getMessage5353407034680111516_1
type: Method Invocation
method: getMessage
Class containing method: org.jboss.injbossaop.lib.ExampleValue
17:54:08,910 INFO [STDOUT] **** ExampleValue.getMessage()
17:54:08,910 INFO [STDOUT] >>> Leaving SimpleInterceptor
17:54:08,910 INFO [STDOUT] >>> Leaving SimpleInterceptor -
7. Re: Deploy AOP to jboss 5.1
kabirkhan Aug 25, 2009 6:06 AM (in response to kgreene)"kgreenejpmc" wrote:
Is there something different that needs to be done if the aop is being triggered via an annotation?
If you mean using @Aspect, @Bind etc., the classes need to be in an .aop file.
If you mean using annotations in your pointcuts, nothing special is needed. If you only remembered to add the @Retention to your @JobFlow annotation after annotating your classes with @JobFlow you should clean and recompile all the classes so the annotation gets reapplied. -
8. Re: Deploy AOP to jboss 5.1
kgreene Aug 25, 2009 3:36 PM (in response to kgreene)Ok, after quite a bit of trial and error I finally got the aop to work. However, I have a question.
If I put my @JobFlow annotation on the onMessage method, the aop does not work. However, If I put the @JobFlow annotation on the processMessage method (which onMessage calls), the aop works. Does jboss suppress or ignore custom annotations on onMessage? If so, is there a way to enable them to work on onMessage?@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName="maxMessages", propertyValue="1"), @ActivationConfigProperty(propertyName="maxSession", propertyValue="3"), @ActivationConfigProperty(propertyName="dLQMaxResent", propertyValue="1"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/TestConsumer1") }) @Clustered public class TestConsumer1 implements MessageListener { private static Logger log = Logger.getLogger(TestConsumer1.class); @Resource private MessageDrivenContext context; //put @JobFlow here does not work. The aop does not get called public void onMessage(Message msg) { log.info("Got message."); try { processMessage(msg); TextMessage txtMsg = (TextMessage)msg; String stagingPath = txtMsg.getText(); log.info("FlowId: " + MessageProperties.getFlowId(msg)); log.info("JobId: " + MessageProperties.getJobId(msg)); log.info("PrevStageId: " + MessageProperties.getPrevStageId(msg)); } catch (Exception e) { context.setRollbackOnly(); } log.info("DONE!"); } //putting @JobFlow here works and the aop is called @JobFlow public void processMessage(Message msg) { log.info("Running processMessage"); } }
-
9. Re: Deploy AOP to jboss 5.1
kabirkhan Aug 25, 2009 3:59 PM (in response to kgreene)If you want to intercept onMessage() only, you're probably better off creating a custom AOP domain for message driven beans (see deploy/ejb3-interceptors-aop.xml for examples of how to do this) and to use the @AspectDomain annotation on your message driven beans where you want this behaviour. This will avoid the need for weaving your classes. There should be some examples on how to do this in the ejb 3 documentation or user forum.
Regarding your question, it "should work" for onMessage(), but I am not sure how ejb3 interacts with woven classes, and since EJB3 uses AOP to configure itself, there might be some problem with aspects on EJB 3 business methods. -
10. Re: Deploy AOP to jboss 5.1
kgreene Aug 26, 2009 3:44 PM (in response to kgreene)Thanks for the feedback. I have another question.
On discovering that the @JobFlow does not work on onMessage, I was very curious as to how annotations such as @TransactionAttribute work on onMessage (as well as other methods). These types of annotations don't seem to require loadtime weaving. In addition, you don't have to do anything special when you compile your classes that use these annotations (which leads me to believe that compile time weaving is not required either).
I did quite a bit of digging and discovered it might have to do with proxies, but I am not sure. I looked at the jboss source code, but did not see anything special in TransactionAttributeImpl.java
I am interested in developing my custom annotation and aspect such that it works like the @TransactionAttribute in that it does not require load time weaving and you don't have to compile your classes in any special way.
Am I correct in assuming that annotations such as @TransactionAttribute don't use compile time or loadtime weaving? If so, could you point me to some sources that would explain how the the code behind the annotation is triggered and executed? -
11. Re: Deploy AOP to jboss 5.1
kgreene Aug 26, 2009 3:46 PM (in response to kgreene)Thanks for the feedback. I have another question.
On discovering that the @JobFlow does not work on onMessage, I was very curious as to how annotations such as @TransactionAttribute work on onMessage (as well as other methods). These types of annotations don't seem to require loadtime weaving. In addition, you don't have to do anything special when you compile your classes that use these annotations (which leads me to believe that compile time weaving is not required either).
I did quite a bit of digging and discovered it might have to do with proxies, but I am not sure. I looked at the jboss source code, but did not see anything special in TransactionAttributeImpl.java
I am interested in developing my custom annotation and aspect such that it works like the @TransactionAttribute in that it does not require load time weaving and you don't have to compile your classes in any special way.
Am I correct in assuming that annotations such as @TransactionAttribute don't use compile time or loadtime weaving? If so, could you point me to some sources that would explain how the the code behind the annotation is triggered and executed? -
12. Re: Deploy AOP to jboss 5.1
kabirkhan Aug 27, 2009 5:14 AM (in response to kgreene)Correct, if you deploy an EJB 3 bean it constructs an EJB container without weaving. The configuration for these containers is in ejb3-interceptors-aop.xml. Calls to the ejb are done via the container and go through the stack of interceptors before hitting the ejb.
For example, if you deploy a stateless session bean it will use the<domain name="Stateless Bean" extends="Intercepted Bean" inheritBindings="true">
which uses pointcuts to apply the different interceptors that make up the container. e.g. the<interceptor-ref name="org.jboss.ejb3.tx.CMTTxInterceptorFactory"/>
looks for the TransactionAttribute annotations on the different methods and applies the correct transactions.
You can either add to these domains in ejb3-interceptors-aop.xml in which case it will apply to all beans matching your pointcuts, or you can create a custom domain with more bindings and choose to apply it to a particular bean using the @AspectDomain annotation
http://www.jboss.org/ejb3/docs/tutorial/configuration/configuration.html
explains more about this. You can get there by going to http://www.jboss.org/community/wiki/EJB3 and then 'Tutorial' and then 'Custom configuration' -
13. Re: Deploy AOP to jboss 5.1
przemekc Jun 16, 2011 6:11 AM (in response to kgreene)Karen,
Does it works for you? I'm trying to add some custom additional annotation on my stateless ejb which is also my webservice but it dosen't call my aspect. I'm using jboss 6 application server. Have you used your configuration on jboss 6?
-
14. Re: Deploy AOP to jboss 5.1
przemekc Jun 16, 2011 6:15 AM (in response to przemekc)I forgot mention that when I have bind pointcut configure lie execution(* MyBean->someMethod(..)) aspect is running. But when I have
execution(* *->@MyAnnotation()) it's not working.