ServiceConfigurationError thrown when trying to create new Jetty WebSocketClient instance

617 views Asked by At

I am trying to create a new WebSocketClient with no args constructor for cometD:

static BayeuxClient newInstace(String url) throws Exception {
    WebSocketClient wsClient = new WebSocketClient(); //exception here!!
    wsClient.start();
    Map<String, Object> options = new HashMap<>();
    ClientTransport transport = new JettyWebSocketTransport(options, Executors.newScheduledThreadPool(2), wsClient);
    BayeuxClient client = new BayeuxClient(url, transport);
    return client;
}

But this is throwing runtime exception:

java.util.ServiceConfigurationError: org.eclipse.jetty.websocket.api.extensions.Extension: Provider org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension not found
    at java.util.ServiceLoader.fail(ServiceLoader.java:225)
    at java.util.ServiceLoader.-wrap1(ServiceLoader.java)
    at java.util.ServiceLoader$LazyIterator.next(ServiceLoader.java:366)
    at java.util.ServiceLoader$1.next(ServiceLoader.java:448)
    at org.eclipse.jetty.websocket.api.extensions.ExtensionFactory.<init>(ExtensionFactory.java:35)
    at org.eclipse.jetty.websocket.client.common.extensions.WebSocketExtensionFactory.<init>(WebSocketExtensionFactory.java:36)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:117)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:108)
    at org.eclipse.jetty.websocket.client.WebSocketClient.<init>(WebSocketClient.java:88)
    at org.asd.util.customerSupportChat.LekaneClient.newInstace(LekaneClient.java:40)

This is happening on Android

minSdkVersion 21
targetSdkVersion 25

And I have included the library like this:

//https://mvnrepository.com/artifact/org.cometd.java/cometd-java-websocket-jetty-client/3.1.2
compile group: 'org.cometd.java', name: 'cometd-java-websocket-jetty-client', version: '3.1.2'

Do you know what is wrong and how can I fix this?

--------------- edit ----------------

this was also in the stacktrace:

Caused by: java.lang.ClassNotFoundException: Didn't find class "org.eclipse.jetty.websocket.common.extensions.identity.IdentityExtension" on path: DexPathList[[zip file "/data/app/org.asd.debug-2/base.apk"],nativeLibraryDirectories=[/data/app/org.asd.debug-2/lib/x86, /system/lib, /vendor/lib]]
1

There are 1 answers

0
Kaarel Purde On BEST ANSWER

As sbordet mentioned in the comments, the problem was with missing dependencies. Adding this to build.gradle fixed the problem:

compile group: 'org.eclipse.jetty.websocket', name: 'websocket-common', version: '9.2.22.v20170606'

(using old version because don't have Java 8 available)

Don't know why it isn't resolved automatically though.