I'm really hoping someone can help me here. I'm trying to set up a secure websocket connection and cannot for the life of me to get it to work. It just always immediately rejects the connection and I have no idea why.
This is the code I'm using server side atm:
import org.vertx.java.core.Handler;
import org.vertx.java.core.buffer.Buffer;
import org.vertx.java.core.http.HttpServerRequest;
import org.vertx.java.core.http.ServerWebSocket;
import org.vertx.java.platform.Verticle;
import org.vertx.java.core.json.JsonObject;
import org.vertx.java.core.json.JsonArray;
public class PF_Character_Server extends Verticle {
vertx.createHttpServer().setSSL(true).setKeyStorePath("keystore.jks").setKeyStorePassword("mypass").websocketHandler(new Handler<ServerWebSocket>() {
public void handle(final ServerWebSocket ws) {
//if (ws.path().equals("/pfcharacter")) {
ws.dataHandler(new Handler<Buffer>() {
public void handle(Buffer data) {
JsonObject msg = new JsonObject(data.toString());
switch (msg.getString("type")) {
ws.writeTextFrame("SUCCESS");
ws.writeTextFrame(msg.getString("msg"));
}).requestHandler(new Handler<HttpServerRequest>() {
public void handle(HttpServerRequest req) {
if (req.path().equals("/")) req.response().sendFile("index.html"); // Serve the html
You can see I've commented out the path check because I've been trying to eliminate what could be the problem. The keystore is one that I created using:
keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass mypass -validity 360 -keysize 2048
And I did create it in the same directory as the java file. I know that it's connecting to the keystore because if I intentionally put in a bad password I get an exception about it. With the correct password however I get no exceptions.
If I try to connect to this server using wss://serveraddress:8124, the connection just immediately fires the socket.onclose event.
Everything works perfectly fine if I take out the keystore and setssl stuff and connect using ws://.
This is the client side JS I'm using atm:
var socket = new WebSocket("wss://serveraddress:8124");
socket.onmessage = function(event) {
//alert("Received data from websocket: " + event.data);
jParsed = JSON.parse(event.data);
alert("JSON Recieved from server, Type: " + jParsed["type"] + " Message: " + jParsed["msg"]);
socket.onopen = function(event) {
alert("Web Socket opened");
//socket.send("Hello World");
socket.onclose = function(event) {
alert("Web Socket closed");
alert("Your browser does not support web sockets, UPGRADE!!!!");
var jsonObj = {"type": "msg",
socket.send(JSON.stringify(jsonObj));
In case it matters, I'm using an apache2 webserver, and this is being done over a https connection.
This is really annoying, cannot find any good examples anywhere of how to set this up properly.
Thanks for any assistance you can offer.