use of org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint in project Smack by igniterealtime.
the class WebSocketConnectionAttemptState method establishWebSocketConnection.
private void establishWebSocketConnection(List<? extends WebSocketRemoteConnectionEndpoint> webSocketEndpoints, List<Exception> failures) throws InterruptedException {
final int endpointCount = webSocketEndpoints.size();
List<SmackFuture<AbstractWebSocket, Exception>> futures = new ArrayList<>(endpointCount);
{
List<AbstractWebSocket> webSockets = new ArrayList<>(endpointCount);
// First only create the AbstractWebSocket instances, in case a constructor throws.
for (WebSocketRemoteConnectionEndpoint endpoint : webSocketEndpoints) {
AbstractWebSocket webSocket = webSocketFactory.create(endpoint, connectionInternal);
webSockets.add(webSocket);
}
for (AbstractWebSocket webSocket : webSockets) {
SmackFuture<AbstractWebSocket, Exception> future = webSocket.getFuture();
futures.add(future);
}
}
SmackFuture.await(futures, connectionInternal.connection.getReplyTimeout());
for (SmackFuture<AbstractWebSocket, Exception> future : futures) {
AbstractWebSocket connectedWebSocket = future.getIfAvailable();
if (connectedWebSocket == null) {
Exception exception = future.getExceptionIfAvailable();
assert exception != null;
failures.add(exception);
continue;
}
if (webSocket == null) {
webSocket = connectedWebSocket;
// futures and close remaining successfully connected ones.
continue;
}
connectedWebSocket.disconnect(1000, "Using other connection endpoint at " + webSocket.getEndpoint());
}
}
use of org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint in project Smack by igniterealtime.
the class WebSocketFactoryServiceTestUtil method createWebSocketTest.
public static void createWebSocketTest(Class<? extends AbstractWebSocket> expected) throws URISyntaxException {
WebSocketRemoteConnectionEndpoint endpoint = WebSocketRemoteConnectionEndpoint.from("wss://example.org");
ModularXmppClientToServerConnectionInternal connectionInternal = mock(ModularXmppClientToServerConnectionInternal.class);
AbstractWebSocket websocket = WebSocketFactoryService.createWebSocket(endpoint, connectionInternal);
assertEquals(expected, websocket.getClass());
}
use of org.jivesoftware.smack.websocket.rce.WebSocketRemoteConnectionEndpoint in project Smack by igniterealtime.
the class Java11WebSocketFactoryTest method returnsNotNullTest.
public void returnsNotNullTest() {
WebSocketRemoteConnectionEndpoint endpoint = mock(WebSocketRemoteConnectionEndpoint.class);
ModularXmppClientToServerConnectionInternal connectionInternal = mock(ModularXmppClientToServerConnectionInternal.class);
Java11WebSocket java11WebSocket = Java11WebSocketFactory.INSTANCE.create(endpoint, connectionInternal);
assertNotNull(java11WebSocket);
}
Aggregations