@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(); }
IoFuture<WebSocketChannel> connectionFuture = new WebSocketClient.ConnectionBuilder( worker, new DefaultByteBufferPool(false, 2048), new URI(registryUrl)).connect();
@Override protected synchronized void tryConnect() throws Exception { if (webSocketChannel != null) { return; } shuttingDown = false; logger.info("Connecting to {}", url); webSocketChannel = new WebSocketClient.ConnectionBuilder( worker, new DefaultByteBufferPool(false, 2048), //TODO configurable ? URI.create(url)) .connect() .get(); ProxyClientEndpoint proxyClientEndpoint = new ProxyClientEndpoint(endpoint); webSocketChannel.getReceiveSetter().set(proxyClientEndpoint); webSocketChannel.getCloseSetter().set((ChannelListener<AbstractFramedChannel>) channel -> { if(!clientClose) { closeChannel(); proxyClientEndpoint.onCloseMessage(null, webSocketChannel); reconnect(); } }); proxyClientEndpoint.onConnect(webSocketChannel); webSocketChannel.resumeReceives(); monitor.add(uuid, this::closeChannel); logger.info("Connected to {}", url); clientClose = false; }
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); }
@Override public UndertowEndpoint connect(URI uri, XEndpointListener<? super UndertowEndpoint> listener) throws Exception { final int bufferSize = UndertowAtts.BUFFER_SIZE.get(config.attributes); final boolean directBuffers = UndertowAtts.DIRECT_BUFFERS.get(config.attributes); final ByteBufferPool pool = new DefaultByteBufferPool(directBuffers, bufferSize); final ConnectionBuilder builder = WebSocketClient.connectionBuilder(worker, pool, uri); if (uri.getScheme().equals("wss")) { final SSLContext sslContext = config.sslContextProvider.getSSLContext(); final ByteBufferPool sslBufferPool = new DefaultByteBufferPool(directBuffers, 17 * 1024); final XnioSsl ssl = new UndertowXnioSsl(worker.getXnio(), OptionMap.EMPTY, sslBufferPool, sslContext); builder.setSsl(ssl); } final WebSocketChannel channel = builder.connect().get(); return UndertowEndpoint.clientOf(scanner, channel, config, listener); }
public static WebSocketChannel connect(String url, ChannelListener<? super WebSocketChannel> clientEndpoint) { try { WebSocketChannel webSocketChannel = new WebSocketClient.ConnectionBuilder( ClientManager.getWorker(), new DefaultByteBufferPool(false, 2048), URI.create(ClientManager.lookup(url))) .connect().get(); webSocketChannel.getReceiveSetter().set(clientEndpoint); webSocketChannel.resumeReceives(); return webSocketChannel; } catch (Exception e) { throw new RuntimeException(e); } }
public IoFuture<WebSocketChannel> connect() { return connectImpl(uri, new FutureResult<WebSocketChannel>(), 0); } private IoFuture<WebSocketChannel> connectImpl(final URI uri, final FutureResult<WebSocketChannel> ioFuture, final int redirectCount) {
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }
public static WebSocketChannel connect(URI uri, ChannelListener<? super WebSocketChannel> clientEndpoint) throws IOException { WebSocketChannel webSocketChannel = new WebSocketClient.ConnectionBuilder( getWorker(), new DefaultByteBufferPool(false, 2048), uri) .connect().get(); webSocketChannel.getReceiveSetter().set(clientEndpoint); webSocketChannel.resumeReceives(); return webSocketChannel; }
public IoFuture<WebSocketChannel> connect() { return connectImpl(uri, new FutureResult<WebSocketChannel>(), 0); } private IoFuture<WebSocketChannel> connectImpl(final URI uri, final FutureResult<WebSocketChannel> ioFuture, final int redirectCount) {
protected WebSocketChannel createWebSocketChannel(XnioWorker worker, DefaultByteBufferPool bufferPool, String url, int redirectionNbr) { try { ConnectionBuilder connectionBuilder = createConnectionBuilder(worker, bufferPool, url); WebSocketChannel webSocketChannel = connectionBuilder.connect().get(); return webSocketChannel; } catch (Exception ex) { throw SpincastStatics.runtimize(ex); } }
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }
@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 void addSslContext(ConnectionBuilder connectionBuilder) { SSLContext sslContext = getSslContext(); XnioSsl xnioSsl = new JsseXnioSsl(getXnio(), OptionMap.create(Options.USE_DIRECT_BUFFERS, true), sslContext); connectionBuilder.setSsl(xnioSsl); }
@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(); }
public IoFuture<WebSocketChannel> connect() { return connectImpl(uri, new FutureResult<WebSocketChannel>(), 0); } private IoFuture<WebSocketChannel> connectImpl(final URI uri, final FutureResult<WebSocketChannel> ioFuture, final int redirectCount) {
/** * Creates a new connection builder that can be used to create a web socket connection. * @param worker The XnioWorker to use for the connection * @param bufferPool The buffer pool * @param uri The connection URI * @return The connection builder */ public static ConnectionBuilder connectionBuilder(XnioWorker worker, ByteBufferPool bufferPool, URI uri) { return new ConnectionBuilder(worker, bufferPool, uri); }
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); }