PF5.2 and push OK, 5.3 do not work anymore !

UI Components for JSF
magsam
Posts: 71
Joined: 18 Jun 2012, 17:43
Location: Bavaria, DE
Contact:

10 Nov 2015, 10:36

PF 5.3 and atmosphere 2.4.0 work correct . try this, important is the

@Inject private EventBus eventBus; (the exampel for ChatResource in the showcase is not correct )


Code: Select all

public class ChatResource {

    @PathParam("room")
    private String room;

    @PathParam("user")
    private String username;

    @Inject
    private ServletContext ctx;

    @Inject
    private EventBus eventBus;
    @Inject
    private RemoteEndpoint endpoint;

    @OnOpen
    public void onOpen() {
        eventBus.publish(room + "/*", new Message(String.format("%s has entered the room '%s'",  username, room), true));
    }

    @OnClose
    public void onClose() {
        ChatUsers users= (ChatUsers) ctx.getAttribute("chatUsers");
        users.remove(username);               
        eventBus.publish(room + "/*", new Message(String.format("%s has left the room", username), true));
    }

    @OnMessage(decoders = {MessageDecoder.class}, encoders = {MessageEncoder.class})
    public Message onMessage(Message message) {
        return message;
    }
PrimeFaces 6.1, Extensions 6.1.1 , Mojarra 2.3 , GlassFish Server Open Source Edition 4.1 (build 13) , atmosphere-runtime 2.4.9 , Open Source ERP with Primefaces http://osretail.de/osRetail/

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

10 Nov 2015, 17:58

magsam wrote:PF 5.3 and atmosphere 2.4.0 work correct . try this, important is the

@Inject private EventBus eventBus; (the exampel for ChatResource in the showcase is not correct )
can you create an issue on PrimeFaces github to 'update' (or correct) the ChatResource code in the showcase app?
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

Miguel Cubells
Posts: 99
Joined: 25 Feb 2015, 11:02

11 Nov 2015, 04:54

I must be missing something...

In our @PushEndpoint class, it seems @Inject EventBus cannot work at all.
WildFly 8 complains during startup, that the injection cannot be satisfied.

The below class works fine under PF 5.2 + Atmosphere 2.3.4, but EventBus parameter becomes NULL under PF 5.3 + Atmosphere 2.4.0:

Code: Select all

@PushEndpoint("/push/{view}")
@Singleton
public class EndPointListener {

    /** The view id. */
    @PathParam("view")
    private String view;

    @OnOpen
    public void onOpen(RemoteEndpoint r, EventBus eventBus) {
    	/*
    	 * eventBus parameter is Ok with PF 5.2 + Atmosphere 2.3.4
    	 * but becomes NULL with PF 5.3 + Atmosphere 2.4.0
    	 */
    }

    @OnClose
    public void onClose(RemoteEndpoint r) {
    }

    @OnMessage(encoders = {JSONEncoder.class})
    public PushExecutionEvent onMessage(PushExecutionEvent event) {
        return event;
    }

    public String getView() {
        return view;
    }

    public void setView(String view) {
        this.view = view;
    }
}
Using the EventFactory does the trick, and it works fine in PF 5.3 + Atmosphere 2.4.0:

Code: Select all

    @OnOpen
    public void onOpen(RemoteEndpoint r) {
    	/*
    	 * getting eventBus with EventBusFactory works fine with PF 5.3 + Atmosphere 2.4.0
    	 */
    	EventBus eventBus = EventBusFactory.getDefault().eventBus();
    }
But if trying the @Inject approach, as shown below, two things happen:

- Eclipse IDE already warns that there is no eligible bean for an EventBus injection, which is suspicious.
- WildFly 8.2.0 fails to deploy the application, because the EventBus injection cannot be satisfied ( confirms Eclipse warning )

Code: Select all

    @Inject
    private EventBus eventBus;

    @OnOpen
    public void onOpen() {
    	/*
    	 * eventBus cannot be injected!! 
    	 * WildFly 8 complains during application startup.
    	 */    	
    }
So my question is:

- How can you make a succesful injection of EventBus in a @PushEndpoint class?
- Why the original code that works in PF 5.2 + Atmosphere 2.3.4, just doesn't work with PF 5.3 + Atmosphere 2.4.0 without having to make code changes ???


Thanks in advance !
PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final

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

11 Nov 2015, 11:21

That's a question for Jeanfrancois on the atmosphere framework google groups mail list. Please ask there and reply here with any/all findings. Thanks.
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

Houdre
Posts: 12
Joined: 29 Apr 2013, 12:22

05 Jan 2016, 15:35

We got the same issue when we raised versions of PF from 5.1 to 5.3 and Atmoshpere from 2.2.2 to 2.4.1.4. I think the issue is in the construction of the EventBusFactory.

The class is not a singleton so the old usage (EventBusFactory.getDefault().eventBus();) will throw a NPE.

PF 5.3 source code:

Code: Select all

/**
* A Factory for retrieving the current {@link EventBus}
*

* It is recommended to use the @Inject EventBus instead from your @PushEndpoint.
*/
public class EventBusFactory {

@Inject
private EventBus eventBus;

private static EventBusFactory f = null;

public EventBusFactory() {
f = this;
}

/**
* Return the default factory
*
* @return the default factory
*/
public final static EventBusFactory getDefault() {
return f;
}

/**
* Return a {@link EventBus}
*
* @return a {@link EventBus}
*/
public EventBus eventBus() {
return eventBus;
}

}
PF 5.1 source:

Code: Select all

/**
 * A Factory for retrieving the current {@link EventBus}
 */
public class EventBusFactory {

