@Override public Channel channel() { return delegate.channel(); }
private synchronized void initSSL(ChannelPipeline pipeline) throws SSLContextException { if (sslContext == null || sslEngine == null) { try (X509Util x509Util = new ClientX509Util()) { sslContext = x509Util.createSSLContext(clientConfig); sslEngine = sslContext.createSSLEngine(host, port); sslEngine.setUseClientMode(true); } } pipeline.addLast("ssl", new SslHandler(sslEngine)); LOG.info("SSL handler added for channel: {}", pipeline.channel()); } }
void finishWithNegotiationFailure( ChannelHandlerContext ctx, SessionProtocol expected, SessionProtocol actual, String reason) { final ChannelPipeline pipeline = ctx.pipeline(); pipeline.channel().eventLoop().execute( () -> pipeline.fireUserEventTriggered( new SessionProtocolNegotiationException(expected, actual, reason))); ctx.close(); }
private void configureHttp(ChannelPipeline p, @Nullable ProxiedAddresses proxiedAddresses) { final Http1ObjectEncoder responseEncoder = new Http1ObjectEncoder(p.channel(), true, false); p.addLast(TrafficLoggingHandler.SERVER); p.addLast(new Http2PrefaceOrHttpHandler(responseEncoder)); configureIdleTimeoutHandler(p); p.addLast(new HttpServerHandler(config, gracefulShutdownSupport, responseEncoder, SessionProtocol.H1C, proxiedAddresses)); }
private synchronized void initSSL(ChannelPipeline p) throws X509Exception, KeyManagementException, NoSuchAlgorithmException { String authProviderProp = System.getProperty(x509Util.getSslAuthProviderProperty()); SSLContext sslContext; if (authProviderProp == null) { sslContext = x509Util.getDefaultSSLContext(); } else { sslContext = SSLContext.getInstance("TLSv1"); X509AuthenticationProvider authProvider = (X509AuthenticationProvider)ProviderRegistry.getProvider( System.getProperty(x509Util.getSslAuthProviderProperty(), "x509")); if (authProvider == null) { LOG.error("Auth provider not found: {}", authProviderProp); throw new SSLContextException( "Could not create SSLContext with specified auth provider: " + authProviderProp); } sslContext.init(new X509KeyManager[] { authProvider.getKeyManager() }, new X509TrustManager[] { authProvider.getTrustManager() }, null); } SSLEngine sslEngine = sslContext.createSSLEngine(); sslEngine.setUseClientMode(false); sslEngine.setNeedClientAuth(true); p.addLast("ssl", new SslHandler(sslEngine)); LOG.info("SSL handler added for channel: {}", p.channel()); }
@Override protected SslHandler newSslHandler(ChannelPipeline pipeline) { SslHandler toReturn = new SslHandler(engineFactory.call(pipeline.channel().alloc())); configureHandler(toReturn); return toReturn; }
void finishSuccessfully(ChannelPipeline pipeline, SessionProtocol protocol) { if (protocol == H1 || protocol == H1C) { addBeforeSessionHandler(pipeline, new Http1ResponseDecoder(pipeline.channel())); } else if (protocol == H2 || protocol == H2C) { final int initialWindow = clientFactory.http2InitialConnectionWindowSize(); if (initialWindow > DEFAULT_WINDOW_SIZE) { incrementLocalWindowSize(pipeline, initialWindow - DEFAULT_WINDOW_SIZE); } } final long idleTimeoutMillis = clientFactory.idleTimeoutMillis(); if (idleTimeoutMillis > 0) { pipeline.addFirst(new HttpClientIdleTimeoutHandler(idleTimeoutMillis)); } pipeline.channel().eventLoop().execute(() -> pipeline.fireUserEventTriggered(protocol)); }
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2MultiplexCodec multiplexCodec = Http2MultiplexCodecBuilder .forServer(http2StreamHandler) .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexCodec); // Need to pass the connection to our handler later, so store it on channel now. Http2Connection connection = multiplexCodec.connection(); pipeline.channel().attr(H2_CONN_KEY).set(connection); }
private Http2ConnectionHandler newHttp2ConnectionHandler(ChannelPipeline pipeline) { final Http2Connection conn = new DefaultHttp2Connection(true); final Http2FrameReader reader = new DefaultHttp2FrameReader(true); final Http2FrameWriter writer = new DefaultHttp2FrameWriter(); final Http2ConnectionEncoder encoder = new DefaultHttp2ConnectionEncoder(conn, writer); final Http2ConnectionDecoder decoder = new DefaultHttp2ConnectionDecoder(conn, encoder, reader); return new Http2ServerConnectionHandler( decoder, encoder, http2Settings(), pipeline.channel(), config, gracefulShutdownSupport); }
private void configureHttp2(ChannelPipeline pipeline) { // setup the initial stream settings for the server to use. Http2Settings settings = new Http2Settings() .maxConcurrentStreams(maxConcurrentStreams) .initialWindowSize(initialWindowSize) .headerTableSize(maxHeaderTableSize) .maxHeaderListSize(maxHeaderListSize); Http2MultiplexCodec multiplexCodec = Http2MultiplexCodecBuilder .forServer(http2StreamHandler) .frameLogger(FRAME_LOGGER) .initialSettings(settings) .validateHeaders(true) .build(); pipeline.replace("codec_placeholder", HTTP_CODEC_HANDLER_NAME, multiplexCodec); // Need to pass the connection to our handler later, so store it on channel now. Http2Connection connection = multiplexCodec.connection(); pipeline.channel().attr(H2_CONN_KEY).set(connection); }
@Override public void initChannel(SocketChannel ch) throws Exception { final ChannelPipeline p = ch.pipeline(); final Http2Connection conn = new DefaultHttp2Connection(false); final HttpToHttp2ConnectionHandler connHandler = new HttpToHttp2ConnectionHandlerBuilder() .connection(conn) .frameListener(new DelegatingDecompressorFrameListener( conn, new InboundHttp2ToHttpAdapterBuilder(conn) .maxContentLength(Integer.MAX_VALUE) .propagateSettings(true).build())) .build(); clientHandler = new THttp2ClientHandler(ch.eventLoop()); if (sslCtx != null) { p.addLast(sslCtx.newHandler(p.channel().alloc())); p.addLast(connHandler); configureEndOfPipeline(p); } else { final Http1ClientCodec sourceCodec = new Http1ClientCodec(); final HttpClientUpgradeHandler upgradeHandler = new HttpClientUpgradeHandler( sourceCodec, new Http2ClientUpgradeCodec(connHandler), 65536); p.addLast(sourceCodec, upgradeHandler, new UpgradeRequestHandler()); } }
protected void doDispose(ChannelPipeline channelPipeline, boolean forceClose) { channelPipeline.remove(CLIENT_CODEC_HANDLER_NAME); channelPipeline.remove(READ_TIMEOUT_HANDLER_NAME); channelPipeline.remove(REDIRECT_HANDLER_NAME); if (channelPipeline.get(DECOMPRESS_HANDLER_NAME) != null) { channelPipeline.remove(DECOMPRESS_HANDLER_NAME); } Channel channel = channelPipeline.channel(); if (forceClose && channel.isOpen()) { channel.close(); } channelPool.release(channel); }
public ConnectionIdleTimeout(ChannelPipeline channelPipeline, Duration timeout) { this.channelPipeline = channelPipeline; this.timeout = timeout; channelPipeline.channel().attr(ATTRIBUTE_KEY).set(this); if (!timeout.isZero()) { init(timeout); } }
@Override public void channelActive(ChannelHandlerContext ctx) throws Exception { final Channel channel = ctx.pipeline().channel(); this.connection = homekitClientConnectionFactory.createConnection(response -> { if (!channel.isActive()) { return; } channel.writeAndFlush(NettyResponseUtil.createResponse(response)); }); LOGGER.info("New homekit connection from "+ctx.channel().remoteAddress().toString()); super.channelActive(ctx); }
@Override public boolean isAvailable() { try { DefaultHttpRequest get = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, path); HttpResponseHandler handler = new HttpResponseHandler(true); Channel ch = bootstrap.connect(configuration.host(), configuration.port()).awaitUninterruptibly().channel().pipeline().addLast( new HttpObjectAggregator(maxContentLength), handler).channel(); ch.writeAndFlush(get).sync().channel().closeFuture().sync(); return handler.getResponse().status().code() == 200; } catch (Exception e) { return false; } }
@Override public void clear() { DefaultHttpRequest delete = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.DELETE, path); try { Channel ch = bootstrap.connect(configuration.host(), configuration.port()).awaitUninterruptibly().channel().pipeline().addLast(new HttpResponseHandler()).channel(); ch.writeAndFlush(delete).sync().channel().closeFuture().sync(); } catch (Exception e) { throw new PersistenceException(e); } }
@Override public void configureNewPipeline(ChannelPipeline pipeline) { final SslHandler sslHandler = new SslHandler(sslEngineFactory.createSSLEngine(pipeline.channel().alloc())); pipeline.addFirst(SSL_HANDLER_NAME, sslHandler); pipeline.addAfter(SSL_HANDLER_NAME, SSL_COMPLETION_HANDLER_NAME, new SslCompletionHandler(sslHandler.handshakeFuture())); } }
@Override public void configureNewPipeline(ChannelPipeline pipeline) { final SslHandler sslHandler = new SslHandler(sslEngineFactory.createSSLEngine(pipeline.channel().alloc())); if(proxy != null) { pipeline.addAfter(Constants.Properties.HTTP_PROXY_HANDLER_NAME,Constants.Properties.SSL_HANDLER_NAME, sslHandler); } else { pipeline.addFirst(Constants.Properties.SSL_HANDLER_NAME, sslHandler); } pipeline.addAfter(Constants.Properties.SSL_HANDLER_NAME, Constants.Properties.SSL_COMPLETION_HANDLER_NAME, new SslCompletionHandler(sslHandler.handshakeFuture())); } }