Primefaces 5 PUSH on Glassfish

UI Components for JSF
eldjon_kepucka
Posts: 1
Joined: 08 Apr 2014, 14:41

22 May 2014, 19:38

Im currently trying to test the COUNTER demo from the website.
I followed the demo step by step but at the end i cant make it work.
I can track that the ManagedBean method is called (when pressing a button)
and the @PushEndpoint onMessage() method is called as well. But somehow
it cant make a connection to the client endpoint.
Im running on Glassfish 4.0, Primefaces 5.0 and Atmosphere 2.1.3

Code: Select all

<h:body>
	<f:view locale="en" encoding="UTF-8">
		<p:growl widgetVar="growl" showDetail="true" />
		<h:form id="mainForm" prependId="false" enctype="multipart/form-data"
			rendered="true">
			<p:commandButton actionListener="#{testBean.testMethod}"></p:commandButton>
			
			<p:commandButton rendered="#{testBean.showSth}" 
				id="testBtn" widgetVar="testBtnW"> slkdjflskjdf</p:commandButton>
		</h:form>
		
		<p:socket channel="/some">
			<p:ajax event="message" update="mainForm:testBtn" />
		</p:socket>
	</f:view>
</h:body>

ekraffmiller
Posts: 8
Joined: 21 May 2014, 21:38

23 May 2014, 20:57

I am having the same problem - I can't get the Push Counter example to work, and I have the same configuration - Primefaces 5.0, Glassfish 4.0, and Atmosphere 2.1.3.

I'm also seeing the same behavior - the message is successfully received by the Endpoint, but it it fails getting sent to the browser.

In firebug, I'm seeing this error when I click the counter button:

The connection to ws://localhost:26293/pushtest/primepush/mytest?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.0-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&X-atmo-protocol=true was interrupted while the page was loading.

Any feedback would be greatly appreciated. We were using push successfully prior to upgrading to Primefaces 5.0.

Here is my test page:

Code: Select all

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"    >
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </h:head>
    <h:body>
        <h:form>
            <h:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>
                            
            <p:socket channel="/mytest" onMessage="handleMessage"  >

                </p:socket>
                <h:outputText styleClass="messageDisplay" id="test1" value="hello text"/>
        </h:form>
        <script type="text/javascript">
            // <![CDATA[
            function handleMessage(data) {                      
                $('.messageDisplay').text(data);
            }     // ]]>
        </script>

    </h:body>
</html>

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

23 May 2014, 21:57

reply with your bean code and web.xml
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

ekraffmiller
Posts: 8
Joined: 21 May 2014, 21:38

28 May 2014, 13:44

Sorry for the late reply, I was on vacation. Here is the rest of the code:

Code: Select all


@Named
@ApplicationScoped
public class TestBean {
    public void sendMessage() {
        Date now = new Date();
        System.out.println("sending message, now: "+now);
         EventBus eventBus = EventBusFactory.getDefault().eventBus();         
        eventBus.publish("/mytest", "complete "+now);        
    }
}

@PushEndpoint("/mytest")
public class PushEndPoint {
    @OnMessage(encoders= {JSONEncoder.class})
    public String onMessage(String msg) {
        System.out.println("received msg: "+msg);
        return msg;
    }  
}

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
 <servlet>
    <servlet-name>Push Servlet</servlet-name>
    <servlet-class>org.primefaces.push.PushServlet</servlet-class>  
       <async-supported>true</async-supported>
