3

I am trying to log HttpServletRequest content through aop in async mode. The method on which pointcut in implement has HttpServletRequest as method argument. I am not able to access it in async mode, though the code works fine without the @Async annotation.

@Async
@AfterReturning(pointcut = "execution(* com.web.dto.util.response.impl.ResponseImpl.prepareResponseDTO(..))", returning = "object")
    public void logSearchJSON(JoinPoint joinPoint, final Object object) {
        try {
            List<Object> objects = getActivityParams(joinPoint);

            UserActivity userPersonalization = null;
            HttpServletRequest httpServletRequest = (HttpServletRequest) objects.get(0);
            if (httpServletRequest.getRequestURI().contains(UserActivityConstant.filter)) 

httpServletRequest.getRequestURI() returns null.

It was working fine without the @Async annotation

vineeth sivan
  • 510
  • 3
  • 18

1 Answers1

0

Have you correctly declared a task executor?

You can do it in that way in your Spring context:

<task:annotation-driven executor="TaskExecutor"/>
<task:executor id="TaskExecutor"
                   pool-size="2-5"
                   queue-capacity="50"
                   keep-alive="120"
                   rejection-policy="CALLER_RUNS"/>

You can also do it in a @Configuration class.

Lucas.de
  • 555
  • 8
  • 17