I am trying to write 2 pieces of advice: a "before advice" which logs a Message object during a normal flow and an "after-throwing" advice that logs the message when an exception happens.
My "before advice" is working but for some reason I cannot get my "after-throws" advice to work.
Here is my XML definition:
My two methods in my advice are:Code:<aop:config> <aop:pointcut id="exceptionPointcut" expression="execution(* com.test.cwp.integration.exchange.hub..*.*(..))"/> <aop:pointcut id="auditLogPointcut" expression="execution(* com.test.cwp.integration.exchange.hub..*.*(..)) and args(message,..)"/> <aop:aspect ref="integrationSystemAdvice"> <aop:after-throwing method="handleMessageException" pointcut-ref="exceptionPointcut" throwing="exception"/> <aop:before method="logMessage" pointcut-ref="auditLogPointcut" arg-names="message" /> </aop:aspect> </aop:config>
I'm running the following method in a test case in the package: com.test.cwp.integration.exchange.hubCode:public void handleMessageException(Exception exception) { System.out.println("#######\n\n" + "Exception logged: " + exception + "##\n\n\n"); } public void logMessage(Message message) { TextMessage m = (TextMessage) message; try { System.out.println("#######\n\n" + "message in logMessage: " + m.getText() + "##\n\n\n"); } catch (JMSException e) { e.printStackTrace(); } }
With this setup, the "before advice" is running properly and my message is printed out in my logMessage method in my advice bean. However, when I throw the new Exception("testing"), it never calls my after-throwing method handleMessageException. What's interesting is the stack trace for the exception I am manually throwing. It is:Code:public void processMessage(Message message) throws Exception { TextMessage tMessage = (TextMessage) message; throw new Exception("testing"); }
If I remove the pointcut for my after-throws advice, then none of the AOP methods are involved when the exception it thrown. Clearly the pointcut is matching the exception since when I remove the pointcut, the aop method calls are gone.Code:java.lang.Exception: testing at com.test.cwp.integration.exchange.hub.ExchangeHubMessageListener.processMessage(ExchangeHubMessageListener.java:33) at com.test.cwp.integration.exchange.hub.ExchangeHubMessageListener.onMessage(ExchangeHubMessageListener.java:19) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:85) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:58) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java(Compiled Code)) at java.lang.reflect.Method.invoke(Method.java(Compiled Code)) at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:301) at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:50) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:160) at org.springframework.aop.aspectj.AspectJAfterThrowingAdvice.invoke(AspectJAfterThrowingAdvice.java:54) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) at $Proxy7.onMessage(Unknown Source) at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:510) at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:445) at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:414) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:309) at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:254) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:870) at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:810) at java.lang.Thread.run(Thread.java:570)
I'm really out of ideas. Does anyone have any thoughts? I'm using Spring 2.5.0 on WAS 5.1 with JDK 1.4.2
Thanks!


Reply With Quote