2

I have successfully configured my webapp with PrimePush, which builds & deploys with no errors. When I attempt to 'push' from my backing bean, I do not get any errors however my client, from what I can tell, never receives it.

My setup: virgo3.0.3/tomcat 7. PF 3.5, Atmosphere 2.0.1. (I was previously using the versions stated in the PF 3.5 userguide, but I was getting build & deployment errors - see my other question here.)

Web.xml

<servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>

Bean.java

public void eventHappened()
{
   //SOMETHING HAS HAPPENED, LET THE CLIENT KNOW!
   pushContext.push("/notification", "a message");
   log.debug("I HAVE JUST SENT A PUSH");
}

Client Page

<h:body>
   <h:form>
      <!--SOME UI ELEMENTS ETC -->
   <h:form>

   <p:socket channel="/notification" autoConnect="false" onMessage="handleMessage"/>

   <script type="text/javascript">  
    function handleMessage(data) {  
        alert("yay");
    }  
   </script>
<h:body>

Now, in my log files, I successfully see I HAVE JUST SENT A PUSH, though no alert is shown on the browser, and I have no errors in my logs.

Now, I am relatively new to PF, so could well be missing something fundamental, however hours of searching threads and StackOverflow has not yield any solutions for me as yet.

What I have come across though, is when I view my source code after depolyment, the rendered javascript is as follows:

<script type="text/javascript">$(function() {widget_j_idt95 = new PrimeFaces.widget.Socket({url:'/myProjectContextPath/primepush/notification',autoConnect:false,transport:'websocket',fallbackTransport:'long-polling',onMessage:handleMessage});});</script>

Looking more closely:

PrimeFaces.widget.Socket({url:'/myProjectContextPath/primepush/notification'

Since I declared my URL pattern, <url-pattern>/primepush/*</url-pattern> I thought a possibility was that the client was listening on a different channel than what the server was sending on. So I changed as such <url-pattern>/myProjectContextPath/primepush/*</url-pattern>. Again, however, this would not a solution.

Thanks in advance for your help!

UPDATE As I previously said, I have probably missed something fundamental. I moved the javascript into my <h:head>To my (somewhat) delight, I was now getting errors on my Chrome console (on page load), which I have seen on other threads:

Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). push.js.xhtml?ln=primefaces:1
Websocket closed, wasClean: false push.js.xhtml?ln=primefaces:1
Websocket failed. Downgrading to Comet and resending 

Now, having searched that error, the solution seems to be to enable 'Comet and Websockets' on Glassfish. Now, I know I said my setup was with Glassfish, however, I think we are just using its libraries - (I am quite new to Maven,OSGI, etc), we deploy the webapp using tomcat/virgo and, for some reason, we have Glassfish as a dependency.

I have searched for how to enable Comets and Websockets, but my searches do not really turn up with any explanations how to.

I wonder if anyone can explain how I can enable them or what my next steps should be?

4

0 回答 0