protected ClientConnectionFactory newSslClientConnectionFactory( ClientConnectionFactory connectionFactory) { return new SslClientConnectionFactory( client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory); }
/** * Processes a new connection making it idle or active depending on whether requests are waiting * to be sent. * * <p>A new connection is created when a request needs to be executed; it is possible that the * request that triggered the request creation is executed by another connection that was just * released, so the new connection may become idle. * * <p>If a request is waiting to be executed, it will be dequeued and executed by the new * connection. * * @param connection the new connection * @param dispatch whether to dispatch the processing to another thread */ protected void process(Connection connection, boolean dispatch) { // Ugly cast, but lack of generic reification forces it final HttpConnection httpConnection = (HttpConnection) connection; final HttpExchange exchange = exchanges.poll(); if (exchange == null) { LOG.debug("{} idle", httpConnection); if (!idleConnections.offer(httpConnection)) { LOG.debug("{} idle overflow"); httpConnection.close(); } if (!client.isRunning()) { LOG.debug("{} is stopping", client); remove(httpConnection); httpConnection.close(); } } else { final Request request = exchange.getRequest(); Throwable cause = request.getAbortCause(); if (cause != null) { abort(exchange, cause); LOG.debug("Aborted before processing {}: {}", exchange, cause); } else { LOG.debug("{} active", httpConnection); if (!activeConnections.offer(httpConnection)) { LOG.warn("{} active overflow"); } if (dispatch) { client .getExecutor() .execute( new Runnable() { @Override public void run() { httpConnection.send(exchange); } }); } else { httpConnection.send(exchange); } } } }
private void tunnelSucceeded() { try { // Replace the promise back with the original context.put(HttpClientTransport.HTTP_CONNECTION_PROMISE_CONTEXT_KEY, promise); HttpDestination destination = (HttpDestination) context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY); HttpClient client = destination.getHttpClient(); ClientConnectionFactory sslConnectionFactory = new SslClientConnectionFactory( client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory); org.eclipse.jetty.io.Connection oldConnection = endPoint.getConnection(); org.eclipse.jetty.io.Connection newConnection = sslConnectionFactory.newConnection(endPoint, context); Helper.replaceConnection(oldConnection, newConnection); LOG.debug("HTTP tunnel established: {} over {}", oldConnection, newConnection); } catch (Throwable x) { tunnelFailed(x); } }
private void tunnel() { try { HttpDestination destination = (HttpDestination) context.get(HttpClientTransport.HTTP_DESTINATION_CONTEXT_KEY); HttpClient client = destination.getHttpClient(); ClientConnectionFactory connectionFactory = this.connectionFactory; if (destination.isSecure()) connectionFactory = new SslClientConnectionFactory( client.getSslContextFactory(), client.getByteBufferPool(), client.getExecutor(), connectionFactory); org.eclipse.jetty.io.Connection newConnection = connectionFactory.newConnection(getEndPoint(), context); getEndPoint().upgrade(newConnection); if (LOG.isDebugEnabled()) LOG.debug("SOCKS4 tunnel established: {} over {}", this, newConnection); } catch (Throwable x) { failed(x); } }