I want to hijack an HTTPServletRequest and log some values from it using AspectJ. However, what ends up in the JoinPoint is a “RequestFacade” object. There doesn’t seem to be much that I can do with this object. Is my logging strategy all wrong? How can I get useful information from the HttpServletRequest? If I have to unwrap it prior to calling a method, that sort of defeats the purpose of AOP in my application.
I am using a Glassfish server, if that makes a difference.
@Before("execution(* Service.testAuditRecord(..))")
public void logBefore(JoinPoint joinPoint) {
System.out.println("logBefore --->" + joinPoint.getSignature().getName());
System.out.println("logBefore--->Args : " + Arrays.toString(joinPoint.getArgs()));
}
The RequestFacade record
INFO: logBefore --->testAuditRecord
INFO: logBefore--->Args : [org.apache.catalina.connector.RequestFacade@4dbfa7d0]
HttpServletRequestis an interface. Each servlet container has its own implementation.org.apache.catalina.connector.RequestFacadeis one of them.That being said you are free to use any of the methods of
HttpServletRequest, without bothering about the actual implementation.What is the signature of
Service.testAuditRecord()? Does it takeHttpServletRequestas an argument? If so, AspectJ should give you a strongly typed instance without much hassle. Try this: