I try to use AOP to wrap of the Http response. I have the following code:
@Component
@Aspect
public class ControllerResponse {
@AfterReturning(pointcut = "execution(* hu.example.app.kafkaexample.controller.Controller.*(..))", returning = "entity")
public ResponseEntity<Object> logMethodCall(JoinPoint jp, Object entity) throws Throwable {
System.out.println("Inside of the aop");
ResponseEntity response = new ResponseEntity(entity, HttpStatus.BAD_REQUEST);
return response;
}
}
I can get the log record on console, but the api call are not manipulated by the setting I did. My question is: can I manipulate the response type by aop? If yes, why is my code bad?
Based on kriegaex comment, using @Around
instead of @AfterReturning
is the approach which allows to manipulate the response. I tried and worked for me.