2016-04-28 70 views
0

我创建了Java Web应用程序,并试图强制使用JSR-356的气氛,因为,据我所知,它是唯一的方法使用原始javax.servlet.HttpSessionAtmosphereResource对象。 (诉9.3.7)大气是无法配置JSR-356

当我部署我的应用程序到码头,我得到以下错误:

16:45:16.535 [Scanner-1] ERROR org.atmosphere.util.IOUtils - 
java.lang.IllegalStateException: Unable to configure jsr356 at that stage. No Servlet associated with Key[type=org.atmosphere.guice.AtmosphereGuiceServlet, annotation=[none]] 
    at org.atmosphere.util.IOUtils.guestRawServletPath(IOUtils.java:274) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.util.IOUtils.guestServletPath(IOUtils.java:248) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:63) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:40) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) [na:1.8.0_74] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) [na:1.8.0_74] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) [na:1.8.0_74] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) [na:1.8.0_74] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:234) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolveWebSocket(DefaultAsyncSupportResolver.java:306) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolve(DefaultAsyncSupportResolver.java:292) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.autoDetectContainer(AtmosphereFramework.java:2082) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:914) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:838) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFrameworkInitializer.configureFramework(AtmosphereFrameworkInitializer.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:84) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:80) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:121) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:103) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:220) [guice-servlet-4.0.jar:na] 
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:350) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772) [jetty-server-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:263) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:499) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:147) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:458) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_74] 
    at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_74] 
16:45:16.536 [Scanner-1] ERROR o.a.cpr.DefaultAsyncSupportResolver - Real error: Unable to configure jsr356 at that stage 
java.lang.IllegalStateException: Unable to configure jsr356 at that stage 
    at org.atmosphere.util.IOUtils.guestRawServletPath(IOUtils.java:292) ~[atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.util.IOUtils.guestServletPath(IOUtils.java:248) ~[atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:63) ~[atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.container.JSR356AsyncSupport.<init>(JSR356AsyncSupport.java:40) ~[atmosphere-runtime-2.4.3.jar:2.4.3] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_74] 
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_74] 
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_74] 
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_74] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.newCometSupport(DefaultAsyncSupportResolver.java:234) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolveWebSocket(DefaultAsyncSupportResolver.java:306) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.DefaultAsyncSupportResolver.resolve(DefaultAsyncSupportResolver.java:292) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.autoDetectContainer(AtmosphereFramework.java:2082) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:914) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFramework.init(AtmosphereFramework.java:838) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereFrameworkInitializer.configureFramework(AtmosphereFrameworkInitializer.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:84) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.configureFramework(AtmosphereServlet.java:80) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at org.atmosphere.cpr.AtmosphereServlet.init(AtmosphereServlet.java:75) [atmosphere-runtime-2.4.3.jar:2.4.3] 
    at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:121) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:103) [guice-servlet-4.0.jar:na] 
    at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:220) [guice-servlet-4.0.jar:na] 
    at org.eclipse.jetty.servlet.FilterHolder.initialize(FilterHolder.java:137) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:856) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:350) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.startWebapp(WebAppContext.java:1379) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1341) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:772) [jetty-server-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.servlet.ServletContextHandler.doStart(ServletContextHandler.java:263) [jetty-servlet-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:517) [jetty-webapp-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:68) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.bindings.StandardStarter.processBinding(StandardStarter.java:41) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.AppLifeCycle.runBindings(AppLifeCycle.java:188) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.DeploymentManager.requestAppGoal(DeploymentManager.java:499) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.DeploymentManager.addApp(DeploymentManager.java:147) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider.fileAdded(ScanningAppProvider.java:180) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.WebAppProvider.fileAdded(WebAppProvider.java:458) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.deploy.providers.ScanningAppProvider$1.fileAdded(ScanningAppProvider.java:64) [jetty-deploy-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.reportAddition(Scanner.java:610) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.reportDifferences(Scanner.java:529) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner.scan(Scanner.java:392) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at org.eclipse.jetty.util.Scanner$1.run(Scanner.java:329) [jetty-util-9.3.7.v20160115.jar:9.3.7.v20160115] 
    at java.util.TimerThread.mainLoop(Timer.java:555) [na:1.8.0_74] 
    at java.util.TimerThread.run(Timer.java:505) [na:1.8.0_74] 

如果我强迫原生API采取优先用下面的代码

params.put(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true"); 

然后一切正常。

这里是我的部署描述符:

<?xml version="1.0" encoding="UTF-8"?> 
<web-app xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
          http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" 
     version="3.0"> 

    <listener> 
     <listener-class>com.sample.guice.GuiceContextListener</listener-class> 
    </listener> 

    <filter> 
     <filter-name>guiceFilter</filter-name> 
     <filter-class>com.google.inject.servlet.GuiceFilter</filter-class> 
    </filter> 

    <filter-mapping> 
     <filter-name>guiceFilter</filter-name> 
     <url-pattern>/*</url-pattern> 
    </filter-mapping> 
</web-app> 

用于提供所有绑定的模块:

public class ServerModule extends AbstractModule 
{ 
    @Override 
    protected void configure() 
    { 
     install(new ServletModule() { 
      @Override 
      protected void configureServlets() 
      { 
       Map<String, String> params = new HashMap<>(); 
       // params.put(ApplicationConfig.WEBSOCKET_SUPPRESS_JSR356, "true"); 
       serve("/atmosphere").with(AtmosphereGuiceServlet.class, params); 
      } 
     }); 
    } 
} 

我省略与@ManagedService注解类和一些其他的代码,因为不存在任何问题。正如我所说的,一切工作正常与本地websocket API。

+0

我建议在JSR356 websocket上使用jetty native websocket API。 –

+0

@JoakimErdfelt似乎它的本地API不提供握手之前可用的'javax.servlet.session.HttpSession',所以我必须使用JSR-356 ... –

+1

访问'HttpSession'对于本地API vs JSR356。你有2种方法。 (1)提供您自己的'WebSocketCreator'并根据您的升级过程做任何事情,包括直接使用HttpSession并推入您的websocket类。 (2)使用'api.Session#getSession()'随时访问'HttpSession'(在'HttpSession'到期之前) –

回答

0

您可以添加ApplicationConfig.JSR356_MAPPING_PATH initParameter并尝试一下。

如果不起作用,可能是您可以显式初始化氛围框架并指定init参数 ApplicationConfig.JSR356_MAPPING_PATH作为有效的键值对。

有关初始化,您可以看到org.atmosphere.cpr.ContainerInitializer和添加的路径,而initalizing大气框架

最终AtmosphereFramework框架= AtmosphereFrameworkInitializer.newAtmosphereFramework(C,假的,真正的); //黑客让jsr356工作。很难看。 DefaultAsyncSupportResolver resolver = new DefaultAsyncSupportResolver(framework.getAtmosphereConfig());

framework.getAtmosphereConfig()。addInitParam(ApplicationConfig.JSR356_MAPPING_PATH,appropriateservletPath);