How to transfer data from a ContainerRequestFilter to a resource in a Jersey structure

I tried using ContainerRequestFilter for my webservice application to authenticate the input request. Once the request is authenticated, I need to pass an object to reprocess all the information. can someone please let me know how we can achieve this?

Thank you for your help.

~ Ms

+4
source share
1 answer

In your filter, you need to execute a servlet request:

@Context private transient HttpServletRequest servletRequest; 

And save your data as an attribute:

 this.servletRequest.setAttribute("My data", myObject); 

And then in the resource you can pull out servletRequest and use:

 Object myObject = this.servletRequest.getAttribute("My data"); 
+9
source

All Articles