websocketjettyomnifaces

Problem when deploying project with web socket on Jetty 9.2.13.v20150730


I've experienced a problem while migrating an app from PrimeFaces 5.2 to 10. This problem is related to migration of web socket implementation from Primefaces to Omnifaces.

The versions I'm using:

I don't have anything fancy, just a simple PushBean which sends a message.

I've tried downgrading to PF8, but, as expected, the result is the same.

The configuration is made as requested in the documentation, in my web.xml file having this flag enabled:

<context-param>
    <param-name>org.omnifaces.SOCKET_ENDPOINT_ENABLED</param-name>
    <param-value>true</param-value>
</context-param>

However, when I try to deploy my app to jetty, I'm receiving the following error:

java.lang.IllegalStateException: OmniFaces failed to initialize! Report an issue to OmniFaces.
    at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:88)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)

. . .

Caused by: java.lang.RuntimeException: Cannot load platform configurator
    at javax.websocket.server.ServerEndpointConfig$Configurator.fetchContainerDefaultConfigurator(ServerEndpointConfig.java:123)
    at javax.websocket.server.DefaultServerEndpointConfig.<init>(DefaultServerEndpointConfig.java:85)
    at javax.websocket.server.ServerEndpointConfig$Builder.build(ServerEndpointConfig.java:301)
    at org.omnifaces.cdi.push.Socket.registerEndpointIfNecessary(Socket.java:1114)
    at org.omnifaces.ApplicationListener.contextInitialized(ApplicationListener.java:85)
    at org.eclipse.jetty.server.handler.ContextHandler.callContextInitialized(ContextHandler.java:800)
    at org.eclipse.jetty.servlet.ServletContextHandler.callContextInitialized(ServletContextHandler.java:444)
    at org.eclipse.jetty.server.handler.ContextHandler.startContext(ContextHandler.java:791)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:294)

I'm guessing that there is something that I'm not doing right, but, I don't know exactly what is it. Can you please, give a little hand?

Thanks in advance!


Solution

  • The stacktrace / exception ...

    Caused by: java.lang.RuntimeException: Cannot load platform configurator
        at javax.websocket.server.ServerEndpointConfig$Configurator.fetchContainerDefaultConfigurator(ServerEndpointConfig.java:123)
        at javax.websocket.server.DefaultServerEndpointConfig.<init>(DefaultServerEndpointConfig.java:85)
        at javax.websocket.server.ServerEndpointConfig$Builder.build(ServerEndpointConfig.java:301)
    

    This is coming from the javax.websocket API jar, when it attempts to find the Server Container Default Configuration (in other words, the implementation specific defaults, which would be Jetty)

    If you are running Jetty, you need to be including the jetty support jar for javax.websocket.server in your classpath.

    Which on Jetty 9.2.x would be the javax-websocket-server-impl-<ver>.jar file (and associated dependencies).

    Per @BalusC, omnifaces is just a web-fragment deployed in your WAR's WEB-INF/lib.

    That means you have to enable support for websocket on the Jetty server side.

    For standalone (using ${jetty.base} and ${jetty.home} split) this means enabling the correct module for your version of Jetty.

    Jetty ver WebSocket spec Module
    Jetty 8.x and older n/a n/a
    Jetty 9.0.x n/a n/a
    Jetty 9.1.x javax.websocket (beta) websocket
    Jetty 9.2.x - 9.4.x javax.websocket 1.0 websocket
    Jetty 10.0.x javax.websocket 1.1 websocket-javax
    Jetty 11.0.x jakarta.websocket 2.0 websocket-jakarta

    To do that you'll use the command line.

    Jetty 9.x

    [~]$ cd /path/to/my-jetty-base
    [my-jetty-base]$ java -jar /path/to/jetty-home/start.jar 
       --add-to-start=websocket
    

    Jetty 10+

    [~]$ cd /path/to/my-jetty-base
    [my-jetty-base]$ java -jar /path/to/jetty-home/start.jar 
       --add-module=websocket-javax