    private static EventBusFactory p = new EventBusFactory();
    private EventBus eventBus = new EventBusImpl();

    protected EventBusFactory() {
    }

    /**
     * Return the default factory
     * @return the default factory
     */
    public final static EventBusFactory getDefault() {
        return p;
    }

    /**
     * Return a {@link EventBus}
     * @return a {@link EventBus}
     */
    public EventBus eventBus(){
        return eventBus;
    }

}

Miguel Cubells
Posts: 99
Joined: 25 Feb 2015, 11:02

07 Jan 2016, 11:03

Houdre wrote:We got the same issue when we raised versions of PF from 5.1 to 5.3 and Atmoshpere from 2.2.2 to 2.4.1.4. I think the issue is in the construction of the EventBusFactory.
So, did you finally switch to PF 5.3 ? If so, how did you solve the EventBus injection problem in your @PushEndpoint classes ?
PrimeFaces 6.1 / PF Extensions 6.1.1 / Atmosphere 2.4.3
Apache Mojarra 2.2.13+
WildFly 10.1.0.Final

zhzhoubin
Posts: 2
Joined: 30 Dec 2015, 21:03

15 Jan 2016, 21:01

recently, I upgraded PF from 5.2 to PF 5.3, and it works fine with atmosphere 2.4.0.

private EventBus eventBus;

the only problem is eventbus takes few milliseconds to initialize . if you use it immediately, it will report error, or silently throw away the message you pushed to end point. If you are using UI, the detail is nature, and it will work fine. If in Java application, thread needs to sleep to wait the eventbus gets fully initialized.




Miguel Cubells wrote:
Houdre wrote:We got the same issue when we raised versions of PF from 5.1 to 5.3 and Atmoshpere from 2.2.2 to 2.4.1.4. I think the issue is in the construction of the EventBusFactory.
So, did you finally switch to PF 5.3 ? If so, how did you solve the EventBus injection problem in your @PushEndpoint classes ?

zhzhoubin
Posts: 2
Joined: 30 Dec 2015, 21:03

15 Jan 2016, 21:25

recently, I upgraded PF from 5.2 to PF 5.3, and it works fine with atmosphere 2.4.0.

private EventBus eventBus;

the only problem is eventbus takes few milliseconds to initialize . if you use it immediately, it will report error, or silently throw away the message you pushed to end point. If you are using UI, the detail is nature, and it will work fine. If in Java application, thread needs to sleep to wait the eventbus gets fully initialized.

Miguel Cubells wrote:
Houdre wrote:We got the same issue when we raised versions of PF from 5.1 to 5.3 and Atmoshpere from 2.2.2 to 2.4.1.4. I think the issue is in the construction of the EventBusFactory.
So, did you finally switch to PF 5.3 ? If so, how did you solve the EventBus injection problem in your @PushEndpoint classes ?

Houdre
Posts: 12
Joined: 29 Apr 2013, 12:22

20 Jan 2016, 11:55

We created our own singleton wrapper (with mutex locking since we're calling it on every REST call) around EventBusFactory that does a null check on EventBusFactory.getDefault() and creates a new instance, not assigned to any variable, if it's null.

It's an ugly workaround but afaik it works.

nitin.kumar.gupta
Posts: 1
Joined: 11 May 2016, 04:47

11 May 2016, 09:52

I am using Spring Boot with Embeded Tomcat and Primefaces.
I have updated the primefaces from 5.2 to 5.3 and atmosphere.runtime from 2.3.2 to 2.4.0-RC6.
After updating, when I push any message to the EventBus I am getting the below error:
Can anyone help us?

2016-05-10 22:04:09.156 ERROR 6180 --- [nio-8080-exec-7] o.p.push.impl.PushEndpointHandlerProxy :

java.lang.StackOverflowError: null
at java.lang.Class.privateGetPublicMethods(Class.java:2892) ~[na:1.8.0_77]
at java.lang.Class.getMethods(Class.java:1615) ~[na:1.8.0_77]
at org.primefaces.json.JSONObject.populateMap(JSONObject.java:990) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.<init>(JSONObject.java:282) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.wrap(JSONObject.java:1570) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.populateMap(JSONObject.java:1020) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.<init>(JSONObject.java:282) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.wrap(JSONObject.java:1570) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.populateMap(JSONObject.java:1020) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.<init>(JSONObject.java:282) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.wrap(JSONObject.java:1570) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.populateMap(JSONObject.java:1020) ~[primefaces-5.3.jar:5.3]
at org.primefaces.json.JSONObject.<init>(JSONObject.java:282) ~[primefaces-5.3.jar:5.3]

Thanks in Advance.

Post Reply

Return to “PrimeFaces”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 16 guests