websocket-spec
  1. websocket-spec
  2. WEBSOCKET_SPEC-181

[jsr 356] java.lang.IllegalStateException: Not in 'deploy' scope

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Labels:
      None

      Description

      The following code:

      public class JSR356AsyncSupport extends Servlet30CometSupport {
          public JSR356AsyncSupport(AtmosphereConfig config) {
              super(config);
              Object serverContainer = config.getServletContext().getAttribute("javax.websocket.server.ServerContainer");
              if (serverContainer != null) {
                  try {
                      ServerContainer.class.cast(serverContainer).addEndpoint(JSR356ServerEndpointConfig.class);
                  } catch (DeploymentException e) {
                      e.printStackTrace();
                  }
              }
          }
      }
      

      produce

      Caused by: java.lang.IllegalStateException: Not in 'deploy' scope.
      	at org.glassfish.tyrus.servlet.TyrusServletServerContainer.addEndpoint(TyrusServletServerContainer.java:71)
      	at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:29)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
      	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
      	at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:252)
      	at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolveWebSocket(DefaultAsyncSupportResolver.java:319)
      	at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolve(DefaultAsyncSupportResolver.java:307)
      	at org.atmosphere.cpr.AtmosphereFramework.autoDetectContainer(AtmosphereFramework.java:1242)
      	at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:567)
      	at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:498)
      	at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:195)
      	at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1583)
      	at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1382)
      	at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5670)
      	... 27 more
      

      According to the Javadoc:

      The ServerContainer is the specialized view of the WebSocketContainer available in server-side deployments. There is one ServerContainer instance per websocket application. The ServerContainer holds the methods to be able to register server endpoints during the initialization phase of the application.
      For websocket enabled web containers, developers may obtain a reference to the ServerContainer instance by retrieving it as an attribute named javax.websocket.server.ServerContainer on the ServletContext. This way, the registration methods held on this interface may be called to register server endpoints from a ServletContextListener during the deployment of the WAR file containing the endpoint.

      If you look at the stack trace, the servletContainer is retrieved during the Servlet.init() invocation.

        Activity

        Hide
        jfarcand added a comment -

        BTW I cannot test this since at Deployment ServerApplicationConfig aren't detected by GlassFish See issue #20195. That's why It's broken

        Show
        jfarcand added a comment - BTW I cannot test this since at Deployment ServerApplicationConfig aren't detected by GlassFish See issue #20195. That's why It's broken
        Hide
        Pavel Bucek added a comment -

        see samples/programmatic-echo

        I saw GLASSFISH-20195, but that unfortunately is not something I can fix right now..

        Show
        Pavel Bucek added a comment - see samples/programmatic-echo I saw GLASSFISH-20195 , but that unfortunately is not something I can fix right now..
        Hide
        dannycoward added a comment -

        Hey Jeanfrancois - this programmatic deployment API wasn't ever supposed to work from servlet.init(). We're following the same model as the webcontainer does for deploying filters and servlets dynamically: you can do it up until the end of ServletContext initialization, e.g.

        http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addFilter%28java.lang.String,%20javax.servlet.Filter%29

        but not after.

        I think this means that you are guaranteed to be able to do it from a SCI, or from a ServletContextListener. But (this is my understanding) servlets themselves do not have to have their init()s called in this period. They might never be called if no-one asks for the URL its mapped to !

        • Danny
        Show
        dannycoward added a comment - Hey Jeanfrancois - this programmatic deployment API wasn't ever supposed to work from servlet.init(). We're following the same model as the webcontainer does for deploying filters and servlets dynamically: you can do it up until the end of ServletContext initialization, e.g. http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContext.html#addFilter%28java.lang.String,%20javax.servlet.Filter%29 but not after. I think this means that you are guaranteed to be able to do it from a SCI, or from a ServletContextListener. But (this is my understanding) servlets themselves do not have to have their init()s called in this period. They might never be called if no-one asks for the URL its mapped to ! Danny
        Hide
        martin_grigorov added a comment -

        Is it possible to allow registering endpoints in Filter#init() implementation ?
        Apache Tomcat 8.x allows it and this makes it much easier for integration with web frameworks.

        For example Apache Wicket frameworks configures itself by using Servlet Filter. To be able to support WebSocket on Glassfish we will have to require our users to add more stuff in web.xml.

        Show
        martin_grigorov added a comment - Is it possible to allow registering endpoints in Filter#init() implementation ? Apache Tomcat 8.x allows it and this makes it much easier for integration with web frameworks. For example Apache Wicket frameworks configures itself by using Servlet Filter. To be able to support WebSocket on Glassfish we will have to require our users to add more stuff in web.xml.
        Hide
        martin_grigorov added a comment -

        Here is a link to the issue in Tomcat's tracker that made it possible to add endpoints in later phase: https://issues.apache.org/bugzilla/show_bug.cgi?id=55314

        As web framework developer I find this functionality as very useful.

        Show
        martin_grigorov added a comment - Here is a link to the issue in Tomcat's tracker that made it possible to add endpoints in later phase: https://issues.apache.org/bugzilla/show_bug.cgi?id=55314 As web framework developer I find this functionality as very useful.

          People

          • Assignee:
            Unassigned
            Reporter:
            jfarcand
          • Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated: