How to forward the HttpServletRequest and HttpServletResponse object to another service?

320 Views Asked by At

I have built a service to extract various details like header, request uri, status code etc from an HttpServletRequest and HttpServletResponse object. I want to extract this information and store it in mongo. Now, I have other services with a servlet filter in them. What I want to do is, whenever a request comes in, I want it to get executed also and simultaneously forward the HttpServletRequest & HttpServletResponse object to the first service so that it can extract data from it and store it somewhere. Any idea how this can be done? I want the first service to be generic, it will have an API that will accept request and response objects of various other services and store its data in mongo. The extraction of fields like request uri, status code etc needs to happen in the generic service only

2

There are 2 best solutions below

0
tushar On

Use response.sendRedirect("url")

1
Kaushik Shaw On

As per my understanding of this question, you can call that service passing the same request and response object and get the data from that. If you give the code snippet it will be easy to describe.

Hope this answer will help you.