First: I know this problem actually requires a redesign of the application, which will be done later, but first I am looking into a short-term workaround.
Framework: Java EE 7.
Problem:
I have a service which injects HttpServletRequest
to read 1 (optional) request header (nothing else is done with it). This makes it only useful inside a RequestContext, not usable in unmanaged beans (eg. a Runnable).
When using BeanManager to programatically lookup this service I ofcourse get this error:
WELD-001303: No active contexts for scope type javax.enterprise.context.RequestScoped
.
Questions:
- Can I "ignore" this error and just let the field be set/kept as null?
- Is it possible to create a custom Producer for HttpServletRequest which - in certain circumstances - ignores WELD-001303 errors and returns null?
- I know I can probably create a custom Scope which can tackle this problem for me, but that no longer is a small short-term workaround. Or is it easier than creating a Scope, Context, Extension and registering it?
- What is the class called which actually produces the HttpServletRequest when injected?
- Are there more ideas to try?