Giter Site home page Giter Site logo

Comments (3)

jansupol avatar jansupol commented on June 30, 2024

The MessageBodyWriter is a singleton, it is not recreated for each request. Whatever injected, it would not be aligned with the current request.

Possibly, you can try to inject InjectionManager class and try to call injectionManager.getInstance(HttpServletRequest.class) in the writeTo method.

The lifecycle of HttpServletRequest class is handled by the Servlet container, i.e. by Jetty. If Jetty invalidates, Jersey cannot prevent that.

from jersey.

rickardoberg avatar rickardoberg commented on June 30, 2024

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.

from jersey.

jansupol avatar jansupol commented on June 30, 2024

There are two possibilities:

  • 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.

from jersey.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.