Comments (3)
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.
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.
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)
- org.glassfish.jersey.message.internal.MessagingBinders$EnabledProvidersBinder.bindToBinder A class javax.activation.DataSource for a default provider MessageBodyWriter<javax.activation.DataSource> was not found. The provider is not available. HOT 1
- Remove `Content-Length` header when encoding response content
- Did Jersey 3.1.4 remove support for JDK 11? HOT 3
- REST Client causes out of memory even if close is called. HOT 4
- 3.1.4 broken release, JettyConnectorProvider always throws exception HOT 2
- Shall we start a 4.0 branch? HOT 8
- Getting rid of `new File(URL.getPath()).toURI()` HOT 3
- @Context annotation declaration of HttpServletReqeuest object in parent reference is passing the first time API hit values to the resource always HOT 3
- Unbounded memory use of LRUMap due to removed access synchronization in ProviderBase HOT 6
- Can I add custom formatting settings to Gson in jersey-media-json-gson? HOT 2
- How to disable JaxRSFeature.READ_FULL_STREAM? HOT 2
- jersey-netty-connector: response body not processed when content-length/transfer-encoding headers are not present
- jersey-media-json-binding 3.0.12 has two impls of parsson on classpath
- InjectionManagerFactory not found in OSGi http service with Declarative service HOT 3
- 2.x/examples/osgi-helloworld-webapp does not work with Jetty 12 but with Jetty 10 HOT 12
- Connectivity issues masked by ProcessingException: Already connected HOT 1
- IllegalAccessException in jersey-client-proxy when `@BeanParam` annotated class contains private fields
- Headers modified by MultiPartWriter are not sent HOT 2
- HttpUrlConnector and JettyConnector doesn't log the headers modified by MultiPartWriter HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jersey.