primepush在Tomcat 7不工作(primepush on Tomcat 7 not wo

2019-09-24 05:08发布

我是新来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框架的源代码,并找出问题出在Servlet30CometSupport.class下面一行:

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

据事后抛出IllegalStateException。 我该如何解决这个问题? 谢谢你的帮助

Answer 1:

Tomcat的版本7.0.27支持WebSockets的。 所以,在你的web.xml PARAM设置应

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

或省略整个PARAM设置原因的WebSockets默认使用。

你还需要添加依赖于大气COMPAT-tomcat的-1.0.1.jar和大气COMPAT-tomcat7-1.0.1.jar



文章来源: primepush on Tomcat 7 not working