Java websocket client using tyrus in OSGi container -
as explained in question title, i'm trying create websocket client java (jar) application, later deployed osgi container (kura, if know framework).
i'm using tyrus javax.websocket implementation. note library have imported on application is: tyrus-standalone-client-1.11.jar
follows code:
client.java
import java.io.ioexception; import java.net.uri; import javax.websocket.clientendpointconfig; import javax.websocket.endpoint; import javax.websocket.endpointconfig; import javax.websocket.messagehandler; import javax.websocket.session; import org.glassfish.tyrus.client.clientmanager; public class client { private session session; public void connect() { try { final clientendpointconfig configuration = clientendpointconfig.builder.create().build(); clientmanager client = clientmanager.createclient(); client.connecttoserver( new endpoint() { @override public void onopen(session session,endpointconfig config) { client.this.session = session; client.this.session.addmessagehandler(new messagehandler.whole() { @override public void onmessage(object message) { system.out.println("received message: "+message); } }); } }, configuration, new uri("ws://echo.websocket.org")); } catch (exception e) { e.printstacktrace(); } }
and in main.java:
client client = new client(); client.connect(); try { client.sendmessage("hello world"); } catch (ioexception | interruptedexception e) { e.printstacktrace(); }
when try run code, catch same damn exception:
java.lang.classcastexception: org.glassfish.tyrus.container.grizzly.client.grizzlyclientcontainer cannot cast org.glassfish.tyrus.spi.clientcontainer
than tried modify line:
clientmanager client = clientmanager.createclient();
to
clientmanager client = clientmanager.createclient("org.glassfish.tyrus.client.clientmanager");
and following result been:
java.lang.runtimeexception: javax.websocket.deploymentexception: class org.glassfish.tyrus.client.clientmanager couldn't instantiated.
what i'm doing wrong?
thanks in advance.
Comments
Post a Comment