i am very new to JSF and Primefaces and tried to get PUSH working correctly.
The strange thing is, after i deploy the application and i test the push service, the socket endpoint doesn't get opened. When i reload the page the connection is opened. After that everything works as expected.
In essence:
The first connect after deploy fails, after that everything works fine.
I tried Firefox and Chromium but the error is the same.
The following are the console outputs of FF and Chromium
FF says:
Firefox can't establish a connection to the server at ws://localhost:8080/MyApp/primepush/VgcBfy?X-Atmosphere-tracking-id=0&X-Atmosphere-Framework=2.2.4-javascript&X-Atmosphere-Transport=websocket&X-Atmosphere-TrackMessageSize=true&X-atmo-protocol=true
GET http://localhost:8080MyApp/primepush/VgcBfy [HTTP/1.1 501 Not Implemented 3ms]
no element found VgcBfy:1
"Websocket failed. Downgrading to Comet and resending" push.js:1
GET http://localhost:8080/MyApp/primepush/VgcBfy [HTTP/1.1 501 Not Implemented 4ms]
no element found
The endpoint is randomly generated, but using a fixed endpoint doesn't help, the error persists.
My xhtml looks like:
Code: Select all
<h:body>
<c:set value="#{util.random}" target="#{viewb}" property="random"/>
<p:growl widgetVar="growl" showDetail="true" />
<h:form id="form">
<p:commandButton actionListener="#{fire.send(viewb.random)}" value="fire event"/>
</h:form>
<p:socket id="mysocket" onMessage="handleMessage" transport="websocket" channel="#{viewb.random}" widgetVar='mysocket' autoConnect="true"/>
<script type="text/javascript">
function handleMessage(data) {
try {
//console.log("handler: " + data["hall"]);
PF('growl').renderMessage({"summary":"Data received!",
"detail":data["hall"],
"severity":"info"})
}
catch (err) {
console.log(err.message);
}
}
</script>
</h:body>
Code: Select all
@ManagedBean(name="fire")
@RequestScoped
public class Fire {
public void changedEntry() {
}
public void send(String channel) {
System.out.println("[Fire]sending to "+channel);
EventBus eventBus = EventBusFactory.getDefault().eventBus();
T t = new T();
eventBus.publish(channel, t);
}
}
Code: Select all
@PushEndpoint("/{random}")
@Singleton
public class Updater {
EventBus eventBus;
@PathParam("random")
String random;
@OnOpen
public void onOpen(RemoteEndpoint r, EventBus e) {
System.out.println("[Updater] opened "+random);
this.eventBus = e;
}
@OnMessage
public void onMessage(T message){
System.out.println("[Updater-"+random+"] got message: "+message);
Gson g = new Gson();
String mmessage = g.toJson(message);
eventBus.publish("/"+random, mmessage);
}
@OnClose
public void onClose(RemoteEndpoint r, EventBus e) {
System.out.println(random+" closed");
}
}
I hope someone can point me in the right direction. My guess is, i am missing some small detail, as only the first connection after deploy fails.
regards
Pascal