Results 1 to 3 of 3

Thread: getting the method arguments in an afterthrowing advice

  1. #1
    Join Date
    Dec 2005
    Location
    California
    Posts
    63

    Default getting the method arguments in an afterthrowing advice

    Hi
    I want to log all the method arguments when any public method fails with an afterthrowing advice. How do I make the following generic so that I do not need a pointcut for methods with 1 argument, methods with 2, etc.:
    Code:
    <aop:config >
      <aop:aspect id="legacyDaoExceptionTranslator" ref="exceptionLogger">
    	<aop:after-throwing method="doLogErrors"
    		pointcut="execution(public * com..FeedProcessor.*(..)) and args(modelId,..)"
    		throwing="ex"/>
      </aop:aspect>
      <aop:aspect id="legacyDaoExceptionTranslator2" ref="exceptionLogger">
    	 <aop:after-throwing method="doLogErrors2"
    		pointcut="execution(public * com..FeedProcessor.*(..)) and args(modelId,modelId2,..)"
    		throwing="ex"/>
      </aop:aspect>
    </aop:config>
    Janos

  2. #2
    Join Date
    Aug 2006
    Location
    Brooklyn
    Posts
    556

    Default

    Try the getArgs method in ProceedingJoinPoint, which is passed to your advice. You can leave out args() from the pointcut definition.

  3. #3
    Join Date
    Dec 2005
    Location
    California
    Posts
    63

    Default args vs. ProceedingJoinPoint

    That was an excellent idea, thanks, it worked.
    I am using ProceedingJoinPoint in around advices, but I could not make args work in a generic way. Even when simple examples work from Eclipse, args do not work when Maven compiles the classes, I am not sure which compiler switch is wrong because the argument names can not be looked and -g does not solve it.
    Janos

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •