我有以下代码
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());
}
它可以很好地连接到connectToServer,但是等待一段时间,然后给出连接超时异常。
我在设置HttpClient连接时遇到问题,因为我必须正确设置与代理的连接,这与
有关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();
如何使WebsocketContainer以类似的方式工作?还是有更好的方法来做到这一点?
答案 0 :(得分:0)
我已经使用了以下代码
session = client.connectToServer(new MyEndpoint() , ClientEndpointConfig.Builder.create().build(),URI.create("wss://client.pushover.net/push"));
我使用来自ClientManager的客户端,而不是使用ClientEndpointConfig的WebSocketContainer。