Tomcat错误:java.lang.IllegalStateException:调用[asyncPostProcess()]对于具有异步状态的请求无效[STARTED]

时间:2013-05-31 11:22:11

标签: tomcat7 long-polling cometd

试图在tomcat 7.0.37上运行这个简单的演示: https://github.com/cometd/cometd-tutorials/tree/master/client-hello

我更改了web.xml以支持异步调用(cometD用于长轮询)。

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

<servlet>
    <servlet-name>cometd</servlet-name>
    <servlet-class>org.cometd.annotation.AnnotationCometdServlet</servlet-class>
    <init-param>
        <param-name>transports</param-name>
        <param-value>org.cometd.websocket.server.WebSocketTransport</param-value>
    </init-param>
    <init-param>
        <param-name>services</param-name>
        <param-value>org.cometd.tutorials.ClientHelloService</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>cometd</servlet-name>
    <url-pattern>/cometd/*</url-pattern>
</servlet-mapping>

<filter>
    <filter-name>cross-origin</filter-name>
    <filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>cross-origin</filter-name>
    <url-pattern>/cometd/*</url-pattern>
</filter-mapping>

<filter>
    <filter-name>continuation</filter-name>
    <filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
    <async-supported>true</async-supported>
</filter>
<filter-mapping>
    <filter-name>continuation</filter-name>
    <url-pattern>/cometd/*</url-pattern>
</filter-mapping>

</web-app>

如果我按下按钮向服务器发送电子邮件,我会收到以下错误:

java.lang.IllegalStateException: Calling [asyncPostProcess()] is not valid for a request with Async state [STARTED]
at org.apache.coyote.AsyncStateMachine.asyncPostProcess(AsyncStateMachine.java:204)
at org.apache.coyote.AbstractProcessor.asyncPostProcess(AbstractProcessor.java:116)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:593)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1686)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)

也许有人可以在这个堆栈中带来光明?

3 个答案:

答案 0 :(得分:0)

确保在所有过滤器上设置为true。见http://cometd.org/node/106

  

应该为CometD servlet和可能在CometD servlet之前执行的所有过滤器指定async支持的元素,例如CrossOriginFilter。

我遇到了这个问题,因为我有一个新添加的过滤器,它与缺少此标记的cometd无关。添加标签解决了问题。

答案 1 :(得分:0)

如果你使用像struts这样的框架,请处理由它动态添加的过滤器,而不是web.xml中配置的过滤器。 http://blog.163.com/pilgrim_yang/blog/static/556314812014218977633/

答案 2 :(得分:0)

看起来像this bug。它已在Tomcat 7.0.43中修复。