Java Code Examples for io.undertow.client.ClientConnection

The following examples show how to use io.undertow.client.ClientConnection. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: lams   Author: lamsfoundation   File: AjpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #2
Source Project: lams   Author: lamsfoundation   File: AjpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress,final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    ChannelListener<StreamConnection> openListener = new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, ssl, bufferPool, options);
        }
    };
    IoFuture.Notifier<StreamConnection, Object> notifier = new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
    if(bindAddress == null) {
        ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, options).addNotifier(notifier, null);
    } else {
        ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 8009 : uri.getPort()), openListener, null, options).addNotifier(notifier, null);
    }
}
 
Example #3
Source Project: lams   Author: lamsfoundation   File: HttpClientConnection.java    License: GNU General Public License v2.0 6 votes vote down vote up
protected void doHttp2Upgrade() {
    try {
        StreamConnection connectedStreamChannel = this.performUpgrade();
        Http2Channel http2Channel = new Http2Channel(connectedStreamChannel, null, bufferPool, null, true, true, options);
        Http2ClientConnection http2ClientConnection = new Http2ClientConnection(http2Channel, currentRequest.getResponseCallback(), currentRequest.getRequest(), currentRequest.getRequest().getRequestHeaders().getFirst(Headers.HOST), clientStatistics, false);
        http2ClientConnection.getCloseSetter().set(new ChannelListener<ClientConnection>() {
            @Override
            public void handleEvent(ClientConnection channel) {
                ChannelListeners.invokeChannelListener(HttpClientConnection.this, HttpClientConnection.this.closeSetter.get());
            }
        });
        http2Delegate = http2ClientConnection;
        connectedStreamChannel.getSourceChannel().wakeupReads(); //make sure the read listener is immediately invoked, as it may not happen if data is pushed back
        currentRequest = null;
        pendingResponse = null;
    } catch (IOException e) {
        UndertowLogger.REQUEST_IO_LOGGER.ioException(e);
        safeClose(this);
    }
}
 
Example #4
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals("https")) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #5
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals("https")) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #6
Source Project: lams   Author: lamsfoundation   File: ProxyHandler.java    License: GNU General Public License v2.0 6 votes vote down vote up
void cancel(final HttpServerExchange exchange) {
    final ProxyConnection connectionAttachment = exchange.getAttachment(CONNECTION);
    if (connectionAttachment != null) {
        ClientConnection clientConnection = connectionAttachment.getConnection();
        UndertowLogger.PROXY_REQUEST_LOGGER.timingOutRequest(clientConnection.getPeerAddress() + "" + exchange.getRequestURI());
        IoUtils.safeClose(clientConnection);
    } else {
        UndertowLogger.PROXY_REQUEST_LOGGER.timingOutRequest(exchange.getRequestURI());
    }
    if (exchange.isResponseStarted()) {
        IoUtils.safeClose(exchange.getConnection());
    } else {
        exchange.setStatusCode(StatusCodes.SERVICE_UNAVAILABLE);
        exchange.endExchange();
    }
}
 
Example #7
Source Project: bouncr   Author: kawasima   File: MultiAppProxyClient.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void completed(final ClientConnection connection) {
    final ServerConnection serverConnection = exchange.getConnection();
    //we attach to the connection so it can be re-used
    if (connectionCache) {
        serverConnection.putAttachment(clientAttachmentKey, connection);
    }
    serverConnection.addCloseListener(serverConnection1 -> IoUtils.safeClose(connection));
    connection.getCloseSetter().set((ChannelListener<Channel>) channel -> serverConnection.removeAttachment(clientAttachmentKey));

    exchange.setRelativePath("/");
    Realm realm = realmCache.matches(exchange.getRequestPath());
    Application application = realmCache.getApplication(realm);
    String path = exchange.getRequestURI();
    if (path.startsWith(application.getVirtualPath())) {
        String passTo = calculatePathTo(path, application);
        exchange.setRequestPath(passTo);
        exchange.setRequestURI(passTo);
    }
    callback.completed(exchange, new ProxyConnection(connection, "/"));
}
 
Example #8
Source Project: light-4j   Author: networknt   File: Http2ClientConnectionPool.java    License: Apache License 2.0 6 votes vote down vote up
public synchronized ClientConnection getConnection(URI uri) {
    if (uri == null) {
        return null;
    }
    String uriString = uri.toString();
    List<CachedConnection> result = connectionPool.get(uriString);
    if (result == null) {
        synchronized (Http2ClientConnectionPool.class) {
            result = connectionPool.get(uriString);
        }
    }
    CachedConnection cachedConnection = selectConnection(uri, result, false);
    if (cachedConnection != null) {
        hangConnection(uri, cachedConnection);
        return cachedConnection.get();
    }
    return null;
}
 
Example #9
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioWorker worker, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals(HTTPS)) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #10
Source Project: light-4j   Author: networknt   File: Light4jHttpClientProvider.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void connect(ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, URI uri, XnioIoThread ioThread, XnioSsl ssl, ByteBufferPool bufferPool, OptionMap options) {
    if (uri.getScheme().equals(HTTPS)) {
        if (ssl == null) {
            listener.failed(UndertowMessages.MESSAGES.sslWasNull());
            return;
        }
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        if (bindAddress == null) {
            ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        } else {
            ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, bufferPool, tlsOptions, uri), tlsOptions).addNotifier(createNotifier(listener), null);
        }
    } else {
        if (bindAddress == null) {
            ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), options).addNotifier(createNotifier(listener), null);
        } else {
            ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri), null, options).addNotifier(createNotifier(listener), null);
        }
    }
}
 
Example #11
Source Project: spring-analysis-note   Author: Vip-Augus   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example #12
Source Project: spring-analysis-note   Author: Vip-Augus   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
public SockJsResponseListener(TransportRequest request, ClientConnection connection, URI url,
		HttpHeaders headers, XhrClientSockJsSession sockJsSession,
		SettableListenableFuture<WebSocketSession> connectFuture) {

	this.request = request;
	this.connection = connection;
	this.url = url;
	this.headers = headers;
	this.session = sockJsSession;
	this.connectFuture = connectFuture;
}
 
Example #13
Source Project: java-technology-stack   Author: codeEngraver   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
private void executeReceiveRequest(final TransportRequest transportRequest,
		final URI url, final HttpHeaders headers, final XhrClientSockJsSession session,
		final SettableListenableFuture<WebSocketSession> connectFuture) {

	if (logger.isTraceEnabled()) {
		logger.trace("Starting XHR receive request for " + url);
	}

	ClientCallback<ClientConnection> clientCallback = new ClientCallback<ClientConnection>() {
		@Override
		public void completed(ClientConnection connection) {
			ClientRequest request = new ClientRequest().setMethod(Methods.POST).setPath(url.getPath());
			HttpString headerName = HttpString.tryFromString(HttpHeaders.HOST);
			request.getRequestHeaders().add(headerName, url.getHost());
			addHttpHeaders(request, headers);
			HttpHeaders httpHeaders = transportRequest.getHttpRequestHeaders();
			connection.sendRequest(request, createReceiveCallback(transportRequest,
					url, httpHeaders, session, connectFuture));
		}

		@Override
		public void failed(IOException ex) {
			throw new SockJsTransportFailureException("Failed to execute request to " + url, ex);
		}
	};

	this.httpClient.connect(clientCallback, url, this.worker, this.bufferPool, this.optionMap);
}
 
Example #14
Source Project: java-technology-stack   Author: codeEngraver   File: UndertowXhrTransport.java    License: MIT License 5 votes vote down vote up
public SockJsResponseListener(TransportRequest request, ClientConnection connection, URI url,
		HttpHeaders headers, XhrClientSockJsSession sockJsSession,
		SettableListenableFuture<WebSocketSession> connectFuture) {

	this.request = request;
	this.connection = connection;
	this.url = url;
	this.headers = headers;
	this.session = sockJsSession;
	this.connectFuture = connectFuture;
}
 
Example #15
Source Project: lams   Author: lamsfoundation   File: AjpClientChannel.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
protected AbstractAjpClientStreamSourceChannel createChannel(FrameHeaderData frameHeaderData, PooledByteBuffer frameData) throws IOException {
    if (frameHeaderData instanceof SendHeadersResponse) {
        SendHeadersResponse h = (SendHeadersResponse) frameHeaderData;
        AjpClientResponseStreamSourceChannel sourceChannel = new AjpClientResponseStreamSourceChannel(this, h.headers, h.statusCode, h.reasonPhrase, frameData, (int) frameHeaderData.getFrameLength());
        this.source = sourceChannel;
        return sourceChannel;
    } else if (frameHeaderData instanceof RequestBodyChunk) {
        RequestBodyChunk r = (RequestBodyChunk) frameHeaderData;
        this.sink.chunkRequested(r.getLength());
        frameData.close();
        return null;
    } else if (frameHeaderData instanceof CpongResponse) {
        synchronized (pingListeners) {
            for(ClientConnection.PingListener i : pingListeners) {
                try {
                    i.acknowledged();
                } catch (Throwable t) {
                    UndertowLogger.ROOT_LOGGER.debugf("Exception notifying ping listener", t);
                }
            }
            pingListeners.clear();
        }
        return null;
    } else {
        frameData.close();
        throw new RuntimeException("TODO: unknown frame");
    }

}
 
