Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jersey-dev] Sharing/caching object in request scope

Hi,

It's odd you have injected the org.glassfish.jersey.server.ContainerRequest, since it does not inherit from HttpServletRequest.

--Jan

On 20.04.2020 22:45, Martynas Jusevičius wrote:
Hi,

I'm porting 1.19 code to 2.30.1 which stores objects as
HttpServletRequest attributes.

This was done to improve performance - if injection providers were
called multiple times, we didn't want to do expensive processing
multiple times to get the injectable object. A request filter would
get the object, store it HttpServletRequest, and providers would
simply take it from the attribute:

public class ApplicationFactory
{
     public Application provide()
     {
         return (Application)httpServletRequest.getAttribute(LAPP.Application.getURI());
     }
...

I wonder if there's a better approach?

In any case, this kind of code does not seem to work anymore. So far
it seems that the request filters get injected one HttpServletRequest
instance while a factory gets a different one:
ApplicationFilter: org.glassfish.jersey.server.ContainerRequest@7a11342
AuthFilter: org.glassfish.jersey.server.ContainerRequest@7a11342
ApplicationFactory: org.apache.catalina.connector.RequestFacade@3515d98a

ApplicationFilter sets Application object as a HttpServletRequest
attribute, ApplicationFactory is supposed to retrieve it and inject it
into AuthFilter.

But if they don't share HttpServletRequest, they don't share the
attributes and our approach breaks down.

Any suggestions? Thanks.

Martynas
_______________________________________________
jersey-dev mailing list
jersey-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jersey-dev


Back to the top