Results 1 to 2 of 2

Thread: How to get the HttpServletResponse object in the around advice

  1. #1
    Join Date
    Dec 2011
    Posts
    1

    Default How to get the HttpServletResponse object in the around advice

    Code:
    @Component
    @Aspect
    public class SpringAspect {
        @Around("execution(* cn.luna.web.controller.*.*(..))")
        public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
            Method method=((MethodSignature)pjp.getSignature()).getMethod();
            //Here I wanna get the HttpServletRequest request and the HttpServletReponse response,I don't know how to do.
            System.out.println("enter the method:"+method);
            Object result = pjp.proceed();
            System.out.println("exit the method");
            return result;
        }
    }
    I use spring mvc to develop my project.

    Thanks for help!!

  2. #2
    Join Date
    Nov 2010
    Posts
    24

    Default

    I was looking for the same thing... I found the solution in this other topic: http://forum.springsource.org/showth...-inside-aspect

    Code:
    //ServletRequestAttributes may be null, check it first.
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Kind regards.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •