First I asked this question in stackoverflow, but it looks like a server issue more than coding problem. I am developing a project with Java EE and I have access to the server computer under a university LAN. Just to give details I also add my codes below.
I am trying to connect to the server through WebSockets only on a single page.
My client websocket:
var socket = new WebSocket("wss://serverName:8181/projectName/actions");
Java Server Endpoint:
/actions
The URL where websocket is used has this structure:
https://serverName/projectName/pageName.xhtml
My context root is same as the project name. Security constraints in web.xml file:
<security-constraint>
<web-resource-collection>
<web-resource-name>SecureResource</web-resource-name>
<url-pattern>/projectName/*</url-pattern>
<http-method>GET</http-method>
<http-method>POST</http-method>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
I use Glassfish Application Server 4.1. The server has two http listeners. About listeners:
Http-Listener-1: listens port 8080, security is not enabled, websocket support is not enabled
Http-Listener-2: listens port 8181, security is enabled, websocket is enabled
SSL3 and TLS is Enabled in both of them. I am giving the server details because I am really a beginner about the server issues, so I dont know if these details are important. I also run the following commands while trying to find a fix. But these commands might not be related:
asadmin set server.network-config.protocols.protocol.http-listener-1.http.scheme-mapping=X-Forwarded-Proto
asadmin set server.network-config.protocols.protocol.http-listener-2.http.scheme-mapping=X-Forwarded-Proto
My all connections works on HTTPS without a problem. However, in the page where I use the websocket I get this error:
WebSocket connection to 'wss://serverName:8181/projectName/actions' failed: Error in connection establishment: net::ERR_CONNECTION_REFUSED
I have tried a lot of different approach. I also tried the websocket URI without the port number. Everything had worked fine before we had a digital certificate on the server computer. I just used 'ws' instead of 'wss' back then and I didnt have the security constraints in the web.xml file. However, I am unable to provide websocket connection under HTTPS after a lot of reading and tries.