Search code examples
javascriptjavaprimefaceswebsocketwebsphere

Primefaces | Push | Notify | Websphere 8.5 | Atmosphere Runtime


i am trying to run Primefaces Nofity with websphere 8.5 below are the files and error details , just stuck to do anything as no error in ide console just browser console error and p:socket is not triggering at all

below code works well with tomcat but not with web-sphere

A) web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>Notify</display-name>
  <welcome-file-list>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>



    <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>*.jsf</url-pattern>
    </servlet-mapping>

 <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>
    <init-param>
         <param-name>org.atmosphere.annotation.packages</param-name>
         <param-value>org.primefaces.push.annotation</param-value>
      </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.broadcasterClass</param-name>
        <param-value>org.atmosphere.cpr.DefaultBroadcaster</param-value>
    </init-param>
   <init-param>
        <param-name>org.atmosphere.cpr.packages</param-name>
        <param-value>com.notify.sample</param-value>
    </init-param>
    <init-param>
        <param-name>org.atmosphere.cpr.sessionSupport</param-name>
        <param-value>true</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>

</web-app>

B) faces-config.xml as

<?xml version="1.0" encoding="utf-8"?>
<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-facesconfig_2_0.xsd"
    version="2.0">


</faces-config>

C) NotifyResource.java

package com.notify.sample;


import javax.faces.application.FacesMessage;

import org.primefaces.push.EventBus;
import org.primefaces.push.RemoteEndpoint;
import org.primefaces.push.annotation.OnClose;
import org.primefaces.push.annotation.OnMessage;
import org.primefaces.push.annotation.OnOpen;
import org.primefaces.push.annotation.PushEndpoint;
import org.primefaces.push.impl.JSONEncoder;

@PushEndpoint("/notify")
public class NotifyResource {

    @OnOpen
    public void onOpen( RemoteEndpoint r, EventBus e ) {
    }

    @OnClose
    public void onClose( RemoteEndpoint r, EventBus e ) {
    }

    @OnMessage(encoders = {JSONEncoder.class})
    public FacesMessage onMessage(FacesMessage message) {
        return message;
    }

}

D) NotifyView.java

package com.notify.sample;

import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;

import org.apache.commons.lang.StringEscapeUtils;
import org.primefaces.push.EventBus;
import org.primefaces.push.EventBusFactory;

@ManagedBean
@RequestScoped
public class NotifyView {

    private final static String CHANNEL = "/notify";

    /** The Constant LOGGER. */

    private String summary;

    private String detail;

    public String getSummary() {
        return summary;
    }
    public void setSummary(String summary) {
        this.summary = summary;
    }

    public String getDetail() {
        return detail;
    }
    public void setDetail(String detail) {
        this.detail = detail;
    }

    public void send() {
        EventBus eventBus = EventBusFactory.getDefault().eventBus();
        eventBus.publish(CHANNEL, new FacesMessage(StringEscapeUtils.escapeHtml(summary), StringEscapeUtils.escapeHtml(detail)));
    }
}

E) notify.xhrml

<html  xmlns="http://www.w3.org/1999/xhtml"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:csxc="http://java.sun.com/jsf/composite/csxcomponent"
    xmlns:p="http://primefaces.org/ui">
<h:head>
    <script type="text/javascript">
        function handleMessage(facesmessage) {
            facesmessage.severity = 'info';

            PF('growl').show([facesmessage]);
        }
</script>
</h:head>
<h:body>
    <center>
    <p:panel header="Notify Form" style="width: 350;">
    <p:growl widgetVar="growl" showDetail="true" />

<h:form>
    <h:panelGrid columns="2">
        <p:outputLabel for="summary" value="Summary: " /> 

         <p:inputText id="summary" value="#{notifyView.summary}" required="true" />

        <p:outputLabel for="detail" value="Detail: " /> 
        <p:inputText id="detail" value="#{notifyView.detail}" required="true" />
    </h:panelGrid>

    <p:commandButton value="Send" actionListener="#{notifyView.send}" />
</h:form>
<p:socket onMessage="handleMessage" channel="/notify" />

    </p:panel>
    </center>
</h:body>
</html>

F) web-inf/lib

  1. commons-lang-2.4.jar
  2. atmosphere-runtime-2.3.1.jar
  3. jsf-api.jar
  4. jsf-impl.jar
  5. jstl-1.0.2.jar
  6. primefaces-5.2.10.jar
  7. slf4j-simple-1.6.1.jar
  8. slf4j.api-1.6.1.jar

G) index.jsp

<jsp:forward page="notify.jsf"></jsp:forward>

Browser Console Error

Tue May 17 2016 22:11:52 GMT+0530 (India Standard Time) Atmosphere: unload event push.js.jsf:1:39484
GET 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 5ms]
Firefox can't establish a connection to the server at ws://localhost:9080/app_notify/primepush/notify?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.9-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true. push.js.jsf:1:12442
Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). push.js.jsf:1:39484
Websocket closed, wasClean: false push.js.jsf:1:39484
Websocket failed. Downgrading to Comet and resending push.js.jsf:1:39484
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 1ms]
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]
GET 
XHR 
http://localhost:9080/app_notify/primepush/notify [HTTP/1.1 404 Not Found 2ms]

Solution

  • So we can mark as answered, I think the crux of the problem is that atmosphere is (correctly, in my opinion) relying on the underlying server for websockets support.

    The application works on WebSphere Liberty, which has support for WebSockets.

    It does not work on WebSphere traditional v8.5, which does not.

    WebSphere traditional has support for WebSockets available in beta, if using the traditional profile of WebSphere is important.