Websocket Client Could not find an implementation class
Asked Answered
C

4

21

I will preface this with I am not using any maven dependencies, yet I know that I am missing a jar file wls-api.jar (at least that is what I have read).

To remedy this I downloaded the oracle-weblogic-7.9.jar but the problem persists.

The exception is thrown at this line

 WebSocketContainer container = ContainerProvider.getWebSocketContainer();

Can anyone tell me why this line continuously fails?

UPDATE: upon further reading the examples I see use this dependency

<dependency>
<groupId>javax.websocket</groupId>
<artifactId>javax.websocket-api</artifactId>
<version>1.0</version>

I have javax.websocket-api.jar in the build path of the server and the client as it is required. What am I missing here?

Other update: I forgot to include the error thrown!

Exception in thread "main" java.lang.RuntimeException: Could not find an implementation class.
at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java:73)
at connect.<init>(connect.java:21)
at test.main(test.java:11)
Crichton answered 3/1, 2015 at 4:10 Comment(2)
What exception does the code throw? The fact that you are missing a dependency might still be a problem.Apatite
Sorry about that, I have updated my question to include some more information as well as the exception thrown!Crichton
S
40

javax.websocket api is only the specification don't have full implementation you may need to take the jar file tyrus-standalone-client-1.9.jar and try the same example that should solve your problem. i tested with my example and it is working fine.

hope this will help you.

Shortwave answered 19/1, 2015 at 14:9 Comment(1)
Unfortunately you are right, what I ended up doing was making a webpage that uses javascript to act as the client. I also have a phone application using the Autobahn websockets api which can be used as a client.Crichton
A
4

I think the RuntimeException you are experiencing is fortunately not generated by any direct coding fault of your own.

The method getWebSocketContainer(), as described here, simply tries to load other classes and get the static instance of the ContainerProvider in the server.

The method looks for the ContainerProvider implementation class in the order listed in the META-INF/services/javax.websocket.ContainerProvider file, returning the WebSocketContainer implementation from the ContainerProvider implementation that is not null.

This, unfortunately, means that your project is not configured correctly. Double check to make sure this file is included in your project's build path.

If other projects you are looking at are using the Maven dependency you described, I would try to set up your project to do the same.

Hope this helped!

Apatite answered 3/1, 2015 at 4:35 Comment(6)
In the build path I have the javax.websocket-api-1.1.jar do I also have to put this in the lib folder? From what I can tell this jar contains the ContainerProviderCrichton
I don't think the lib folder is anything standard, but try it and see if it works.Apatite
I have set up a few more projects and always get the same exceptionCrichton
I have one more quick question for you, do you think the project which is set up improperly is the server or the client?Crichton
My guess is that ContainerProvider would be involved in a client side implementation, since there is a specific server side implementation that extends this.Apatite
Ok, my client is not working, maybe the phone application will have better luck connecting to my serverCrichton
C
4

Adding

// https://mvnrepository.com/artifact/org.glassfish.tyrus.bundles/tyrus-standalone-client

compile group: 'org.glassfish.tyrus.bundles', name: 'tyrus-standalone-client', version: '1.9'

to my build.gradle file worked for me.

Carmancarmarthen answered 12/9, 2018 at 15:47 Comment(0)
H
3

The error "Could not find an implementation class" indicates that you don't have a JAR on your classpath that publishes a ContainerProvider implementation through a META-INF/services/javax.websocket.ContainerProvider file.

A possible client implementation that is not tied to a specific container is the tyrus-container-jdk-client package, also available in a bundle with dependencies and the websocket-api as the tyrus-standalone-client-jdk package.

Note that 1.x versions of Tyrus use the javax.websocket API from Java EE, while 2.x versions use jakarta.websocket from its successor Jakarta EE. So you can also get the error if you use a version Tyrus that is not compatible with the websocket API that you are using.

Heilungkiang answered 20/3, 2023 at 21:31 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.