2012-11-27 193 views
3

我使用:Primepush ...無法建立連接,WebSocket的關閉,原因:連接被關閉異常

的Linux
PrimeFaces 3.4.1
的Glassfish 3.1.2.2(建5,彗星啓用,禁用的WebSockets)
火狐10.0.7
鉻22.0.1229.94

我有一個PrimePush消息驅動bean中。當我的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> 

回答

1

我面臨同樣的問題,並實現在GlassFish中固定我的問題的WebSockets(以下添加啓用後彗星支持到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中啓用的WebSockets。我認爲設置傳輸到彗星(長輪詢/流)在p:套接字也可能工作。

BTW,我測試了:

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

謝謝你,給我幾天避開測試此。我因爲某種原因想過我嘗試過,但現在不記得。 – Ender