I have an issue connecting to the web sockets after moving the application from http to https. The browser simply fails to establish the connection to the web socket displaying the below message:
GET wss://appserverURL/MyApplication/NotificationsWSEndpoint
Firefox can’t establish a connection to the server at wss://appserverURL/MyApplication/NotificationsWSEndpoint.
For https we are attaching a valid SSL certificate on port 443 and the 443 port on that VIP is setup same way as http port 80.
Any pointers on resolving this issue are highly appreciated. Thanks.
My JavaScript
var wsUri = ((window.location.protocol === "https:") ? "wss:" : "ws:") + "//" + document.location.host + "/MyApp/NotificationsWSEndpoint";
notificationsWebSocket = new WebSocket(wsUri);
var browserSupport = ("WebSocket" in window) ? true : false;
if (browserSupport) {
notificationsWebSocket.onopen = function (event) {
};
notificationsWebSocket.onmessage = function (event) {
};
notificationsWebSocket.onclose = function (event) {
};
} else {
alert("WebSocket is NOT supported by your Browser!");
}
My EndPoint
@ServerEndpoint(value = "/NotificationsWSEndpoint")
public class NotificationsWSEndpoint {
private static final Set<Session> SESSIONS = Collections.synchronizedSet(new HashSet<Session>());
@OnOpen
public void onOpen(Session session) {
try {
SESSIONS.add(session);
} catch (Exception ex) {
}
}
@OnMessage
public void onMessage(final String message, final Session client) {
try {
} catch (JSONException | NumberFormatException ex) {
}
}
public static void sendAll(String text) {
synchronized (SESSIONS) {
SESSIONS.stream().filter((session) -> (session.isOpen())).forEach((Session session) -> {
try {
session.getAsyncRemote().sendText(text);
} catch (Exception ex) {
}
});
}
}
@OnClose
public void onClose(final Session session, CloseReason closeReason) {
SESSIONS.remove(session);
}
}