I created a simple websocket client using tyrus standaline client
library (libs-tyrus-standalone-client-1.7.jar). It works nicely when
connecting to an unsecure websocket, or if connecting to the secure
echo server on "wss://echo.websocket.org". But when I try to connect to
my own secure server, I receive the following exception:
javax.websocket.DeploymentException: Handshake response not received.
at
org.glassfish.tyrus.client.ClientManager$1$1.run(ClientManager.java:570
)
at
org.glassfish.tyrus.client.ClientManager$1.run(ClientManager.java:582)
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown
Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at
org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.exec
ute(ClientManager.java:734)
at java.util.concurrent.AbstractExecutorService.submit(Unknown
Source)
at
org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.
java:431)
at
org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.
java:267)
at WSClient.main(WSClient.java:27)
Here is my client implementation:
@ClientEndpoint
public class WSClient {
@OnMessage
public void onMessage(String message) {
System.out.println("Received msg: " + message);
}
public static void main(String[] args) throws Exception {
WebSocketContainer container = null;//
Session session = null;
try {
container =
ContainerProvider.getWebSocketContainer();
String uri =
"wss://localhost:8443/test/websocket";
//String uri = "wss://echo.websocket.org";
session =
container.connectToServer(WSClient.class,
URI.create(uri));
} catch (Exception e) {
e.printStackTrace();
}
BufferedReader bf = new BufferedReader(new
InputStreamReader(System.in));
String line;
while((line = bf.readLine())!= null) {
session.getBasicRemote().sendText(line);
}
}
}
And my server part:
@ServerEndpoint("/websocket")
public class TestWebSocket {
private static final Logger logger =
Logger.getLogger("WEBSOCKET");
Session session;
@OnOpen
public void openConnection(Session session) {
this.session = session;
logger.info(this+" session opened. " + session);
}
@OnClose
public void closedConnection(Session session) {
logger.info("Connection closed. " + session);
}
@OnError
public void error(Session session, Throwable t) {
logger.info(t.toString());
logger.info("Connection error.");
}
@OnMessage
public void handleMessage(String message) {
logger.info(this+ "message: " + message);
//echo the message
try {
session.getBasicRemote().sendText(message);
} catch (Exception e) {
logger.info("error while sending: " +
e.toString());
}
}
}
I´m running the server on Tomcat 7.0.54. I tried configuring Tomcat
with BIO, NIO and APR for secure connector. This error happens with all
of them. The websocket (secure) works with HTML client and even with an
iOS app client. Is there anything I am missing?