Example #16
Source Project: lams   Author: lamsfoundation   File: AjpClientChannel.java    License: GNU General Public License v2.0 5 votes vote down vote up
public void sendPing(ClientConnection.PingListener pingListener, long timeout, TimeUnit timeUnit) {
    AjpClientCPingStreamSinkChannel pingChannel = new AjpClientCPingStreamSinkChannel(this);
    try {
        pingChannel.shutdownWrites();
        if (!pingChannel.flush()) {
            pingChannel.getWriteSetter().set(ChannelListeners.flushingChannelListener(null, new ChannelExceptionHandler<AbstractAjpClientStreamSinkChannel>() {
                @Override
                public void handleException(AbstractAjpClientStreamSinkChannel channel, IOException exception) {
                    pingListener.failed(exception);
                    synchronized (pingListeners) {
                        pingListeners.remove(pingListener);
                    }
                }
            }));
            pingChannel.resumeWrites();
        }
    } catch (IOException e) {
        pingListener.failed(e);
        return;
    }

    synchronized (pingListeners) {
        pingListeners.add(pingListener);
    }
    getIoThread().executeAfter(() -> {
        synchronized (pingListeners) {
            if(pingListeners.contains(pingListener)) {
                pingListeners.remove(pingListener);
                pingListener.failed(UndertowMessages.MESSAGES.pingTimeout());
            }
        }
    }, timeout, timeUnit);
}
 
Example #17
Source Project: lams   Author: lamsfoundation   File: AjpClientConnection.java    License: GNU General Public License v2.0 5 votes vote down vote up
AjpClientConnection(final AjpClientChannel connection, final OptionMap options, final ByteBufferPool bufferPool, ClientStatistics clientStatistics) {
    this.clientStatistics = clientStatistics;
    this.options = options;
    this.connection = connection;
    this.bufferPool = bufferPool;

    connection.addCloseTask(new ChannelListener<AjpClientChannel>() {
        @Override
        public void handleEvent(AjpClientChannel channel) {
            log.debugf("connection to %s closed", getPeerAddress());
            AjpClientConnection.this.state |= CLOSED;
            ChannelListeners.invokeChannelListener(AjpClientConnection.this, closeSetter.get());
            for(ChannelListener<ClientConnection> listener : closeListeners) {
                listener.handleEvent(AjpClientConnection.this);
            }
            AjpClientExchange pending = pendingQueue.poll();
            while (pending != null) {
                pending.setFailed(new ClosedChannelException());
                pending = pendingQueue.poll();
            }
            if(currentRequest != null) {
                currentRequest.setFailed(new ClosedChannelException());
                currentRequest = null;
            }
        }
    });
    connection.getReceiveSetter().set(new ClientReceiveListener());
    connection.resumeReceives();
}
 
Example #18
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {

    if (bindAddress == null) {
        worker.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null);
    } else {
        worker.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null);
    }}
 
Example #19
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, final InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {

    if (bindAddress == null) {
        ioThread.openStreamConnection(new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), options).addNotifier(createNotifier(listener), null);
    } else {
        ioThread.openStreamConnection(bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 80 : uri.getPort()), createOpenListener(listener, bufferPool, options, uri.getHost()), null, options).addNotifier(createNotifier(listener), null);
    }
}
 
Example #20
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #21
Source Project: lams   Author: lamsfoundation   File: Http2PriorKnowledgeClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final String defaultHost) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, defaultHost);
        }
    };
}
 
Example #22
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioWorker worker, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    if (ssl == null) {
        listener.failed(UndertowMessages.MESSAGES.sslWasNull());
        return;
    }
    OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
    if(bindAddress == null) {
        ssl.openSslConnection(worker, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null);
    } else {
        ssl.openSslConnection(worker, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), tlsOptions).addNotifier(createNotifier(listener), null);
    }

}
 
