You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My resources return CompletionStage and then I have a MessageBodyWriter for MyType. The issue is that if the CompletionStage is not immediately complete upon returning from resource method then the MessageBodyWriter fails because the ServletContext accessed from HttpServletRequest has already been invalidated and set to null (by Jetty 11).
Is there a way around this so that the HttpServletRequest (injected with Provider in MessageBodyWriter constructor and accessed in the writeTo method) becomes valid again? Or is this just a bug that needs to be fixed in Jersey?
The text was updated successfully, but these errors were encountered:
I'm injecting Provider<HttpServletRequest>into the MessageBodyWriter constructor, which in writeTo returns a proxy to the correct object. This part is fine. The issue is that because of the asynchronous nature of returning a CompletionStage<MyType> from the resource the request has not been reassociated correctly with the servletcontext. There's some scope fixing (or similar) that needs to happen before calling writeTo, when the result is a CompletionStage. The main issue is that HttpServletRequest.getServletContext needs to return the correct value.
The injected HttpServletRequest provided does not belong to the current request
Jetty ended the current request and set the HttpServletRequest.getServletContext to return null.
You might be trying to provide request-scoped information outside of a request. The JAX-RS way which avoids the injection is to utilize WriterInterceptor.getProperty during the entity writing and setting up the property in the resource class or in the ContainerFilter where the request-scoped information is available.
My resources return CompletionStage and then I have a MessageBodyWriter for MyType. The issue is that if the CompletionStage is not immediately complete upon returning from resource method then the MessageBodyWriter fails because the ServletContext accessed from HttpServletRequest has already been invalidated and set to null (by Jetty 11).
Is there a way around this so that the HttpServletRequest (injected with Provider in MessageBodyWriter constructor and accessed in the writeTo method) becomes valid again? Or is this just a bug that needs to be fixed in Jersey?
The text was updated successfully, but these errors were encountered: