java - How to use tomcat secured web socket with javax websocket annotated Client model -
i have client program here not working wss schema works ws schema .
@clientendpoint public class wsclient { public static session usersession; protected static countdownlatch countdownlatch; @onopen public void onopen(session usersession) { wsclient.usersession = usersession; } @onclose public void onclose(session usersession, closereason reason) { calendar instance = calendar.getinstance(); date time = instance.gettime(); system.out.println(time + " : " + "closing socket reason = " + reason.getreasonphrase()); } @onmessage public void onmessage(string message) { calendar instance = calendar.getinstance(); date time = instance.gettime(); system.out.println(time + " : " + message); if (message.contains("acknowledgementid")) { jsonobject serverjsonobj = jsonutility.getfirstjsonobject(message, false); threadexecutor.connectionid = long.parselong(serverjsonobj.getstring("acknowledgementid")); countdownlatch.countdown(); } } public boolean sendmessage(string message, uri uri) { boolean done = false; try { if (usersession.isopen()) { usersession.getasyncremote().sendtext(message); done = true; } else { done = false; } } catch (exception ex) { system.out.println("sendmessage ex = " + ex.getmessage()); } return done; } public session makeconnection(uri uri) { try { wsclient client = new wsclient(); websocketcontainer container = containerprovider.getwebsocketcontainer(); container.setdefaultmaxsessionidletimeout(-1); usersession = container.connecttoserver(client, uri); } catch (deploymentexception | ioexception ex) { logger.getlogger(wsclient.class.getname()).log(level.severe, null, ex); } return usersession; } public static void main(string[] args) { try { uri uri = new uri("wss://" + websocket_url); wsclient client = new wsclient(); wsclient.countdownlatch = new countdownlatch(1); session session = client.makeconnection(uri); wsclient.countdownlatch.await(); client.sendmessage("hi", uri); } catch (exception e) { system.out.println("wsclient e = " + e.getmessage()); } } } now configured tomcat ssl connector
<connector port="443" protocol="org.apache.coyote.http11.http11nioprotocol" sslenabled="true" maxconnections="200" scheme="https" secure="true" clientauth="false" sslprotocol="tls" keystoretype="pkcs12" keystorefile="e:\keys\ssl\tomcat\keystore.pkcs12" keystorepass="keystorepass" insecurerenegotiation="true"/> according tomcat docs ,
to connect websocket client secure server endpoints, client ssl configuration controlled userproperties of provided javax.websocket.clientendpointconfig. ( have no idea little noob in it.)
i using javax websocket tyrus dependency, getting ssl handshake failure
javax.websocket.deploymentexception: ssl handshake has failed i saw links glassfish server . didn't samples or examples tomcat server ( use 8.5.16).
can explain need client make ssl handshake or throw spark how use library secured connections?
Comments
Post a Comment