private Mono<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) { MonoProcessor<Void> completion = MonoProcessor.create(); return Mono.fromCallable( () -> { if (logger.isDebugEnabled()) { logger.debug("Connecting to " + url); } List<String> protocols = handler.getSubProtocols(); ConnectionBuilder builder = createConnectionBuilder(url); DefaultNegotiation negotiation = new DefaultNegotiation(protocols, headers, builder); builder.setClientNegotiation(negotiation); return builder.connect().addNotifier( new IoFuture.HandlingNotifier<WebSocketChannel, Object>() { @Override public void handleDone(WebSocketChannel channel, Object attachment) { handleChannel(url, handler, completion, negotiation, channel); } @Override public void handleFailed(IOException ex, Object attachment) { completion.onError(new IllegalStateException("Failed to connect to " + url, ex)); } }, null); }) .then(completion); }
@Deprecated public static IoFuture<WebSocketChannel> connect(XnioWorker worker, XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap optionMap, InetSocketAddress bindAddress, final URI uri, WebSocketVersion version, WebSocketClientNegotiation clientNegotiation, Set<ExtensionHandshake> clientExtensions) { return connectionBuilder(worker, bufferPool, uri) .setSsl(ssl) .setOptionMap(optionMap) .setBindAddress(bindAddress) .setVersion(version) .setClientNegotiation(clientNegotiation) .setClientExtensions(clientExtensions) .connect(); }
@Deprecated public static IoFuture<WebSocketChannel> connect(XnioWorker worker, XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap optionMap, InetSocketAddress bindAddress, final URI uri, WebSocketVersion version, WebSocketClientNegotiation clientNegotiation, Set<ExtensionHandshake> clientExtensions) { return connectionBuilder(worker, bufferPool, uri) .setSsl(ssl) .setOptionMap(optionMap) .setBindAddress(bindAddress) .setVersion(version) .setClientNegotiation(clientNegotiation) .setClientExtensions(clientExtensions) .connect(); }
protected ConnectionBuilder createConnectionBuilder(XnioWorker worker, DefaultByteBufferPool bufferPool, String url) { URI uri = createWebsocketUri(url); ConnectionBuilder connectionBuilder = WebSocketClient.connectionBuilder(worker, bufferPool, uri); addSslContext(connectionBuilder); connectionBuilder.setClientNegotiation(new WebSocketClientNegotiation(createSupportedSubProtocols(), createSupportedExtensions()) { @Override public void beforeRequest(final Map<String, List<String>> headers) { //========================================== // Add custom headers //========================================== addCustomHeaders(headers); //========================================== // Add cookies //========================================== addCustomCookies(headers); //========================================== // Add HTTP authenticatiin headers //========================================== addHttpAuthHeaders(headers); } }); return connectionBuilder; }
private Mono<Void> executeInternal(URI url, HttpHeaders headers, WebSocketHandler handler) { MonoProcessor<Void> completion = MonoProcessor.create(); return Mono.fromCallable( () -> { ConnectionBuilder builder = createConnectionBuilder(url); String[] protocols = beforeHandshake(url, headers, handler); DefaultNegotiation negotiation = new DefaultNegotiation(protocols, headers, builder); builder.setClientNegotiation(negotiation); return builder.connect().addNotifier( new IoFuture.HandlingNotifier<WebSocketChannel, Object>() { @Override public void handleDone(WebSocketChannel channel, Object attachment) { handleChannel(url, handler, completion, negotiation, channel); } @Override public void handleFailed(IOException ex, Object attachment) { completion.onError(new IllegalStateException("Failed to connect", ex)); } }, null); }) .then(completion); }
@Deprecated public static IoFuture<WebSocketChannel> connect(XnioWorker worker, XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap optionMap, InetSocketAddress bindAddress, final URI uri, WebSocketVersion version, WebSocketClientNegotiation clientNegotiation, Set<ExtensionHandshake> clientExtensions) { return connectionBuilder(worker, bufferPool, uri) .setSsl(ssl) .setOptionMap(optionMap) .setBindAddress(bindAddress) .setVersion(version) .setClientNegotiation(clientNegotiation) .setClientExtensions(clientExtensions) .connect(); }