f1wade f1wade - 6 months ago 38
Java Question

websocket through proxy timing out

I have the following code

ClientManager client = ClientManager.createClient();
client.getProperties().put(ClientManager.WLS_PROXY_HOST,PROXY_HOST);
client.getProperties().put(ClientManager.WLS_PROXY_PORT,""+PROXY_PORT);
client.getProperties().put(ClientManager.WLS_PROXY_PASSWORD,authPassword);
client.getProperties().put(ClientManager.WLS_PROXY_USERNAME,authUser);

WebSocketContainer container = ContainerProvider.getWebSocketContainer();
container.connectToServer(new MyEndpoint() , URI.create("wss://client.pushover.net/push"));
} catch (Exception e) {
System.out.println(e.GetMessage());
}


It gets to the connectToServer fine, but then waits for a while and then gives a Connection Timed out Exception.

I had issues setting up a HttpClient connection as i had to setup the connection to the proxy correctly, this worked with

HttpHost proxy = new HttpHost(PROXY_HOST, PROXY_PORT);
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);

AuthCache authCache = new BasicAuthCache();
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(new AuthScope(PROXY_HOST, PROXY_PORT, AuthScope.ANY_HOST, "ntlm"), new NTCredentials(authUser, authPassword, "",PROXY_DOMAIN));
HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(credsProvider);
context.setAuthCache(authCache);

httpClient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).setRoutePlanner(routePlanner).build();


How Do I make the WebsocketContainer work in a simiar way? or is there a better approach to doing this?

Answer

I have got it working with the code below

session = client.connectToServer(new MyEndpoint() , ClientEndpointConfig.Builder.create().build(),URI.create("wss://client.pushover.net/push"));

I am using the client from ClientManager, and NOT the WebSocketContainer, with a ClientEndpointConfig.

Comments