I was not able to inject HttpServletRequest in ContainerRequestFilter via @Context in Jersey 2.22.1 using weblogic 12.1.3. I researched several places that this issue exists and
As an alternative to typically preferred injection by @Context
, @Inject
, or @Autowire
, you can inject HttpServletRequest into a request-scoped bean using Spring's static method:
HttpServletRequest request=
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
Note that this approach is not ideal, because static methods make your code harder to test and make your code more rigid.
It seems this is a bug with Weblogic 12.1.3. I tried upgrading to Weblogic 12.2.1 and injecting HttpServletRequest
using @Context
works correctly even inside ContainerRequestFilter
.