</servlet>
<servlet-mapping>
    <servlet-name>Push Servlet</servlet-name>
    <url-pattern>/primepush/*</url-pattern>
</servlet-mapping>  
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>/faces/*</url-pattern>
</servlet-mapping>  

</web-app>

Maven Dependencies: 

 <dependencies>
    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-web-api</artifactId>
        <version>7.0</version>
        <scope>provided</scope>
    </dependency>
<dependency>
    <groupId>org.atmosphere</groupId>
    <artifactId>atmosphere-runtime</artifactId>
    <version>2.1.3</version>
</dependency>
  <dependency>
        <groupId>org.primefaces</groupId>
        <artifactId>primefaces</artifactId>
        <version>5.0</version>
    </dependency>
</dependencies>
 

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 May 2014, 16:28

do the following and let me know the test results.

change the following

Code: Select all

        <h:form>
            <h:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>
                            
            <p:socket channel="/mytest" onMessage="handleMessage"  >

                </p:socket>
                <h:outputText styleClass="messageDisplay" id="test1" value="hello text"/>
        </h:form>
        <script type="text/javascript">
            // <![CDATA[
            function handleMessage(data) {                      
                $('.messageDisplay').text(data);
            }     // ]]>
        </script>
to the following

Code: Select all

        <h:form id="myForm">
            <p:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>
                            
                <h:outputText styleClass="messageDisplay" id="test1" value="hello text"/>
        </h:form>
        <p:socket channel="/mytest" onMessage="handleMessage"/>
        <script type="text/javascript">
            function handleMessage(data) {                      
                document.getElementById('myForm:messageDisplay').text(data);
            }
        </script>
* above, look at h:form ID, p:commandButton, p:socket outside of h:form, and handleMessage()

change the following

Code: Select all

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

Code: Select all

    <servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
        <init-param>
            <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
            <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
        </init-param>
        <async-supported>true</async-supported>
    </servlet>
    <servlet-mapping>
        <servlet-name>Push Servlet</servlet-name>
        <url-pattern>/primepush/*</url-pattern>
    </servlet-mapping>
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

ekraffmiller
Posts: 8
Joined: 21 May 2014, 21:38

28 May 2014, 20:24

Hi Howard, thanks for the reply.

I tried the changes you suggested, but I'm still getting the same error.

My new page:

Code: Select all

<h:body>
        <h:form id="myForm">
            <p:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>                                
                <h:outputText styleClass="messageDisplay" id="test1" value="hello text"/>
        </h:form>
         <p:socket channel="/mytest" onMessage="handleMessage" autoConnect="true"  >
          </p:socket>
        <script type="text/javascript">
            // <![CDATA[
            function handleMessage(data) {                      
           //     $('.messageDisplay').text(data);
       
              document.getElementById('myForm:messageDisplay').text(data);
            }     // ]]>
        </script>

    </h:body>
And web.xml:

Code: Select all

<servlet>
        <servlet-name>Push Servlet</servlet-name>
        <servlet-class>org.primefaces.push.PushServlet</servlet-class>
           <init-param>
            <param-name>org.atmosphere.cpr.broadcasterCacheClass</param-name>
            <param-value>org.atmosphere.cache.UUIDBroadcasterCache</param-value>
       </init-param> 
       <load-on-startup>1</load-on-startup>
           <async-supported>true</async-supported>
    </servlet>
On other piece of info: I'm using the primefaces-extensions library, for a page layout on another page in my app. Don't know if that would make a difference.

Thanks,
Ellen

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 May 2014, 22:24

ekraffmiller wrote:I am having the same problem - I can't get the Push Counter example to work, and I have the same configuration - Primefaces 5.0, Glassfish 4.0, and Atmosphere 2.1.3.

I'm also seeing the same behavior - the message is successfully received by the Endpoint, but it it fails getting sent to the browser.

In firebug, I'm seeing this error when I click the counter button:

Code: Select all

The connection to ws://localhost:26293/pushtest/primepush/mytest?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.0-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-Cache-Date=0&X-atmo-protocol=true was interrupted while the page was loading.
Any feedback would be greatly appreciated. We were using push successfully prior to upgrading to Primefaces 5.0.
1. what version of Firefox are you using (what is full version # of firefox that you are using)?

2. Are you using PrimeFaces 5.0 final release or a snapshot build/version of PrimeFaces 5.0?

3. Do you see this error when you use Google Chrome?
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

smithh032772
Posts: 6144
Joined: 10 Sep 2011, 21:10

28 May 2014, 22:28

ekraffmiller wrote:On other piece of info: I'm using the primefaces-extensions library, for a page layout on another page in my app. Don't know if that would make a difference.
reply with 'all' xhtml pages that are displayed at same time when p:socket is on the page.
Howard

PrimeFaces 6.0, Extensions 6.0.0, Push (Atmosphere 2.4.0)
TomEE+ 1.7.4 (Tomcat 7.0.68), MyFaces Core 2.2.9, JDK8
JUEL 2.2.7 | OmniFaces | EclipseLink-JPA/Derby | Chrome

Java EE 6 Tutorial|NetBeans|Google|Stackoverflow|PrimeFaces|Apache

ekraffmiller
Posts: 8
Joined: 21 May 2014, 21:38

28 May 2014, 23:12

smithh032772 wrote: 1. what version of Firefox are you using (what is full version # of firefox that you are using)?

2. Are you using PrimeFaces 5.0 final release or a snapshot build/version of PrimeFaces 5.0?

3. Do you see this error when you use Google Chrome?
1. I am using Firefox version 29.0.1
2. I am using the final release of Primefaces 5.0
3. I'm also seeing this error in Google Chrome ( version 35.0.1916.114) and Safari (version 7.0.3)

I'm also tried deploying the showcase-5.0 war file, and I'm seeing the same problem in the Counter example.

ekraffmiller
Posts: 8
Joined: 21 May 2014, 21:38

28 May 2014, 23:14

smithh032772 wrote:
reply with 'all' xhtml pages that are displayed at same time when p:socket is on the page.
There is only one simple xhtml page that is used in my test - here is the whole page:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"    
      xmlns:c="http://java.sun.com/jsp/jstl/core"
      xmlns:o="http://omnifaces.org/ui">
    <h:head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    </h:head>
    <h:body>
        <h:form id="myForm">
            <p:commandButton value="send message" actionListener="#{testBean.sendMessage()}"/>                                
                <h:outputText styleClass="messageDisplay" id="test1" value="hello text!"/>
        </h:form>
         <p:socket channel="/mytest" onMessage="handleMessage" autoConnect="true"  >
          </p:socket>
        <script type="text/javascript">
            // <![CDATA[
            function handleMessage(data) {                      
           //     $('.messageDisplay').text(data);
              document.getElementById('myForm:messageDisplay').text(data);
            }     // ]]>
        </script>

    </h:body>
</html>
Thanks,
Ellen

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 43 guests