RF 4.1 cr2 CDI push demo doesn't work
yyq2009 Dec 8, 2011 6:45 AMI just created a maven project to test CDI push, but it can't work, the project run well, but can not send messages to consumer, and I found that the message reached the method TopicsContext.publish, but the getTopic(resolvedKey) returns null, I don't know why.
public void publish(TopicKey key, Object data) throws MessageException {
TopicKey resolvedKey = getTopicKeyWithResolvedExpressions(key);
Topic topic = getTopic(resolvedKey);
System.out.println("=====================");
System.out.println("topic = " + topic);
System.out.println("=====================");
if (topic == null) {
throw new MessageException(MessageFormat.format("Topic {0} not found", resolvedKey.getTopicName()));
}
topic.publish(resolvedKey, data);
}
I've tried changed the version of atmosphere to 0.8RC2 or 0.8.1, when I request consumer.jsf page, it shows me can't find the class SocketSupport.
Netbeans 7.0 IDE + Mojarra 2.1.3 (FCS b02) + RF 4.1 cr2 Glassfish 3.1.1
my pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Push</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Push</name>
<properties>
<endorsed.dir>${project.build.directory}/endorsed</endorsed.dir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<hornetq.version>2.2.6.Final</hornetq.version>
<richfaces.version>4.1.0.CR2</richfaces.version>
<dependency.scope>compile</dependency.scope>
<netbeans.hint.deploy.server>gfv3ee6</netbeans.hint.deploy.server>
</properties>
<dependencies>
<dependency>
<artifactId>log4j</artifactId>
<groupId>log4j</groupId>
<type>jar</type>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-api</artifactId>
<version>${richfaces.version}</version>
</dependency><dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>${richfaces.version}</version>
</dependency><dependency>
<groupId>org.richfaces.cdk</groupId>
<artifactId>annotations</artifactId>
<version>${richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-api</artifactId>
<version>${richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>${richfaces.version}</version>
</dependency>
<dependency>
<groupId>org.atmosphere</groupId>
<artifactId>atmosphere-runtime</artifactId>
<version>0.7.2</version>
<exclusions>
<exclusion>
<artifactId>atmosphere-ping</artifactId>
<groupId>org.atmosphere</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>1.2.3</version>
</dependency>
<!-- Dependencies for CDI -->
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<version>1.0-SP2</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>jboss-public-repository-group</id>
<name>JBoss Public Maven Repository Group</name>
<url>https://repository.jboss.org/nexus/content/repositories/releases</url>
<layout>default</layout>
<releases>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</releases>
<snapshots>
<enabled>true</enabled>
<updatePolicy>never</updatePolicy>
</snapshots>
</repository>
</repositories>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<compilerArguments>
<endorseddirs>${endorsed.dir}</endorseddirs>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<outputDirectory>${endorsed.dir}</outputDirectory>
<silent>true</silent>
<artifactItems>
<artifactItem>
<groupId>javax</groupId>
<artifactId>javaee-endorsed-api</artifactId>
<version>6.0</version>
<type>jar</type>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 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-app_3_0.xsd">
<display-name>Push Demo</display-name>
<context-param>
<param-name>org.richfaces.fileUpload.maxRequestSize</param-name>
<param-value>100000</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.fileUpload.createTempFiles</param-name>
<param-value>false</param-value>
</context-param>
<context-param>
<param-name>javax.faces.PROJECT_STAGE</param-name>
<param-value>Development</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.resourceMapping.enabled</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>server</param-value>
</context-param>
<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>
<welcome-file-list>
<welcome-file>index.jsf</welcome-file>
</welcome-file-list>
<mime-mapping>
<extension>xcss</extension>
<mime-type>text/css</mime-type>
</mime-mapping>
<login-config>
<auth-method>BASIC</auth-method>
</login-config> <!-- Registers Push -->
<context-param>
<param-name>org.richfaces.push.jms.connectionUsername</param-name>
<param-value>guest</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.push.jms.connectionPassword</param-name>
<param-value>guest</param-value>
</context-param>
<context-param>
<param-name>org.richfaces.push.jms.disable</param-name>
<param-value>true</param-value>
</context-param>
<!-- Force this Servlet to use one Thread per connection
instead of native API as workaround for (RF-11064) -->
<context-param>
<param-name>org.atmosphere.useBlocking</param-name>
<param-value>true</param-value>
</context-param>
</web-app>
PushBean.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.demo.push;
import java.io.Serializable;
import java.util.UUID;
import javax.annotation.PostConstruct;
import javax.enterprise.context.SessionScoped;
import javax.enterprise.event.Event;
import javax.inject.Inject;
import javax.inject.Named;
import org.richfaces.cdi.push.Push;
@Named
@SessionScoped
public class PushBean
implements Serializable {
private static final long serialVersionUID = 1L;
private static final String PUSH_CDI_TOPIC = "pushCdi";
private String userIdentifier;
private String message;
@Inject
@Push(topic = PUSH_CDI_TOPIC , subtopic = "admin")
Event<String> pushEvent;
@PostConstruct
public void initialize() {
if (this.userIdentifier == null) {
this.userIdentifier = getUUID().replace("-", "");
}
}
public void sendMessage() {
System.out.println(message);
this.pushEvent.fire(this.message);
}
public String getUserIdentifier() {
return this.userIdentifier;
}
public String getUUID() {
return UUID.randomUUID().toString();
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
}
index.xhtml
<h:form>
<h:panelGrid columns="3">
<h:outputLabel value="Message:" />
<h:inputText styleClass="message" value="#{pushBean.message}" />
<a4j:commandButton value="Send"
action="#{pushBean.sendMessage}"
execute="@form"
oncomplete="jQuery('.message').val('')" />
</h:panelGrid>
<h:outputLink target="_blank" value="#{facesContext.externalContext.requestContextPath}/consumer.jsf?userIdentifier=admin">
<h:outputText value="Consumer"/>
</h:outputLink>
<a4j:log level="ALL" mode="inline"/>
</h:form>
consumer.xhtml
<h:form>
<h:panelGrid columns="3">
<a4j:push address="admin@pushCdi"
ondataavailable="jQuery('<li />').prependTo('#messages').text(event.rf.data)" />
<ul id="messages" />
</h:panelGrid>
</h:form>
<a4j:log level="ALL" mode="inline"/>
Can anyone explain why the topic is null?
Thanks in advance.