Search code examples
javaspringmavenspring-mvckurento

Spring + Kurento (Jetty not working)


I have a Spring Boot app, using spring boot version 1.3.1 and Spring 4.2.4 to create a simple web application that provides a REST API and a websocket server.

I want to use the Kurento Media Server lib with this app but I'm running into some issues.

This Kurento Java lib uses Jetty to connect to the Kurento Media server using websockets. The problem I'm facing is connecting to this websocket server, it looks like there is some problem with Jetty (included in kurento-client 6.3.0 lib).

The problem happens when the websocket tries to connect to the server. The connection always fails (the kurento server is fine, see below). The logs shows a lot of information (full log dump in pastebin) but the specific problem looks like it's this:

Caused by: java.lang.AbstractMethodError: org.eclipse.jetty.io.SelectorManager.newEndPoint(Ljava/nio/channels/SocketChannel;Lorg/eclipse/jetty/io/SelectorManager$ManagedSelector;Ljava/nio/channels/SelectionKey;)Lorg/eclipse/jetty/io/EndPoint;
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.createEndPoint(SelectorManager.java:743) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processConnect(SelectorManager.java:681) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.processKey(SelectorManager.java:644) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.select(SelectorManager.java:611) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.io.SelectorManager$ManagedSelector.run(SelectorManager.java:549) [jetty-io-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.NonBlockingThread.run(NonBlockingThread.java:52) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:635) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:555) [jetty-util-9.2.14.v20151106.jar:9.2.14.v20151106]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_60]
15:58:40.574 [     pool-3-thread-1] DEBUG - o.k.j.client.JsonRpcClientWebSocket      - [KurentoClient]  Closing client
15:58:40.574 [     pool-3-thread-1] DEBUG - o.e.j.websocket.client.WebSocketClient   - Stopping org.eclipse.jetty.websocket.client.WebSocketClient@41a60b
15:58:40.576 [     pool-3-thread-1] DEBUG - o.e.j.websocket.client.WebSocketClient   - Stopped org.eclipse.jetty.websocket.client.WebSocketClient@41a60b
15:58:40.576 [       restartedMain] DEBUG - o.k.j.client.JsonRpcClientWebSocket      - [KurentoClient]  Connecting webSocket client to server ws://10.39.40.215:8888/kurento
15:58:40.576 [     pool-3-thread-1] WARN  - o.kurento.jsonrpc.client.JsonRpcClient   - [KurentoClient]  Error sending heartbeat to server. Exception: [KurentoClient]  Exception connecting to WebSocket server ws://10.39.40.215:8888/kurento
15:58:40.577 [     pool-3-thread-1] WARN  - o.kurento.jsonrpc.client.JsonRpcClient   - [KurentoClient]  Stopping heartbeat and closing client: failure during heartbeat mechanism
15:58:40.577 [     pool-3-thread-1] INFO  - o.k.j.client.JsonRpcClientWebSocket      - [KurentoClient]  Closing websocket session to force reconnection

I've already asked for help in the Kurento discussion group but no one as came up with a final answer yet. Discussion here: Exception connecting to WebSocket server.

My Kurento media server is up and there is no problem with IP's and ports and other similar problems because I can setup a websocket connection to the Kurento server from a web browser (using http://www.websocket.org/echo.html). The error is occuring in the java stack.

I've also created a standalone Jetty app from this example http://www.eclipse.org/jetty/documentation/current/jetty-websocket-client-api.html and successfully connects to the Kurento websocket server.

Is there something wrong with Jetty and Spring? Is that the problem? What should I do to fix this error?


Solution

  • The problem was with the Jetty dependencies, Kurento needs a specific version and it was not being automatically included.

    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-util</artifactId>
        <version>9.3.0.M2</version>
    </dependency>
    
    <dependency>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-io</artifactId>
        <version>9.3.0.M2</version>
    </dependency>