Reputation: 2041
I tried to test new WebSocket feature with JSF 2.3.3(Glassfish implementation). I used Tomcat 9.0.1 as web server and followed this guide(https://javaserverfaces.github.io/whats-new-in-jsf23.html)
I created a managed bean:
@Named
@ApplicationScoped
public class Controller {
@Inject @Push
private PushContext cityChannel;
public void send() {
cityChannel.send("test");
}
}
updated index.xhtml:
<f:websocket channel="cityChannel"
onmessage="function(message){alert(message)}" />
And updated web.xml:
<context-param>
<param-name>javax.faces.ENABLE_CDI_RESOLVER_CHAIN</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.ENABLE_WEBSOCKET_ENDPOINT</param-name>
<param-value>true</param-value>
</context-param>
Unfortunately Tomcat failed to load application with an error:
SEVERE [main] com.sun.faces.config.ConfigureListener.contextInitialized Critical error during deployment:
javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/javax.faces.push/{channel}] : existing endpoint was [class com.sun.faces.push.WebsocketEndpoint] and new endpoint is [class com.sun.faces.push.WebsocketEndpoint]
at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:169)
If I remove context param javax.faces.ENABLE_WEBSOCKET_ENDPOINT then JSF runtime raises an error when I hit index.xhtml:
Caused by: java.lang.IllegalStateException: f:websocket endpoint is not enabled. You need to set web.xml context param 'javax.faces.ENABLE_WEBSOCKET_ENDPOINT' with value 'true'.
Please, advise.
Upvotes: 3
Views: 1920
Reputation: 1108852
javax.websocket.DeploymentException: Multiple Endpoints may not be deployed to the same path [/javax.faces.push/{channel}] : existing endpoint was [class com.sun.faces.push.WebsocketEndpoint] and new endpoint is [class com.sun.faces.push.WebsocketEndpoint] at org.apache.tomcat.websocket.server.WsServerContainer.addEndpoint(WsServerContainer.java:169) I
This will happen when the runtime classpath is polluted with multiple Mojarra implementations. For example, one coming from a jsf-impl.jar
file and another coming from a javax.faces.jar
file. Or perhaps even multiple different versioned one.
You need to ensure that you have only one version of a library in the runtime classpath. This does not apply specifically to Mojarra, but to every Java based library.
Installation instructions of Mojarra can be found in its README.
Upvotes: 2