If I'm building a Dropwizard application, how do I inject HttpHeaders using Dagger?
- Inject
ResourceContextinto your class. - Call the
httpHeaders()method of theResourceContextobject. - Add
RequestContextModuleto your Dagger component.- This Dagger module only depends on the Dropwizard
Environment.
- This Dagger module only depends on the Dropwizard
If you want a code example, see ExampleResource and ExampleApp.
ResourceContext contains:
HttpHeadersUriInfoSecurityContextRequestHttpServletRequestHttpServletResponse
Limitation
This context is thread-local; it is only accessible from the thread that handles the request.
(The same limitation would apply if you used HK2 to inject Provider<HttpHeaders> into a class.)