Passing User Data from Jersey Filter Service to Jersey Endpoint Support

We are in an OSGI environment using the Jetty-Felix HTTP server.

We have a package that implements the Jersey filter service.

Another kit implements the Jersey endpoint.

In the filter, we have set some custom properties using ContainerRequestContext.setProperty ().

My question is, how can I access these properties from the endpoint methods?

@ The context doesn't seem to give me access to everything I can return the properties to.

thank

+3


source to share


1 answer


Actually, in the filter we use ContainerRequestContext.setProperty (key, value);

At the endpoint, we can get it with value = HttpServletRequest.getAttribute (key);



Then the problem was that I was trying to insert @Context as an instance of the class. But since this is a request, it must be entered as a function parameter, for example:

@GET
@Path("/something")
@Produces({MediaType.APPLICATION_JSON})
public AClass getSomething(@Context HttpServletRequest servletRequest) {
   // Retrieve my thing from the filter
   MyThing thing = (MyThing)servletRequest.getAttribute("the-key-to-my-thing");

   return new AClass(mything);
}

      

+2


source







All Articles