0

I have to log the request parameters/ form data before any bean/controller method is called. My application is written in spring web flow.

What would be the best way to implement it?

neha
  • 1
  • 1
  • 1

3 Answers3

0

I think Spring AOP can help you.

Define a Pointcut expression that selects all your controller method and use the @Before advice to log the parameters

Example:

@Before("execution(@controllers.package * *(..))")
public void logArguments(JoinPoint joinPoint) throws Throwable {
    logger.debug("Entering method - Arguments : " + joinPoint.getArgs());
}
Adolfo
  • 798
  • 1
  • 7
  • 15
0

If you need to intercept each request before reaching the controller, you can use interceptor. You will have to extend your class with HandlerInterceptorAdapter.You may override it's preHandle method to intercept each request before it reaches controller.You will get access to request and response objects in this method to change your target page or url.

Sumit Desai
  • 1,542
  • 9
  • 22
-1

You don't need AOP/Aspectj, you can do that with a Servlet Filter

Adisesha
  • 5,200
  • 1
  • 32
  • 43
  • Well then we can do anything with pure JSP/Servlet :) – Ishan Liyanage Sep 17 '20 at 03:39
  • Struts, Spring MVC, Spring Security etc are build on pure Servlet framework. You can check code of Spring security on how calls are intercepted using filters. AOP or Servlet Filters, you choose it based on the problem. – Adisesha Sep 20 '20 at 14:12
  • exactly my point. If we want to write pure JSP/Servlet, then we can do anything and no need Spring. Author is asking how to do it with Spring. – Ishan Liyanage Sep 21 '20 at 09:51
  • ok, what I am trying to say is if you are using Spring, it doesn't mean that you must use AOP. The question was 7 years old, lot of things have improve, check https://stackoverflow.com/questions/33744875/spring-boot-how-to-log-all-requests-and-responses-with-exceptions-in-single-pl – Adisesha Sep 21 '20 at 11:48