Announcement Announcement Module
No announcement yet.
passing something in aop from advice to target Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • passing something in aop from advice to target

    Can i pass data from my advice to my target and vice versa - or should i not be using aop for this

    I want to wrap a method with some logging statements, but those logging statements need a transactionId that was prepared earlier.

    How to i get the transactionId to the advice?


  • #2
    If such transaction ID is passed as method parameter to a target method then yes you can intercept the arguments:

    @Before(. . .your pointcut . .)
    public void fooAdvice(JoinPoint jPoint){
         Object[] arguments = jPoint.getArgs();
         . . . . . . . . . . .
    You can also bind parameters to a strong types (read chapter 6, 7 of reference manual for more details on Spring AOP)

    If, however, such transaction id is not passed as argument to a method, but is an instance variable of a calling class, then you can use AspectJ call pointcut expression to access callers context.


    • #3
      You see thats the problem.

      I dont want to pass transactionId in the parameter list, as it is generated in the aspect.

      What happens is, i have a class with lots of methods that calls a web service. I wrap these methods using AOP and in the aspect it calls a stored procedure to generate a transactionId. However, the call to the web service also needs this transactionId - so i need to get this Id back into the method that is being called.

      I could add it as a parameter, but then the API to the class suggests that this id should be passed when the method is called - but i wont have it at that point, so i would have to call it will null as the id, until the aspect filled in the details - i dont really want to do that.

      Any ideas or suggestions on how to work around this? Maybe its not possible.


      • #4
        I tried delegating the call inside the class, but then spring seems to ignore the aop on it: eg:

        //This is the public api method...
         public AvailableMoneyWSResultTO getTheMoney(PlayerTO playerTO, PokerTableTO pokerTableTO) throws BrokerUnavailableException {
             return getAvailableMoney(playerTO, pokerTableTO, null);
        //This method makes the call and is configured to be wrapped by AOP
        //But spring is ingoring this.
        private AvailableMoneyWSResultTO getAvailableMoney(PlayerTO playerTO, PokerTableTO pokerTableTO, BrokerTransactionID id) throws BrokerUnavailableException {
        ....//implementation here


        • #5
          calls inside the class are not going through the proxy and are therefore not advised...