This is what I was trying to do in my class:
MessageBodyWriter
@Context
ContainerRequestContext crc;
...which was throwing this exception...
Exception
java.lang.IllegalStateException: Not inside a request scope."
weblogic.application.ModuleException: java.lang.IllegalStateException: Not inside a request scope.
at weblogic.application.internal.ExtensibleModuleWrapper.start(ExtensibleModuleWrapper.java:140)
...
Caused By: java.lang.IllegalStateException: Not inside a request scope.
at jersey.repackaged.com.google.common.base.Preconditions.checkState(Preconditions.java:173)
at org.glassfish.jersey.process.internal.RequestScope.current(RequestScope.java:233)
at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(RequestScope.java:158)
at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2022)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:114)
at org.jvnet.hk2.internal.ServiceHandleImpl.getService(ServiceHandleImpl.java:88)
at org.glassfish.jersey.internal.inject.ContextInjectionResolver.resolve(ContextInjectionResolver.java:126)
...
The solution was to inject a ResourceContext instead and then look up the ContainerRequestContext when needed.
So my injection code became:
MessageBodyWriter
@Context
ResourceContext resourceContext;
...and then to get the ContainerRequestContext I simply got it from the ResourceContext like so:
MessageBodyWriter
ContainerRequestContext crc =
resourceContext.getResource(ContainerRequestContext.class);
This worked with Jersey 2.x (2.25.1 in my case).
-i