2

我是 primepush 的新手,有一个问题。整个项目基于maven,服务器是Tomcat 7.0.27,所以我在pom.xml文件中添加依赖如下:

    <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>

web.xml 如下所示:

<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> 

我从 primefaces 展示中获取了聊天代码,但不知何故总是抛出 AtomsphereFramework 的 IllegalStateException。

    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]

我调试了 Atomsphere Framework 的源代码,发现问题是 Servlet30CometSupport.class 中的以下行:

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

之后它会抛出一个 IllegalStateException 。我该如何解决这个问题?谢谢你的帮助

4

1 回答 1

0

Tomcat 版本 7.0.27 支持 WebSockets。所以 web.xml 中的参数设置应该是

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

或省略整个参数设置,因为默认情况下使用 websockets。

此外,您还需要为大气兼容-tomcat-1.0.1.jar 和大气兼容-tomcat7-1.0.1.jar 添加依赖项

于 2013-07-03T14:08:35.743 回答