0

I have spring boot application which has both Jersey endpoints and Spring mvc endpoints. I would like to intercept request and response from a single point for both types of enpoint.

So far I know there is three option to do that. Those are- Filter, Spring Interceptor and Spring @ControllerAdvice. Among them Interceptor and ControllerAdvice is only applicable for Spring endpoints and it doesn't work for Jersey endpoints. Only the Filter is so far working for both endpoints. Is there any other way I can intercept request/response both for Jersey and Spring mvc?

Thanks in advance.

pijushcse
  • 510
  • 9
  • 31
  • Filter sounds perfect for both. What's the problem? – Strelok Mar 19 '18 at 22:07
  • My requirements is to log both request and response body. It looks like I need to do lots of low-level (OutputStream etc) coding to extract the content from `HttpServletRequest` and `HttpServletResponse` object. This is the part I wanted to avoid. I was wondering if there any Spring boot way to do it both for Spring mvc and Jersey endpoints. – pijushcse Mar 20 '18 at 06:00
  • There is `org.springframework.web.filter.CommonsRequestLoggingFilter` that may or may not be enough for your needs. You can write your own, using the above as a reference. – Strelok Mar 20 '18 at 06:07

1 Answers1

0

Another way would be to use Spring's @RequestBodyAdvice and @ResponseBodyAdvice if you are on Spring 4.2+ but I'm not sure it will work with Jersey. This will depend on your project setup. All in all, standard JEE Filter is the easiest choice here.

Karol Dowbecki
  • 43,645
  • 9
  • 78
  • 111