WebSocket Не удается найти ошибку класса реализации - PullRequest
1 голос
/ 06 июля 2019

Я планирую написать класс streamer, для которого я хотел попробовать открыть соединение с websocket, но не смог заставить работать мое соединение через websocket.Цель этого - заставить потоковые данные API TDAmeritrade работать.

пытался использовать javax.websocket-api-1.1.jar и tyrus-standalone-client-1.9

Должен ли я использоватьдругой jar?

package socketProg;
import java.net.URI;
import javax.websocket.*;
@ClientEndpoint
public class WSClient  {
    private static Object waitLock = new Object();
@OnMessage
    public void onMessage(String message) {
//the new USD rate arrives from the websocket server side.
       System.out.println("Received msg: "+message);        
    }
 private static void  wait4TerminateSignal()
 {
  synchronized(waitLock)
  {try {
    waitLock.wait();
   } catch (InterruptedException e) {    
   }}}
public static void main(String[] args) {
WebSocketContainer container=null;//
     Session session=null;
  try{
   //Tyrus is plugged via ServiceLoader API. See notes above
   container = ContainerProvider.getWebSocketContainer(); 
//WS1 is the context-root of my web.app 
//ratesrv is the  path given in the ServerEndPoint annotation on server implementation
session=container.connectToServer(WSClient.class, URI.create("ws://localhost:8080/WS1/ratesrv")); 
   wait4TerminateSignal();
  } catch (Exception e) {
   e.printStackTrace();
  }
  finally{
   if(session!=null){
    try {
 session.close();
    } catch (Exception e) {     
     e.printStackTrace();
    }

Я ожидал, что соединение установится, но получаю следующие ошибки

  1. для javax.websocket-api jar - получаю эту ошибку:

java.lang.RuntimeException: Could not find an implementation class. at javax.websocket.ContainerProvider.getWebSocketContainer(ContainerProvider.java: 73) at socketProg.WSClient.main(WSClient.java:24)

для tyrus-standalone-client-1.9 при получении этой ошибки:

javax.websocket.DeploymentException: Connection failed.
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientSocket._connect(GrizzlyClientSocket.java:404)
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientSocket.access$000(GrizzlyClientSocket.java:80)
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientSocket$1.call(GrizzlyClientSocket.java:211)
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientSocket$1.call(GrizzlyClientSocket.java:207)
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientSocket.connect(GrizzlyClientSocket.java:225)
    at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientContainer.openClientSocket(GrizzlyClientContainer.java:72)
    at org.glassfish.tyrus.client.ClientManager$3$1.run(ClientManager.java:645)
    at org.glassfish.tyrus.client.ClientManager$3.run(ClientManager.java:694)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:848)
    at java.util.concurrent.AbstractExecutorService.submit(Unknown Source)
    at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:493)
    at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:299)
    at socketProg.WSClient.main(WSClient.java:27)
Caused by: java.net.ConnectException: Connection refused: no further information
    at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
    at sun.nio.ch.SocketChannelImpl.finishConnect(Unknown Source)
    at org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler.onConnectedAsync(TCPNIOConnectorHandler.java:187)
    at org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler$1.connected(TCPNIOConnectorHandler.java:135)
    at org.glassfish.grizzly.nio.transport.TCPNIOConnection.onConnect(TCPNIOConnection.java:234)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:506)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.executeIoEvent(WorkerThreadIOStrategy.java:80)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.executeIoEvent(AbstractIOStrategy.java:66)
    at org.glassfish.grizzly.nio.SelectorRunner.iterateKeyEvents(SelectorRunner.java:391)
    at org.glassfish.grizzly.nio.SelectorRunner.iterateKeys(SelectorRunner.java:360)
    at org.glassfish.grizzly.nio.SelectorRunner.doSelect(SelectorRunner.java:324)
    at org.glassfish.grizzly.nio.SelectorRunner.run(SelectorRunner.java:255)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
    at java.lang.Thread.run(Unknown Source)
...