primepush on Tomcat 7 not working

落花浮王杯 提交于 2019-12-13 16:58:08

问题


I am new to primepush and have a question. The whole project is based on maven and the server is Tomcat 7.0.27, so I add the dependence into pom.xml file as following:

    <dependency>
         <groupId>org.atmosphere</groupId>
          <artifactId>atmosphere-runtime</artifactId>
           <version>1.0.1</version>
      </dependency>
      <dependency>
         <groupId>org.atmosphere</groupId>
         <artifactId>atmosphere-annotations</artifactId>
         <version>1.0.1</version>
      </dependency>

The web.xml is like following:

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
    <init-param>
        <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
        <param-value>org.atmosphere.cache.HeaderBroadcasterCache</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.broadcasterClass</param-name>
        <param-value>org.atmosphere.cpr.DefaultBroadcaster</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.broadcastFilterClasses</param-name>
        <param-value>org.atmosphere.client.TrackMessageSizeFilter</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.sessionSupport</param-name>
        <param-value>true</param-value>
    </init-param>
    <init-param>
       <param-name>org.atmosphere.useWebSocket</param-name>
    <param-value>false</param-value>
</init-param>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping> 

I grab the code of chat from primefaces showcase, but somehow the IllegalStateException of AtomsphereFramework is always thrown.

    09:33:38.322 ERROR o.atmosphere.cpr.AtmosphereFramework - AtmosphereFramework exception
java.lang.IllegalStateException: Not supported.
   at org.apache.catalina.connector.Request.startAsync(Request.java:1609) ~[catalina.jar:7.0.12]
   at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1031) ~[catalina.jar:7.0.12]
   at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379) ~[servlet-api.jar:3.0.FR]
   at javax.servlet.ServletRequestWrapper.startAsync(ServletRequestWrapper.java:379) ~[servlet-api.jar:3.0.FR]
   at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:556) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
   at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:137) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
   at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:103) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
   at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1293) ~[atmosphere-runtime-1.0.1.jar:1.0.1]
   at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:293) [atmosphere-runtime-1.0.1.jar:1.0.1]
   at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:279) [atmosphere-runtime-1.0.1.jar:1.0.1]
   at javax.servlet.http.HttpServlet.service(HttpServlet.java:621) [servlet-api.jar:na]

I debug the source code of Atomsphere Framework and find out the problem is the following line in the Servlet30CometSupport.class:

AsyncContext asyncContext = req.startAsync(req, res);

It throws an IllegalStateException afterwards. How can I solve that problem? Thanks for any help


回答1:


Tomcat version 7.0.27 supports WebSockets. So param setting in your web.xml should be

<init-param>
    <param-name>org.atmosphere.useWebSocket</param-name>
    <param-value>true</param-value>
</init-param>

or omit entire param setting cause websockets are used by default.

Also you will need to add dependencies for atmosphere-compat-tomcat-1.0.1.jar and atmosphere-compat-tomcat7-1.0.1.jar



来源:https://stackoverflow.com/questions/12929606/primepush-on-tomcat-7-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!