【问题标题】:Primepush ... Can't Establish Connection, Websocket closed, reason: Connection was closed abnormallyPrimepush ...无法建立连接,Websocket关闭,原因:连接异常关闭
【发布时间】:2012-11-27 01:41:04
【问题描述】:

我正在使用:

Linux
PrimeFaces 3.4.1
Glassfish 3.1.2.2(内部版本 5,启用了彗星,禁用了 websockets)
火狐 10.0.7
铬 22.0.1229.94

我在消息驱动 bean 中有 PrimePush。当我的 MDB 的 onMessage() 被调用时(这应该是每秒几次),我期待出现咆哮通知。此外,不确定这是否重要,但 MDB 位于 *.ear 内的 *.jar 文件中,Web 应用程序也在耳内的 *.war 中。我在 MDB 中有 PrimePush,如下所示。

pushContext = PushContextFactory.getDefault().getPushContext();
pushContext.push("/notifications",
    new FacesMessage("Hello World", "New Notification"));

这是我的 web.xml。

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>

问题是当我第一次将所有内容(glassfish,浏览器)清理干净时会触发一次通知,但通常不会再次出现或每次调用 pushContext.push() 时都不会出现。使用FF,它甚至一次都不起作用。当 MDB onMessage() 触发时,我会在 firefox 错误控制台中收到以下信息。

Error: Firefox can't establish a connection to the server at ws://localhost:8080/test/primepush/notifications?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=1.0&X-Atmosphere-Transport=websocket&X-Cache-Date=0.
Source File: http://localhost:8080/test/javax.faces.resource/push/push.js.xhtml?ln=primefaces
Line: 1  

使用 Chrome,它至少可以工作一次,有时但不是更可靠。每次我加载网页时,我都会看到一个连接已关闭(就像我加载页面一样)。这是在错误控制台中。

Unexpected response code: 200 :8080:1
Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). push.js.xhtml:1
Websocket closed, wasClean: false push.js.xhtml:1
Websocket failed. Downgrading to Comet and resending  

这是我的 text.xhtml 页面。

<p:growl widgetVar="growl" showDetail="true"/>

<h:form id="myform">
    <p:fieldset id="myfs" legend="Push Test">
        <!-- stuff -->
    </p:fieldset>
</h:form>

<script type="text/javascript">
    function handleMessage(data) {
        data.severity = 'info';
        growl.show([data]);
    }
</script>

<p:socket onMessage="handleMessage" channel="/notifications">
</p:socket>

【问题讨论】:

    标签: firefox google-chrome primefaces glassfish-3 atmosphere


    【解决方案1】:

    我遇到了同样的问题,在 glassfish 中启用 websocket 解决了我的问题(在启用 comet-support 后将以下内容添加到 domain.xml):

    websockets-support-enabled="true"
    

    提示是这样的:

    Websocket failed. Downgrading to Comet and resending  
    

    根据http://www.primefaces.org/docs/vdl/3.4/primefaces-p/socket.html 此处的文档,websocket 是 primepush 中使用的默认方式,需要在 glassfish 中启用 websocket。我认为在 p:socket 中将传输设置为彗星(长轮询/流)也可能有效。

    顺便说一句,我测试过:

    Mac
    PrimeFaces 3.4.2 with Atmosphere 1.0.8
    Glassfish 3.1.2 (with comet enabled, websockets enabled)
    FireFox 18
    Chromium 24
    

    【讨论】:

    • 谢谢,给我几天时间来测试一下。我以为出于某种原因我尝试过,但现在不记得了。
    猜你喜欢
    • 2019-12-14
    • 1970-01-01
    • 2017-03-20
    • 2022-07-30
    • 1970-01-01
    • 2020-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多