0

I have the following method

 @AutoHandling(slot = FunctionalArea.PRE_MAIN_MENU) @RequestMapping(method = RequestMethod.GET) public String navigation(ModelMap model) { logger.debug("navigation"); ... //First time to the Main Menu and ID-Level is ID-1 or greater if (!callSession.getCallFlowData().isMainMenuPlayed() && callSession.getCallFlowData().getIdLevel() >= 1) { // Call Auto Handling logger.info("Call AutoHandling"); autoHandlingComponent.processAutoHandling(); } ... return forward(returnView); } 

Basically what I want to do, is have a pointcut on processAutoHandling() But in the @After, I need to use the slot() for @AutoHandling

I tried this, but it does not get called

@Pointcut("execution(* *.processAutoHandling())") public void processAutoHandleCall() { logger.debug("processAutoHandleCall"); } @Around("processAutoHandleCall() &&" + "@annotation(autoHandling) &&" + "target(bean) " ) public Object processAutoHandlingCall(ProceedingJoinPoint jp, AutoHandling autoHandling, Object bean) throws Throwable { ... 

2 Answers 2

2

You can use the wormhole design pattern for this. I am illustrating using AspectJ byte-code based approach and syntax, but you should be able to get the same effect using an explicit ThreadLocal if you are using Spring's proxy-based AOP.

pointcut navigation(AutoHandling handling) : execution(* navigation(..)) && @annotation(handling); // Collect whatever other context you need pointcut processAutoHandleCall() : execution(* *.processAutoHandling()); pointcut wormhole(AutoHandling handling) : processAutoHandleCall() && cflow(navigation(handling)); after(AutoHandling handling) : wormhole(hanlding) { ... you advice code ... access the slot using handling.slot() } 
Sign up to request clarification or add additional context in comments.

1 Comment

Excellent answer as usual (+1). @Mick read his book AspectJ in Action, 2nd ed for more info about the wormhole pattern
0

a) It can't work, you are trying to match two different things:

@Around("processAutoHandleCall() &&" + "@annotation(autoHandling) &&" + "target(bean) " ) 

processHandleCall() matches the inner method execution autoHandlingComponent.processAutoHandling() while @annotation(autoHandling) matches the outer method execution navigation(ModelMap model)

b) since you are obviously trying to advise a Controller, there are a few caveats:

  • if you use proxy-target-class=true everything should work as is, just make sure you don't have any final methods
  • if you don't, all your controller methods must be backed by an interface and the @RequestMapping etc annotations must be on the interface, not the implementing class as described in this section of the Spring MVC reference docs

3 Comments

That can I add the Annotation at the actual Call?
@Mick You can't annotate a method call, but you could annotate the processAutoHandling() method.
I have that, but my issue now is I need to actually redirect the return value for the controller, but by just using processAutoHandling() I cannot for a return value for NavigationController can I?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.