users@tyrus.java.net

Re: Exception on secure websocket client

From: Pavel Bucek <pavel.bucek_at_oracle.com>
Date: Wed, 18 Jun 2014 12:11:06 +0200

Hi,

yes, unless you don't have certificates signed by sume trusted authority
(you don't), you need to tweak client (or JDK where the client is
running) truststore settings little bit.

This is what we do for our tests on glassfish, you might do something
similar with Tomcat (paths and port will differ, but thats about it):

mvn ...
-Djavax.net.ssl.trustStore=$AS_MAIN/domains/domain1/config/cacerts.jks
-Djavax.net.ssl.trustStorePassword=changeit

you might also want to add "-Djavax.net.debug=all" to see SSL/TLS
related debug output.


There is also programmatic way how to set this up - for example when you
don't have access to JDK settings or you want to have different settings
per client connection:

See
https://tyrus.java.net/apidocs/1.7/org/glassfish/tyrus/client/ClientManager.html#SSL_ENGINE_CONFIGURATOR


Hope it helps,
Pavel


On 18/06/14 12:03, andre.lcm_at_gmail.com wrote:
> 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. Is there anything I am
> missing?
>