tomcat - AtmosphereFramework异常java.lang.IllegalStateException : Not supported

标签 tomcat grails atmosphere

我在我的 grails 应用程序中使用 Atmosphere。从我的 IDE (IntelliJ Idea) 运行应用程序时,一切都很好。但是当我将它部署到 tomcat (7.0) 后出现异常时:

2013-07-08 09:07:19,118 [ajp-nio-8009-exec-13] ERROR cpr.AtmosphereFramework  - AtmosphereFramework exception
java.lang.IllegalStateException: Not supported.
    at org.atmosphere.cpr.AtmosphereRequest.startAsync(AtmosphereRequest.java:594)
    at org.atmosphere.container.Servlet30CometSupport.suspend(Servlet30CometSupport.java:138)
    at org.atmosphere.container.Servlet30CometSupport.service(Servlet30CometSupport.java:104)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.doService(Tomcat7Servlet30SupportWithWebSocket.java:65)
    at org.atmosphere.container.TomcatWebSocketUtil.doService(TomcatWebSocketUtil.java:87)
    at org.atmosphere.container.Tomcat7Servlet30SupportWithWebSocket.service(Tomcat7Servlet30SupportWithWebSocket.java:61)
    at org.atmosphere.cpr.AtmosphereFramework.doCometSupport(AtmosphereFramework.java:1571)
    at org.atmosphere.cpr.AtmosphereServlet.doPost(AtmosphereServlet.java:176)
    at org.atmosphere.cpr.AtmosphereServlet.doGet(AtmosphereServlet.java:162)
    at com.googlecode.psiprobe.Tomcat70AgentValve.invoke(Tomcat70AgentValve.java:38)
    at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
    at java.lang.Thread.run(Thread.java:662)

web.xml 中的 myservlet 配置是:

<servlet>
        <description>MeteorServlet</description>
        <servlet-name>MeteorServlet</servlet-name>
        <servlet-class>org.grails.plugin.platform.events.push.GrailsMeteorServlet</servlet-class>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.shareableThreadPool</param-name>
            <param-value>true</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxProcessingThreads</param-name>
            <param-value>20</param-value>
        </init-param>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcaster.maxAsyncWriteThreads</param-name>
            <param-value>20</param-value>
        </init-param>
        <load-on-startup>0</load-on-startup>
        <async-supported>true</async-supported>
    </servlet>

用法是

var receivedOrders = new Array();
    var grailsEvents = new grails.Events("${rootPath}",
    {
        transport: 'sse',
        fallbackTransport: 'long-polling',
        timeout: 10000,
        onMessage: function(data){
            try{
                if(data.responseBody.length > 0){
                    var order = jQuery.parseJSON(data.responseBody).body;
                    if(order.id){
                        if (receivedOrders.indexOf(order.id) == -1) {
                        receivedOrders[receivedOrders.length] = order.id;
                        var url = "<g:createLink controller="orderAdministration" action="orderNotification"/>";
                        $.ajax({
                            type: "POST",
                            url: url,
                            data: { id: order.id }
                        }).done(function (response) {
                                    if (response != "0") {
                                        $.msgGrowl({
                                            type: 'info', sticky: true, 'title': '${message(code: 'order.notification.title')}', 'text': response, lifetime: 5000
                                        });
                                    }
                                });
                        }
                    }
                }
            } catch (e) {
                // Atmosphere sends commented out data to WebKit based browsers
            }
        }
    });

    grailsEvents.on('order_event', function(data){});

看来tomcat配置有问题。有什么想法吗?

编辑:

我已经测试过了。但不起作用。

问题的发生是因为我在 grails.Events 中提供了选项。 通过更改为此,解决了异常。

var receivedOrders = new Array();
    var grailsEvents = new grails.Events("${rootPath}");

    function handleOrderEvent(data){
        try{
            if(data.id){
                if (receivedOrders.indexOf(data.id) == -1) {
                    receivedOrders[receivedOrders.length] = data.id;
                    var url = "<g:createLink controller="orderAdministration" action="orderNotification"/>";
                    $.ajax({
                        type: "POST",
                        url: url,
                        data: { id: data.id }
                    }).done(function (response) {
                        if (response != "0") {
                            $.msgGrowl({
                                type: 'info', sticky: true, 'title': '${message(code: 'order.notification.title')}', 'text': response, lifetime: 5000
                            });
                        }
                    });
                }
            }
        }catch (e) {
        // Atmosphere sends commented out data to WebKit based browsers
        }
    }

    grailsEvents.on('order_event', handleOrderEvent, {transport:'long-polling', fallbackTransport:'polling'});

但仍然没有事件传播到客户端!

我在 tomcat 前面有一个 apache 网络服务器。事件在服务中触发,但在 javascript 中不触发。

最佳答案

还有来自 JF Arcand(Atmospehere 框架的创建者)的另一个回应: http://atmosphere-framework.2306103.n4.nabble.com/org-apache-catalina-connector-Request-startAsync-Not-Supported-td4651994.html

你要么需要在你的 web.xml 中添加

<servlet-class>org.atmosphere.cpr.AtmosphereServlet</servlet-class>
<async-supported>true</async-supported>

启用Servlet 3.0,或添加

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

因为 async-supported 已经被定义,你应该尝试将 org.atmosphere.useNative 设置为 true

关于tomcat - AtmosphereFramework异常java.lang.IllegalStateException : Not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17528449/

相关文章:

java - 尝试调用 servlet 时遇到错误 404

Grails transient 属性未在对象创建时获取

grails - 基于gsp文件自动创建对象

amazon-ec2 - 亚马逊 ec2 上的 Websockets 连接失败

eclipse - 我可以在不重新编译类的情况下使用 Wicket 和 Eclipse 更新 HTML 文件吗?

java - Servlet 示例 - 找不到文件

apache - 只有与 mod_proxy 一起使用的端口是 8009。尝试与 tomcat 和 httpd/一起使用

exception - grails输出 “an error has occurred”,如何显示实际错误?

java - 在 Java 中使用 Atmosphere 传输

java - 如何删除 Atmosphere 广播