Non-Proxy Web Sites

This is a fairly common problem, but I can not find a solution for my specific case. I am using Glassfish 4.1.1 and my application implements Websockets.

On the client side, I connect to the WS server simply:

var serviceLocation = "ws://" + window.location.host + window.location.pathname + "dialog/"; var wsocket = new WebSocket(serviceLocation + token_var); 

On server-side websites, @ServerEndpoint functions are implemented and looks very common:

 @ServerEndpoint(value = "/dialog/{token}", decoders = DialogMessageDecoder.class) public class DialogWebsoketEndpoint { @OnOpen public void open(final Session session, @PathParam("token") final String token) { ... } etc. } 

Everything works fine until the client tries to connect using a proxy. Using this test: http://websocketstest.com/ I found that the client computer is running http-proxy 1.1. It cannot connect to websites, they simply do not work at all. wsoscket.readyState will never become 1.

How to configure my ServerEndpoint so that this code works even when a client connects using a proxy?

Thank you in advance!

UPDATE: I would provide a screenshot with websocketstest on this computer: enter image description here

On my computer, this is similar, except for one: HTTP proxy: no.

+7
java javascript proxy websocket glassfish
source share
1 answer

As comments on the questions notice, it seems that Proxy does not support Websockets properly.

This is a common problem (some cellular companies have proxies that interrupt connections to web servers), and the solution is to use TLS / SSL connections.

The problem arises mainly because some proxies "fix" (read: corrupted) the Websocket request headers.

However, when using TLS / SSL, proxies cannot read header data (which is encrypted), causing the data transfer to “skip” on most proxies.

This means that headers will be sent safely at the other end, and the proxy server (mostly) ignores the connection ... this may still cause a connection timeout problem, but this usually fixes the problem.

EDIT

Please note that browsers will protect the client from mixing unencrypted content with encrypted content. Make sure the script initiates ws connections using the wss option when using TLS / SSL connections.

+10
source share

All Articles