我想在我的应用程序中实现一个简单的推送机制。我正在使用TomEE 1.7服务器,它使用Tomcat以及许多其他软件包。
对于Atmosphere我使用的是氛围运行时2.4.3,在客户端我使用的是2.3.1版本。
现在,当我尝试使用websockets进行推送时,我的工作正常,但是当我尝试使用长轮询作为传输时,我在服务器上收到以下错误:
WARNING: Duplicate resource be43d07f-cbb4-412e-9d50-2d047a2e0223. Could be caused by a dead connection not detected by your server. Replacing the old one with the fresh one
browser connected be43d07f-cbb4-412e-9d50-2d047a2e0223
Mar 10, 2016 11:56:36 AM org.atmosphere.cpr.AtmosphereFramework doCometSupport
SEVERE: AtmosphereFramework exception
java.lang.IllegalStateException: A filter or servlet of the current chain does not support asynchronous operations.
at org.apache.catalina.connector.Request.startAsync(Request.java:1658)
at org.apache.catalina.connector.RequestFacade.startAsync(RequestFacade.java:1029)
at org.atmosphere.cpr.AtmosphereRequestImpl.startAsync(AtmosphereRequestImpl.java:623)
at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:95)
at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:70)
at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:2287)
at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:191)
at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:177)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:620)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.filters.CorsFilter.handleSimpleCORS(CorsFilter.java:302)
at org.apache.catalina.filters.CorsFilter.doFilter(CorsFilter.java:166)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.tomee.catalina.OpenEJBValve.invoke(OpenEJBValve.java:44)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at com.tradeweb.server.tools.valve.RequestHeaderCopyValve.invoke(RequestHeaderCopyValve.java:41)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:316)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:745)
在客户端上,我看到以下问题(如果是chrome):
GET http://127.0.0.1:43859/report-integrator-war/notification?X-Atmosphere-trac…ype=text%2Fplain%3B%20charset%3Dutf-8&X-atmo-protocol=true&_=1457628996834 net::ERR_INCOMPLETE_CHUNKED_ENCODING
_executeRequest @ atmosphere.js:2123
_reconnect @ atmosphere.js:2232
ajaxRequest.onreadystatechange @ atmosphere.js:2106
atmosphere.js:3258 Thu Mar 10 2016 11:56:36 GMT-0500 (Eastern Standard Time) Atmosphere: ajaxRequest.onreadystatechange, new state: 4
atmosphere.js:3258 Thu Mar 10 2016 11:56:36 GMT-0500 (Eastern Standard Time) Atmosphere: Firing onError, reasonPhrase: maxReconnectOnClose reached
atmosphere.js:3258 Thu Mar 10 2016 11:56:36 GMT-0500 (Eastern Standard Time) Atmosphere: Firing onError, reasonPhrase: maxReconnectOnClose reached
atmosphere.js:3258 Thu Mar 10 2016 11:56:36 GMT-0500 (Eastern Standard Time) Atmosphere: ajaxrequest.onerror
这是我的web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>Portfolio Analytics Integrator</display-name>
<servlet>
<servlet-name>AtmosphereServlet</servlet-name>
<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<load-on-startup>0</load-on-startup>
<async-supported>true</async-supported>
</servlet>
<servlet-mapping>
<servlet-name>AtmosphereServlet</servlet-name>
<url-pattern>/notification/*</url-pattern>
</servlet-mapping>
</web-app>
在这里我们可以看到我正在使用= true仍然服务器抱怨servlet不支持异步操作。
我对Atmosphere相对较新,所以无法解决这里的问题。此外,当我在本地运行代码时,至少我可以通过websockets进行通信,但是当我在服务器环境中部署代码时,也无法使用websockets连接,并且回退到长轮询产生上述错误。当我在中间使用charles代理时,我的本地也是如此。
答案 0 :(得分:0)
我已经找到了问题,看起来这是一个TomEE 1.7.0 Server错误。 TomEE服务器使用的是运行tomcat 7.0.55.0。以下是TomEE的version.sh输出:
[web@DEVTWDLNX05 bin]$ ./version.sh
Using CATALINA_BASE: /home/web/servers/apache-tomee-plus
Using CATALINA_HOME: /home/web/servers/apache-tomee-plus
Using CATALINA_TMPDIR: /home/web/servers/apache-tomee-plus/temp
Using JRE_HOME: /usr
Using CLASSPATH: /home/web/servers/apache-tomee-plus/bin/bootstrap.jar:/home/web/servers/apache-tomee-plus/bin/tomcat-juli.jar
Server version: Apache Tomcat/7.0.55
Server built: Jul 18 2014 05:34:04
Server number: 7.0.55.0
OS Name: Linux
OS Version: 3.8.13-55.1.6.el7uek.x86_64
Architecture: amd64
JVM Version: 1.7.0_75-mockbuild_2015_01_20_15_59-b00
JVM Vendor: Oracle Corporation
当我在运行Tomcat 7.0.68的TomEE 1.7.4上运行代码时,一切运行正常。
令人费解的是,我还在普通的Tomcat 7.0.55.0上运行了相同的代码,并且代码工作得很好但是当Tomcat服务器打包相同的tomcat时,我们收到了错误。