jersey
  1. jersey
  2. JERSEY-2241

Jersey server throwing a IllegalStateException about not being in RequestScope

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 2.4.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:

      Glassfish 4.0.1 b03, Ubuntu 12.04

      Description

      When the @Context for URIInfo is in the wrong location the following error is thrown when the uriInfo is accessed.

      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.MethodInterceptorImpl.intercept(MethodInterceptorImpl.java:80)
              at org.glassfish.jersey.internal.inject.UriInfoInjectee$$EnhancerByCGLIB$$ef535da6.toString(<generated>)
              at java.lang.String.valueOf(String.java:2854)
              at java.lang.StringBuilder.append(StringBuilder.java:128)
              at au.csiro.esa.authrest.rest.user.resource.UserResource.setUriInfo(UserResource.java:68)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at org.glassfish.hk2.utilities.reflection.ReflectionHelper.invoke(ReflectionHelper.java:1011)
              at org.jvnet.hk2.internal.Utilities.justInject(Utilities.java:816)
              at org.jvnet.hk2.internal.ServiceLocatorImpl.inject(ServiceLocatorImpl.java:801)
              at org.glassfish.jersey.gf.cdi.CdiComponentProvider$1.inject(CdiComponentProvider.java:316)
              at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:158)
              at org.jboss.weld.context.AbstractContext.get(AbstractContext.java:103)
              at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:93)
              at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
              at au.csiro.esa.authrest.rest.user.resource.UserResource$Proxy$_$$_WeldClientProxy.signupUser(Unknown Source)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:601)
              at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
              at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:140)
              at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:158)
              at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
              at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:101)
              at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:353)
              at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:343)
              at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:102)
              at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:237)
              at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
              at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
              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.process(Errors.java:267)
              at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:318)
              at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:211)
              at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:982)
              at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:359)
              at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:372)
              at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:335)
              at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:218)
              at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
              at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
              at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
              at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
              at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
              at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
              at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
              at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:359)
              at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:260)
              at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:496)
              at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:175)
              at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:191)
              at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:168)
              at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:187)
              at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
              at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
              at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
              at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:837)
              at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
              at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
              at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
              at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
              at java.lang.Thread.run(Thread.java:722)]]
      

      The Jersey Resource that caused this looks like.

      @Path("ping")
      @RequestScoped
      public class PingResource {
      
      	protected UriInfo uriInfo;
      	@Context
      	public void setUriInfo(UriInfo uriInfo) {
      		System.out.println("UserResource - set uriInfo:"+uriInfo);
      		this.uriInfo = uriInfo;
      	}
      
      	@PermitAll
      	@GET
      	@Produces({ MediaType.TEXT_PLAIN })
      	public Response ping() {
      		System.out.println("Hit ping");
      		return Response.ok().entity("Running version UNCOMMENT").build();//" + properties.getProperty("application.version")).build();
      		// return Response.ok().entity("Running version 10").build();
      	}
      }
      

      Moving this around to give on of the following fixes the error:

      	@Context
      	protected UriInfo uriInfo;
      

      OR

      public void setUriInfo(@Context UriInfo uriInfo) {
      		System.out.println("UserResource - set uriInfo:"+uriInfo);
      		this.uriInfo = uriInfo;
      	}
      

      The issue for me is why did the incorrect code do something that caused the error. Surely if the @Context was in the wrong location URIInfo would just be null.

        Activity

        Hide
        Michal Gajdos added a comment -

        This has been fixed in previous versions of Jersey (~2.4). Please use the latest nightly build of GF 4.0.1 available at [1].

        [1] http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/latest-glassfish.zip

        Show
        Michal Gajdos added a comment - This has been fixed in previous versions of Jersey (~2.4). Please use the latest nightly build of GF 4.0.1 available at [1] . [1] http://dlc.sun.com.edgesuite.net/glassfish/4.0.1/nightly/latest-glassfish.zip

          People

          • Assignee:
            Unassigned
            Reporter:
            HankCa
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: