Perhaps you should get these values from the ContainerRequestContext param
of the filter method ?
Generally filters are outside of the request scope, because they work as
singletons (might be wrong here) and you should be very careful with
synchronization of it's contents.
2013/9/10 Chris Wright <chris_at_ausregistry.com.au>
> Further to this, I get the same error when trying to inject
> HttpServletRequest into a ContainerRequestFilter... have I configured
> something wrong... everything I look out seems to indicate that this should
> work?****
>
> ** **
>
> @Context****
>
> HttpServletRequest request;****
>
> ** **
>
> ** **
>
> Thanks****
>
> ** **
>
> Chris****
>
> *From:* Chris Wright
> *Sent:* Tuesday, 10 September 2013 10:40 AM
> *To:* 'users_at_jersey.java.net'
> *Subject:* Not inside request scope in a ContainerRequestFilter****
>
> ** **
>
> Hi all, ****
>
> ** **
>
> I am having trouble getting Jersey 2.2 to inject a request scope
> injectable into a ContainerRequestFilter. The injectable works fine when
> injected into a resource, but I can't inject it into a Filter - it seems to
> me that this should be allowed am I missing something?****
>
> ** **
>
> The exception is:****
>
> ** **
>
> *javax.servlet.ServletException*:
> org.glassfish.jersey.servlet.ServletContainer-483429798_at_2f4865c==org.glassfish.jersey.servlet.ServletContainer,-1,false
> ****
>
> at org.eclipse.jetty.servlet.ServletHolder.initServlet(*
> ServletHolder.java:563*)****
>
> at org.eclipse.jetty.servlet.ServletHolder.initialize(*
> ServletHolder.java:351*)****
>
> at org.eclipse.jetty.servlet.ServletHandler.initialize(*
> ServletHandler.java:800*)****
>
> at org.eclipse.jetty.servlet.ServletContextHandler.startContext(*
> ServletContextHandler.java:288*)****
>
> at org.eclipse.jetty.server.handler.ContextHandler.doStart(*
> ContextHandler.java:731*)****
>
> at org.eclipse.jetty.util.component.AbstractLifeCycle.start(*
> AbstractLifeCycle.java:69*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.start(*
> ContainerLifeCycle.java:108*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(*
> ContainerLifeCycle.java:90*)****
>
> at org.eclipse.jetty.server.handler.AbstractHandler.doStart(*
> AbstractHandler.java:58*)****
>
> at org.eclipse.jetty.server.handler.ContextHandlerCollection.doStart(
> *ContextHandlerCollection.java:156*)****
>
> at org.eclipse.jetty.util.component.AbstractLifeCycle.start(*
> AbstractLifeCycle.java:69*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.start(*
> ContainerLifeCycle.java:108*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(*
> ContainerLifeCycle.java:90*)****
>
> at org.eclipse.jetty.server.handler.AbstractHandler.doStart(*
> AbstractHandler.java:58*)****
>
> at org.eclipse.jetty.util.component.AbstractLifeCycle.start(*
> AbstractLifeCycle.java:69*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.start(*
> ContainerLifeCycle.java:108*)****
>
> at org.eclipse.jetty.server.Server.start(*Server.java:342*)****
>
> at org.eclipse.jetty.util.component.ContainerLifeCycle.doStart(*
> ContainerLifeCycle.java:90*)****
>
> at org.eclipse.jetty.server.handler.AbstractHandler.doStart(*
> AbstractHandler.java:58*)****
>
> at org.eclipse.jetty.server.Server.doStart(*Server.java:290*)****
>
> at org.eclipse.jetty.util.component.AbstractLifeCycle.start(*
> AbstractLifeCycle.java:69*)****
>
> at com.discoverydns.dnsapi.Main.runServers(*Main.java:160*)****
>
> at com.discoverydns.dnsapi.Main.main(*Main.java:149*)****
>
> Caused by: A *MultiException* has 3 exceptions. They are:****
>
> 1. *java.lang.IllegalStateException*: Not inside a request scope.****
>
> 2. *java.lang.IllegalArgumentException*: While attempting to resolve the
> dependencies of com.discoverydns.dnsapi.rest.injectors.TestFilter errors
> were found****
>
> 3. *java.lang.IllegalStateException*: Unable to perform operation:
> resolve on com.discoverydns.dnsapi.rest.injectors.TestFilter****
>
> ** **
>
> at org.jvnet.hk2.internal.Collector.throwIfErrors(*Collector.java:88
> *)****
>
> at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(*
> ClazzCreator.java:246*)****
>
> at org.jvnet.hk2.internal.ClazzCreator.create(*ClazzCreator.java:328
> *)****
>
> at org.jvnet.hk2.internal.SystemDescriptor.create(*
> SystemDescriptor.java:454*)****
>
> at org.jvnet.hk2.internal.SingletonContext.findOrCreate(*
> SingletonContext.java:119*)****
>
> at org.jvnet.hk2.internal.Utilities.createService(*
> Utilities.java:2296*)****
>
> at org.jvnet.hk2.internal.ServiceHandleImpl.getService(*
> ServiceHandleImpl.java:98*)****
>
> at org.jvnet.hk2.internal.ServiceHandleImpl.getService(*
> ServiceHandleImpl.java:87*)****
>
> at
> org.glassfish.jersey.internal.inject.Providers.getAllRankedProviders(*
> Providers.java:234*)****
>
> at
> org.glassfish.jersey.server.ApplicationHandler.getProcessingProviders(*
> ApplicationHandler.java:616*)****
>
> at org.glassfish.jersey.server.ApplicationHandler.initialize(*
> ApplicationHandler.java:409*)****
>
> at org.glassfish.jersey.server.ApplicationHandler.access$500(*
> ApplicationHandler.java:161*)****
>
> at org.glassfish.jersey.server.ApplicationHandler$3.run(*
> ApplicationHandler.java:286*)****
>
> at org.glassfish.jersey.internal.Errors$2.call(*Errors.java:289*)***
> *
>
> at org.glassfish.jersey.internal.Errors$2.call(*Errors.java:286*)***
> *
>
> at org.glassfish.jersey.internal.Errors.process(*Errors.java:315*)**
> **
>
> at org.glassfish.jersey.internal.Errors.process(*Errors.java:297*)**
> **
>
> at org.glassfish.jersey.internal.Errors.processWithException(*
> Errors.java:286*)****
>
> at org.glassfish.jersey.server.ApplicationHandler.<init>(*
> ApplicationHandler.java:283*)****
>
> at org.glassfish.jersey.servlet.WebComponent.<init>(*
> WebComponent.java:298*)****
>
> at org.glassfish.jersey.servlet.ServletContainer.init(*
> ServletContainer.java:167*)****
>
> at org.glassfish.jersey.servlet.ServletContainer.init(*
> ServletContainer.java:349*)****
>
> at javax.servlet.GenericServlet.init(*GenericServlet.java:244*)****
>
> at org.eclipse.jetty.servlet.ServletHolder.initServlet(*
> ServletHolder.java:542*)****
>
> ... 22 more****
>
> Caused by: *java.lang.IllegalStateException*: Not inside a request scope.*
> ***
>
> at com.google.common.base.Preconditions.checkState(*
> Preconditions.java:149*)****
>
> at org.glassfish.jersey.process.internal.RequestScope.current(*
> RequestScope.java:226*)****
>
> at org.glassfish.jersey.process.internal.RequestScope.findOrCreate(*
> RequestScope.java:154*)****
>
> at org.jvnet.hk2.internal.Utilities.createService(*
> Utilities.java:2296*)****
>
> at org.jvnet.hk2.internal.ServiceHandleImpl.getService(*
> ServiceHandleImpl.java:98*)****
>
> at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(*
> ServiceLocatorImpl.java:569*)****
>
> at org.jvnet.hk2.internal.ThreeThirtyResolver.resolve(*
> ThreeThirtyResolver.java:77*)****
>
> at org.jvnet.hk2.internal.ClazzCreator.resolve(*
> ClazzCreator.java:208*)****
>
> at org.jvnet.hk2.internal.ClazzCreator.resolveAllDependencies(*
> ClazzCreator.java:231*)****
>
> ... 44 more****
>
> ** **
>
> Thanks****
>
> ** **
>
> Chris****
>
--
Z poważaniem
Andrzej Le¶kiewicz