@PushEndPoint @OnMessage is never called

UI Components for JSF
Post Reply
samm
Posts: 7
Joined: 21 May 2014, 13:02

06 Sep 2014, 15:52

Hi guys, I have been stock on this issue for over a couple of days now.

This may be a duplicate post but I wen through most of the posts in this section but could not find a solution.
I have a listener in MessageServiceNotificationListener.java which broadcasts a message upon notifictionReceived. Problems is, @OnMessage method in NotificationEndPoint.java never gets called so no message is ever sent to the socket present on home.xhtml....

here is my web.xml

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<web-app 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-app_3_0.xsd"
	version="3.0" xmlns="http://java.sun.com/xml/ns/javaee">

	<!-- Default page to serve -->
	<welcome-file-list>
		<welcome-file>home.xhtml</welcome-file>
	</welcome-file-list>
	<listener>
		<listener-class>org.apache.shiro.web.env.EnvironmentLoaderListener</listener-class>
	</listener>
	<filter>
		<filter-name>ShiroFilter</filter-name>
		<filter-class>org.apache.shiro.web.servlet.ShiroFilter</filter-class>
	</filter>

	<filter-mapping>
		<filter-name>ShiroFilter</filter-name>
		<url-pattern>/*</url-pattern>
		<dispatcher>REQUEST</dispatcher>
		<dispatcher>FORWARD</dispatcher>
		<dispatcher>INCLUDE</dispatcher>
		<dispatcher>ERROR</dispatcher>
	</filter-mapping>

	<servlet>
		<servlet-name>Faces Servlet</servlet-name>
		<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
		<load-on-startup>1</load-on-startup>
	</servlet>
	<!-- Map these files with JSF -->
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>/faces/*</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.jsf</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.faces</url-pattern>
	</servlet-mapping>
	<servlet-mapping>
		<servlet-name>Faces Servlet</servlet-name>
		<url-pattern>*.xhtml</url-pattern>
	</servlet-mapping>

	<servlet>
		<servlet-name>Push Servlet</servlet-name>
		<servlet-class>org.primefaces.push.PushServlet</servlet-class>
		<init-param>
			<param-name>org.atmosphere.cpr.BroadcasterCache</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</param-value>
		</init-param>
		<init-param>
			<param-name>org.atmosphere.cpr.packages</param-name>
			<param-value>net.dpco.ismn.web.bean.msg</param-value>
		</init-param>
		<init-param>
			<param-name>org.atmosphere.useWebSocket</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>org.atmosphere.useNative</param-name>
			<param-value>true</param-value>
		</init-param>
		<init-param>
			<param-name>org.atmosphere.cpr.sessionSupport</param-name>
			<param-value>true</param-value>
		</init-param>
		<load-on-startup>1</load-on-startup>
		<async-supported>true</async-supported>
	</servlet>
	<servlet-mapping>
		<servlet-name>Push Servlet</servlet-name>
		<url-pattern>/primepush/*</url-pattern>
	</servlet-mapping>

</web-app>
Here is my pom.xml

Code: Select all

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<parent>
		<groupId>net.dpco.ismn</groupId>
		<artifactId>ismn</artifactId>
		<version>2.0.0</version>
	</parent>
	<groupId>${parent.groupId}</groupId>
	<artifactId>${parent.artifactId}-web</artifactId>
	<version>2.3.0-SNAPSHOT</version>
	<packaging>war</packaging>
	<name>ISMN Web Interface</name>
	<dependencies>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>gnr-common</artifactId>
			<version>${project.version}</version>
			<exclusions>
				<exclusion>
					<groupId>net.dpco.ismn</groupId>
					<artifactId>communication-framework</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>tmc-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>communication-framework</artifactId>
			<version>2.0.0-SNAPSHOT</version>
			<exclusions>
				<exclusion>
					<groupId>javax.servlet</groupId>
					<artifactId>servlet-api</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.apache.activemq</groupId>
					<artifactId>activemq-core</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>jetty</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>jetty-util</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>jsp-api-2.1</artifactId>
				</exclusion>
				<exclusion>
					<groupId>org.mortbay.jetty</groupId>
					<artifactId>jsp-2.1</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>mtools-common</artifactId>
			<version>${project.version}</version>
			<exclusions>
				<exclusion>
					<groupId>ISMNAgent</groupId>
					<artifactId>ISMNAgent</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>tma-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>als-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>trt-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>flc-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>core-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>inv-common</artifactId>
			<version>${project.version}</version>
			<exclusions>
				<exclusion>
					<groupId>xml-apis</groupId>
					<artifactId>xml-apis</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>net.dpco.ismn</groupId>
			<artifactId>sec-common</artifactId>
			<version>${project.version}</version>
		</dependency>
		<dependency>
			<groupId>org.primefaces</groupId>
			<artifactId>primefaces</artifactId>
			<version>5.0</version>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-core</artifactId>
			<version>1.2.3</version>
		</dependency>
		<dependency>
			<groupId>org.apache.shiro</groupId>
			<artifactId>shiro-web</artifactId>
			<version>1.2.3</version>
		</dependency>
		<dependency>
			<groupId>commons-logging</groupId>
			<artifactId>commons-logging</artifactId>
			<version>1.1.1</version>
		</dependency>
		<dependency>
			<groupId>junit</groupId>
			<artifactId>junit</artifactId>
			<version>4.11</version>
			<scope>test</scope>
		</dependency>
		<dependency>
			<groupId>com.sun.faces</groupId>
			<artifactId>jsf-api</artifactId>
			<version>2.2.5</version>
		</dependency>
		<dependency>
			<groupId>com.sun.faces</groupId>
			<artifactId>jsf-impl</artifactId>
			<version>2.2.5</version>
		</dependency>
		<dependency>
			<groupId>org.primefaces.themes</groupId>
			<artifactId>all-themes</artifactId>
			<version>1.0.10</version>
		</dependency>
		<dependency>
			<groupId>org.primefaces.extensions</groupId>
			<artifactId>primefaces-extensions</artifactId>
			<version>1.1.0</version>
		</dependency>
		<dependency>
			<groupId>org.atmosphere</groupId>
			<artifactId>atmosphere-runtime-native</artifactId>
			<version>2.2.0</version>
		</dependency>
		<dependency>
			<groupId>org.atmosphere</groupId>
			<artifactId>atmosphere-annotations</artifactId>
			<version>2.2.0</version>
			<exclusions>
				<exclusion>
					<groupId>org.atmosphere</groupId>
					<artifactId>atmosphere-runtime</artifactId>
				</exclusion>
			</exclusions>
		</dependency>
		<dependency>
			<groupId>com.google.code.gson</groupId>
			<artifactId>gson</artifactId>
			<version>2.2.4</version>
		</dependency>
		<dependency>
			<groupId>org.easymock</groupId>
			<artifactId>easymock</artifactId>
			<version>3.2</version>
			<scope>test</scope>
		</dependency>
		<!-- <dependency> -->
		<!-- <groupId>org.jboss.arquillian.junit</groupId> -->
		<!-- <artifactId>arquillian-junit-container</artifactId> -->
		<!-- <scope>test</scope> -->
		<!-- </dependency> -->
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-api</artifactId>
			<version>1.7.5</version>
		</dependency>
		<dependency>
			<groupId>org.slf4j</groupId>
			<artifactId>slf4j-simple</artifactId>
			<version>1.7.5</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>3.0.1</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.tomcat</groupId>
			<artifactId>tomcat-websocket-api</artifactId>
			<version>8.0.9</version>
			<scope>provided</scope>
		</dependency>
		<dependency>
			<groupId>org.apache.activemq</groupId>
			<artifactId>activemq-all</artifactId>
			<version>5.6.0</version>
		</dependency>
	</dependencies>
	<build>
		<plugins>
			<plugin>
				<groupId>org.codehaus.mojo</groupId>
				<artifactId>native2ascii-maven-plugin</artifactId>
				<version>1.0-beta-1</version>
				<executions>
					<execution>
						<goals>
							<goal>native2ascii</goal>
						</goals>
						<configuration>
							<src>${basedir}/src/main/resources</src>
							<dest>${project.build.directory}/native2ascii</dest>
							<encoding>UTF8</encoding>
							<include>**\/*.xsd</include>
						</configuration>
					</execution>
				</executions>
			</plugin>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.1</version>
				<configuration>
					<source>1.7</source>
					<target>1.7</target>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-war-plugin</artifactId>
				<configuration>
					<archive>
						<manifestEntries>
							<Dependencies>org.apache.shiro</Dependencies>
						</manifestEntries>
					</archive>
				</configuration>
			</plugin>
			<plugin>
				<groupId>org.apache.tomcat.maven</groupId>
				<artifactId>tomcat7-maven-plugin</artifactId>
				<version>2.2</version>
				<executions>
					<execution>
						<id>deploy</id>
						<phase>install</phase>
						<goals>
							<goal>deploy</goal>
						</goals>
						<configuration>
							<force>true</force>
						</configuration>
					</execution>
					<execution>
						<id>undeploy</id>
						<phase>clean</phase>
						<goals>
							<goal>undeploy</goal>
						</goals>
						<configuration>
							<ignoreMissingDeployment>true</ignoreMissingDeployment>
						</configuration>
					</execution>
				</executions>
				<configuration>
					<update>true</update>
					<username>admin</username>
					<password>admin</password>
				</configuration>
			</plugin>
		</plugins>
		<finalName>ismn-web</finalName>
	</build>

</project>
here is my home.xml

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 lang="en" xmlns="http://www.w3.org/1999/xhtml"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:p="http://primefaces.org/ui">
<h:head>
	<title></title>
	<h:outputStylesheet library="css" name="default.css" />
</h:head>
<h:body>
	<p:layout fullPage="true">
		<p:layoutUnit position="north" size="60">
			<h:form id="topForm">
				<h:commandLink action="#{securityBean.logout}"
					style="font-size: 14px;float:right;">logout</h:commandLink>
				<br />				
			</h:form>
			<p:panel id="rollingTextPanel">
				<p:socket onMessage="handleMessage" channel="/notification"  autoConnect="true" />
			
				<f:verbatim style="color: blue;" >
					<marquee style="color: blue; font-size: 14px;">#{userPreferences.message.message}</marquee>
				</f:verbatim>
				
				<p:dialog id="newMessageDialog" closable="false" fitViewport="true" modal="true" closeOnEscape="close" widgetVar="newMessageDialog">
					<p:panelGrid>
						 <f:facet name="header">
						 	<p:row >
						 		<p:column colspan="4">New Message</p:column>
       						</p:row>
   						 </f:facet>
   						 <p:row>
   						 	<p:column >Sender: </p:column>
   						 	<p:column >#{userPreferences.message.sender}</p:column>
   						 	<p:column >Submit Date: </p:column>
   						 	<p:column >#{userPreferences.message.submitDate}</p:column>
   						 </p:row>
   						 <p:row>
   						 	<p:column>Message: </p:column>
   						 	<p:column><h:outputText value="#{userPreferences.message.message}"/></p:column>
   						 </p:row>
   						 <p:row>
   						 	<p:column><p:commandButton update="rollingTextPanel" process="@this" value="Ok" onclick="newMessageDialog.hide()" /></p:column>
   						 </p:row>
					</p:panelGrid>
				</p:dialog>Iran
			</p:panel>
		</p:layoutUnit>
		<p:layoutUnit position="west" size="300" style="color: #99CCFF;">
			<h:form>
				<h1 style="margin-top: 0; font-size: 14px; color: blue;"></h1>
				<p:outputPanel
					style="width: 100%;height: 300px;overflow: auto;display: block">
					<p:tree id="treeConfig" value="#{treeMainView.root}" var="node"
						style="width:100%;height:100%;border-width:0;"
						selection="#{treeMainView.selectedNode}" selectionMode="single">
						<p:ajax event="select" listener="#{treeMainView.onNodeSelect}"
							process="@this @form" update="@form" />
							<p:ajax event="collapse"
							listener="#{treeMainView.onNodeCollapse}" process="@this @form"
							update="@form" />
						<p:treeNode icon="ui-icon-document">
							<h:outputText value="#{node}" />
						</p:treeNode>
					</p:tree>
				</p:outputPanel>
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<br />
				<!-- 				<h:graphicImage value="/resources/images/sidepanel.png" width="280" -->
				<!-- 					height="200" /> -->
			</h:form>
		</p:layoutUnit>
		<p:layoutUnit position="center">
			<ui:insert id="content" name="content">
			</ui:insert>

		</p:layoutUnit>
	</p:layout>
</h:body>

</html>
This is MessageServiceNotificationListener.java

Code: Select all


@ManagedBean(eager=true)
@ApplicationScoped
public class MessageServiceNotificationListener implements Notifiable, Serializable{
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 909865276675729334L;
	private static final Logger logger = Logger.getLogger(MessageServiceNotificationListener.class);
	public static final String NOTIFICATION_CHANNEL = "/notification";
	
	@Override
	public void notifactionReceived(NotificationEvent event) {
		Object data = event.getData();
		if(data instanceof LoginMessage){
			EventBus eventBus = EventBusFactory.getDefault().eventBus();
			eventBus.publish(MessageServiceNotificationListener.NOTIFICATION_CHANNEL, data);
		}
	}

	public static String getNotificationChannel() {
		return NOTIFICATION_CHANNEL;
	}

	public void subscribeToMessageService() {
		try{
			MessageService messageService = ServiceLocator.createSync(MessageService.class);
			messageService.registerForNotification(this);
			logger.debug("Successfully subscribed to Message Service");
		} catch (Exception e) {
			logger.error("Unable to subscribe to Message Service: " + e.getMessage(), e);
		}
	}
	
	@PreDestroy
	public void unsubscribeFromMessageService(){
		try {
			MessageService messageService = ServiceLocator.createSync(MessageService.class);
			messageService.deregisterForNotification(this);
			logger.debug("Successfully unsubscribed from Message Service");
		} catch (Exception e) {
			logger.error("Unable to unsubscribe from Message Service: " + e.getMessage(), e);
		} 
	}
}
this is NotificationEndPoint.java

Code: Select all


@PushEndpoint(MessageServiceNotificationListener.NOTIFICATION_CHANNEL)
@Singleton
public class NotificationEndPoint {
	
	@ManagedProperty(value="#{userPreferences}")
	private UserPreferences userPreferences;
	
	
	
	public UserPreferences getUserPreferences() {
		return userPreferences;
	}



	public void setUserPreferences(UserPreferences userPreferences) {
		this.userPreferences = userPreferences;
	}



	@OnMessage(encoders= {JSONEncoder.class})
	public LoginMessage onMessage(LoginMessage message){
		userPreferences.setMessage(message);
		return message;
	}
		
}
I also enabled tomcat NIO connector like this:

Code: Select all

<Connector connectionTimeout="20000" maxThreads="1000" port="8080" protocol="org.apache.coyote.http11.Http11NioProtocol" redirectPort="8443"/>
I'd be so thankful if anyone could help me out
Primefaces 5.0, JSF 3.0, Eclipse Juno, tomcat 8.0.11

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

08 Sep 2014, 13:28

hmmm, you're using tomcat8 + NIO + shiro.

what happens when you remove these from web.xml? i think this is saying that you prefer to use tomcat8's native websocket instead of atmosphere's websocket. as a tomee (tomcat7) user, I recommend using atmosphere's websocket, and I recommend to remove the following:

Code: Select all

      <init-param>
         <param-name>org.atmosphere.useWebSocket</param-name>
         <param-value>true</param-value>
      </init-param>
      <init-param>
         <param-name>org.atmosphere.useNative</param-name>
         <param-value>true</param-value>
      </init-param>
      <init-param>
         <param-name>org.atmosphere.cpr.sessionSupport</param-name>
         <param-value>true</param-value>
      </init-param>
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

kukeltje
Expert Member
Posts: 9605
Joined: 17 Jun 2010, 13:34
Location: Netherlands

09 Sep 2014, 07:55

@howard: Care to elaborate a little why you reccommend these changes? Is tomcat native of a low quality? Does atmosphere integrate badly with it? Are the config params counter productive?

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

09 Sep 2014, 18:28

kukeltje wrote:@howard: Care to elaborate a little why you reccommend these changes? Is tomcat native of a low quality? Does atmosphere integrate badly with it? Are the config params counter productive?
tomcat 8

and read some of those forum topics. I don't see many having much success with tomcat8 native (JSR356). why use atmosphere + tomcat8 native (JSR356)? if you want to use tomcat8 native, then use built-in tomcat8 native (JSR356) websocket without atmosphere.
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

samm
Posts: 7
Joined: 21 May 2014, 13:02

16 Oct 2014, 07:33

Guys I couldn't wait any longer for you reply since I had a strict dead line, so I left primefaces push out of my project and continued on using javax's native websocket along with tomcat8 wesocket. It indeed solved all my issues. Thank you any way for participating in this...
Primefaces 5.0, JSF 3.0, Eclipse Juno, tomcat 8.0.11

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 25 guests