This question took off because I read Arjan Tijms blogpost about JSF 2.3. There, he list all JSF artifacts which can be injected via CDI. Although HttpServletRequest
is mentioned, HttpServletResponse
doesn't appear on the said list which I didn't believe at first.
To try things out, I setup a simple Server (JavaEE8, Wildfy22):
@Inject private HttpServletRequest req;
works just fine@Inject private HttpServletResponse res;
throwsDeploymentException: WELD-001408: Unsatisfied dependencies for type HttpServletResponse
I don't see why HttpServletResponse
should not be injectable. After all, the goal was to replace convulent method chains by a concise injection.
In case of HttpServletRequest
, FacesContext.getCurrentInstance().getExternalContext().getRequest();
can now be shortened to the above injection.
Well, in case of HttpServletResponse
, there is no injection candidate to replace FacesContext.getCurrentInstance().getExternalContext().getResponse();
as shown above.
Summarized: Why is HttpServletRequest
injectable via CDI but HttpServletResponse
isn't?