Results 1 to 5 of 5

Thread: passing something in aop from advice to target

  1. #1
    Join Date
    Feb 2008
    Posts
    27

    Default 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?

    Thanks
    Dave

  2. #2
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

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

    Code:
    @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. #3
    Join Date
    Feb 2008
    Posts
    27

    Default

    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. #4
    Join Date
    Feb 2008
    Posts
    27

    Default

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

    Code:
    //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. #5
    Join Date
    Nov 2007
    Posts
    420

    Default

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

Posting Permissions

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