Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wss web socket creation issue #10

Closed
prakashkolandaivelu opened this issue Jun 17, 2016 · 2 comments
Closed

wss web socket creation issue #10

prakashkolandaivelu opened this issue Jun 17, 2016 · 2 comments

Comments

@prakashkolandaivelu
Copy link

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.

@aniruddhambarkar
Copy link

Facing same issue for WSS.. tried setting SSL context but still same issue

@prakashkolandaivelu
Copy link
Author

    super(serverURI, draft);
    SSLContext sslContext;
    try {
        sslContext = SSLContext.getInstance("SSL");
        // set up a TrustManager that trusts everything
        sslContext.init(null, new TrustManager[] { new X509TrustManager() {
            public X509Certificate[] getAcceptedIssuers() {
                logger.debug("getAcceptedIssuers =============");
                return null;
            }

            public void checkClientTrusted(X509Certificate[] certs, String authType) {
                logger.debug("checkClientTrusted =============");
            }

            public void checkServerTrusted(X509Certificate[] certs, String authType) {
                logger.debug("checkServerTrusted =============");
            }
        } }, new SecureRandom());
        this.setWebSocketFactory(new DefaultSSLWebSocketClientFactory(sslContext));
        this.messageHandlerList = messageHandlerList;
    } catch (Exception e) {
        logger.error("Error while creating the Socket object {}");
    }
    logger.debug("Socket object created");

I changed the Constructor something like this to make it work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants