I have a simple aspect as you can see below:
@Aspect
@Component
public class ApiCallLogAspect {
@AfterReturning(pointcut = "execution(* com.example.web.rest.api.ApiResource.getAddress (String)) && args(mobile))", argNames = "mobile")
public void endpointAfterReturning(String mobile) throws InterruptedException {
Thread.sleep(10000);
System.out.println("This is aspect log.");
}
}
}
And this is getAddress
method in ApiResource
class, as you see this is very simple and fast method:
@RestController
@RequestMapping("/api/v1")
public class ApiResource {
public String getAddress(String mobile) {
return "This is your address";
}
}
Now, when i call getAddress
method the Thread.sleep(10000)
in aspect cause to delay in execution of getAddress
method.
How can i seprate execution of aspect from joinpoint method?
NOTE
I used Thread.sleep(10000)
to demonstrate my problem. I want to do something after a method executed, and don't want to affect on main method, either delay, exception or anything. what should i use to do for this purpose?
UPDATE
My goal is to log requests to my rest apis and store call details, such as ip, arguments values, request headers and returned value.