title: Primefaces Push onMessage not working
body: <p>I am trying out the notify example from <a href="http://www.primefaces.org/showcase/push/notify.xhtml" rel="nofollow noreferrer">http://www.primefaces.org/showcase/push/notify.xhtml</a></p>
  
  <p>I am using primefaces 5 and glassfish 4.</p>
  
  <p>However, my <code>onMessage</code> code is not getting called.</p>
  
  <p>My web.xml</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;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"&gt;
      &lt;context-param&gt;
          &lt;param-name&gt;javax.faces.PROJECT_STAGE&lt;/param-name&gt;
          &lt;param-value&gt;Development&lt;/param-value&gt;
      &lt;/context-param&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;javax.faces.webapp.FacesServlet&lt;/servlet-class&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Faces Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;*.xhtml&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Push Servlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.primefaces.push.PushServlet&lt;/servlet-class&gt;
          &lt;async-supported&gt;true&lt;/async-supported&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Push Servlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/primepush/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;  
      &lt;session-config&gt;
          &lt;session-timeout&gt;
              30
          &lt;/session-timeout&gt;
      &lt;/session-config&gt;
      &lt;welcome-file-list&gt;
          &lt;welcome-file&gt;index.xhtml&lt;/welcome-file&gt;
      &lt;/welcome-file-list&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p>My index.xhtml</p>
  
  <pre class="lang-xhtml prettyprint-override"><code>&lt;?xml version='1.0' encoding='UTF-8' ?&gt;
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  &lt;html xmlns="http://www.w3.org/1999/xhtml"
        xmlns:h="http://xmlns.jcp.org/jsf/html"
        xmlns:p="http://primefaces.org/ui"
        &gt;
      &lt;h:head&gt;
          &lt;title&gt;Facelet Title&lt;/title&gt;
      &lt;/h:head&gt;
      &lt;h:body&gt;
          &lt;p:growl widgetVar="growl" showDetail="true" /&gt;
  
          &lt;h:form&gt;
              &lt;h:panelGrid columns="2"&gt;
                  &lt;p:outputLabel for="summary" value="Summary: " /&gt; 
                  &lt;p:inputText id="summary" value="#{notifyView.summary}" required="true" /&gt;
  
                  &lt;p:outputLabel for="detail" value="Detail: " /&gt; 
                  &lt;p:inputText id="detail" value="#{notifyView.detail}" required="true" /&gt;
              &lt;/h:panelGrid&gt;
  
              &lt;p:commandButton value="Send" actionListener="#{notifyView.send}" /&gt;
          &lt;/h:form&gt;
  
          &lt;p:socket onMessage="handleMessage" channel="/notify" /&gt;
  
          &lt;script type="text/javascript"&gt;
              function handleMessage(facesmessage) {
                  facesmessage.severity = 'info';
  
                  PF('growl').show([facesmessage]);
              }
          &lt;/script&gt;
      &lt;/h:body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>My NotifyView.java</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package org.primefaces.showcase.push.notify;
  
  import javax.faces.application.FacesMessage;
  import javax.faces.bean.ManagedBean;
  import javax.faces.bean.RequestScoped;
  import org.apache.commons.lang3.StringEscapeUtils;
  import org.primefaces.push.EventBus;
  import org.primefaces.push.EventBusFactory;
  
  @ManagedBean
  @RequestScoped
  public class NotifyView {
  
      private final static String CHANNEL = "/notify";
  
      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.escapeHtml3(summary), StringEscapeUtils.escapeHtml3(detail)));
          System.out.println("Send");
      }
  }
  </code></pre>
  
  <p>My NotifyResource.java</p>
  
  <pre><code>/*
   * To change this license header, choose License Headers in Project Properties.
   * To change this template file, choose Tools | Templates
   * and open the template in the editor.
   */
  
  package org.primefaces.showcase.push.notify;
  
  import javax.faces.application.FacesMessage;
  import org.primefaces.push.annotation.OnMessage;
  import org.primefaces.push.annotation.PushEndpoint;
  import org.primefaces.push.impl.JSONEncoder;
  
  @PushEndpoint("/notify")
  public class NotifyResource {
  
      @OnMessage(encoders = {JSONEncoder.class})
      public FacesMessage onMessage(FacesMessage message) {
          System.out.println("onMessage");
          return message;
      }
  
  }
  </code></pre>
  
  <p>All the files in my library
  <img src="https://i.stack.imgur.com/A0in8.png" alt="enter image description here"></p>
  
  <p>I have included a <code>println("onMessage")</code> to check whether  @OnMessage in NotifyResource.java is called.
  For some reason, the @OnMessage in NotifyResource.java did not get called.</p>
  
  <p>Any idea on why is this so?</p>