0

I got - closed connection -1 , draft org.java_websocket.drafts.Draft_17@75599672 refuses handshake , false - then changed the code as below:

Socket creation coode

    webClient = new APICWebClient(new URI(getWebSocketUrl(currentApic.IPAddress, port)), new Draft_17());
                webClient.connect();

Constructor:
    public APICWebClient(URI serverURI, Draft draft) {
        super(serverURI, draft);

        SSLContext sslContext = null;
        try {
            sslContext = SSLContext.getDefault();
        } catch (NoSuchAlgorithmException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));
        logger.info("Socket object created");
    }

Draft_17. I get : closed connection -1 , , true. Any help here. This happens during socket creation.

Prakash
  • 145
  • 1
  • 13

1 Answers1

0

Need to create sslcontext like below. it skips the certificate. I was successfully able make a connection without certificate

SSLContext sslContext = SSLContext.getInstance("SSL");

// set up a TrustManager that trusts everything
sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                    System.out.println("getAcceptedIssuers =============");
                    return null;
            }

            public void checkClientTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkClientTrusted =============");
            }

            public void checkServerTrusted(X509Certificate[] certs,
                            String authType) {
                    System.out.println("checkServerTrusted =============");
            }
} }, new SecureRandom());
Prakash
  • 145
  • 1
  • 13