-1

I want to use spring aspect for my crosscutting process like a before or after handler in my process execution lifetime. For example

What I want before a method I want to execute my handler and due to its response I want to finialize myprocess and return custom response.

In example in stop condition should I throw custom exception to stop process that time how can I handle my return response ,I want to give meaningfull object at the client.What is the best way to do that?

@Before
MyHandler()
{

bool stop=checkvalue();
if(stop==false)
continue...
else
{
  //break all process
    and return custom response to client
  //throw exception but meaningfullresponse??
}

}
Bilgehan
  • 1,135
  • 1
  • 14
  • 41

1 Answers1

0

Instead of using Before advice, I would use Around advice to wrap the method invocation and call checkValue() on beforehand:

@Around("someJoinpoint")
public Object MyHandler(ProceedingJoinPoint pjp) {
    if (!checkvalue()) {
        return pjp.proceed();
    } else {
        return someCustomResponseToClient();
    }
}

More info on Around advice can be found in the Spring documentation.

Michiel
  • 2,914
  • 1
  • 18
  • 27