Alan Gaytan
Alan Gaytan

Reputation: 910

eventBus() method is returning null

I have an application that use primefaces 5.3,jsf 2.1,atmosphere-runtime 2.3.0,spring 4.0.0, servlet 3.0, I try to use push in primefaces but when I execute the line

EventBus eventBus = EventBusFactory.getDefault().eventBus();

it always return null, I searched in some pages but can't fix my problem,

This is my 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" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
    <display-name>Aclaraciones</display-name>

    <welcome-file-list>
        <welcome-file>login.xhtml</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>*.xhtml</url-pattern>
    </servlet-mapping>

    <context-param>
        <description>State saving method: 'client' or 'server' (=default). See JSF Specification 2.5.2</description>
        <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
        <param-value>server</param-value>
    </context-param>

    <context-param>
        <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
        <param-value>resources.application</param-value>
    </context-param>

    <listener>
        <listener-class>com.sun.faces.config.ConfigureListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
    </listener>

    <context-param>
        <param-name>primefaces.THEME</param-name>
        <param-value>start</param-value>
    </context-param>

    <context-param>
        <param-name>primefaces.FONT_AWESOME</param-name>
        <param-value>true</param-value>
    </context-param>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>

    <filter>
        <filter-name>filtro</filter-name>
        <filter-class>com.aclaraciones.filter.LoginFilter</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>filtro</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <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>0</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>

This is my class that use endPoint:

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

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

}

And I execute this method

public void socket(){
    EventBus eventBus = EventBusFactory.getDefault().eventBus();
    eventBus.publish("/notify", "Hola mundo");
}

Someone know what am I missing?

Thanks in advance.

Upvotes: 1

Views: 1182

Answers (2)

&#214;mer Faruk Kurt
&#214;mer Faruk Kurt

Reputation: 570

I have encountered such an error. Try to change the version of Atmosphere 2.4.3. You can also look here

EventBusFactory JSF1073

Upvotes: 1

Alan Gaytan
Alan Gaytan

Reputation: 910

I found that my problem was the version of primefaces that I was using, after try and try again I found that the version that works is the 5.2 and the atmosphere version that I use is:

    <dependency>
        <groupId>org.atmosphere</groupId>
        <artifactId>atmosphere-runtime</artifactId>
        <version>2.3.2</version>
    </dependency>

    <dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-lang3</artifactId>
        <version>3.3.2</version>
    </dependency>

    <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>javax.inject</groupId>
        <artifactId>javax.inject</artifactId>
        <version>1</version>
    </dependency>

hope this help someone else.

Upvotes: 2

Related Questions