Example #23
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void connect(final ClientCallback<ClientConnection> listener, InetSocketAddress bindAddress, final URI uri, final XnioIoThread ioThread, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    if (ssl == null) {
        listener.failed(UndertowMessages.MESSAGES.sslWasNull());
        return;
    }
    if(bindAddress == null) {
        OptionMap tlsOptions = OptionMap.builder().addAll(options).set(Options.SSL_STARTTLS, true).getMap();
        ssl.openSslConnection(ioThread, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, tlsOptions), options).addNotifier(createNotifier(listener), null);
    } else {
        ssl.openSslConnection(ioThread, bindAddress, new InetSocketAddress(uri.getHost(), uri.getPort() == -1 ? 443 : uri.getPort()), createOpenListener(listener, uri, ssl, bufferPool, options), options).addNotifier(createNotifier(listener), null);
    }

}
 
Example #24
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #25
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final URI uri, final XnioSsl ssl, final ByteBufferPool bufferPool, final OptionMap options) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, uri, bufferPool, options);
        }
    };
}
 
Example #26
Source Project: lams   Author: lamsfoundation   File: Http2ClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
public static ALPNClientSelector.ALPNProtocol alpnProtocol(final ClientCallback<ClientConnection> listener, URI uri, ByteBufferPool bufferPool, OptionMap options) {
    return new ALPNClientSelector.ALPNProtocol(new ChannelListener<SslConnection>() {
        @Override
        public void handleEvent(SslConnection connection) {
            listener.completed(createHttp2Channel(connection, bufferPool, options, uri.getHost()));
        }
    }, HTTP2);
}
 
Example #27
Source Project: wildfly-core   Author: wildfly   File: SNICombinedWithALPNTestCase.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
@Test
public void testHttpsViaIp() throws Exception {
    Assume.assumeFalse("There is no ALPN implementation in IBM JDK 8 and less; also ALPN-hack that serves" +
            " as a workaround for other JDKs does not work with IBM JDK.", isIbmJdk() && jdkLessThan9());

    XnioSsl ssl = createClientSSL(ipKeystore);
    UndertowClient client = UndertowClient.getInstance();
    DefaultByteBufferPool pool = new DefaultByteBufferPool(false, 1024);
    ClientConnection connection = client.connect(new URI("https", null, "127.0.0.1", TestSuiteEnvironment.getHttpPort(), "", null, null), XnioWorker.getContextManager().get(), ssl, pool, OptionMap.create(UndertowOptions.ENABLE_HTTP2, true)).get();
    performSimpleTest(pool, connection);
}
 
Example #28
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private IoFuture.Notifier<StreamConnection, Object> createNotifier(final ClientCallback<ClientConnection> listener) {
    return new IoFuture.Notifier<StreamConnection, Object>() {
        @Override
        public void notify(IoFuture<? extends StreamConnection> ioFuture, Object o) {
            if (ioFuture.getStatus() == IoFuture.Status.FAILED) {
                listener.failed(ioFuture.getException());
            }
        }
    };
}
 
Example #29
Source Project: lams   Author: lamsfoundation   File: HttpClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
private ChannelListener<StreamConnection> createOpenListener(final ClientCallback<ClientConnection> listener, final ByteBufferPool bufferPool, final OptionMap options, final URI uri) {
    return new ChannelListener<StreamConnection>() {
        @Override
        public void handleEvent(StreamConnection connection) {
            handleConnected(connection, listener, bufferPool, options, uri);
        }
    };
}
 
Example #30
Source Project: lams   Author: lamsfoundation   File: SimpleProxyClientProvider.java    License: GNU General Public License v2.0 5 votes vote down vote up
@Override
public void getConnection(ProxyTarget target, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit) {
    ClientConnection existing = exchange.getConnection().getAttachment(clientAttachmentKey);
    if (existing != null) {
        if (existing.isOpen()) {
            //this connection already has a client, re-use it
            callback.completed(exchange, new ProxyConnection(existing, uri.getPath() == null ? "/" : uri.getPath()));
            return;
        } else {
            exchange.getConnection().removeAttachment(clientAttachmentKey);
        }
    }
    client.connect(new ConnectNotifier(callback, exchange), uri, exchange.getIoThread(), exchange.getConnection().getByteBufferPool(), OptionMap.EMPTY);
}