@Override protected void initChannel(SocketChannel channel) throws Exception { configureChannel(channel.config()); ChannelPipeline pipeline = channel.pipeline(); if (isSecure) { Assert.notNull(sslContext, "sslContext should not be null"); pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort())); } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); if (readTimeout > 0) { pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS)); } } });
@Override protected void initChannel(SocketChannel ch) throws Exception { ChannelPipeline p = ch.pipeline(); // Enable HTTPS if necessary. if ("https".equals(requestUri.getScheme())) { // making client authentication optional for now; it could be extracted to configurable property JdkSslContext jdkSslContext = new JdkSslContext(client.getSslContext(), true, ClientAuth.NONE); p.addLast(jdkSslContext.newHandler(ch.alloc())); } // http proxy Configuration config = jerseyRequest.getConfiguration(); final Object proxyUri = config.getProperties().get(ClientProperties.PROXY_URI); if (proxyUri != null) { final URI u = getProxyUri(proxyUri); final String userName = ClientProperties.getValue( config.getProperties(), ClientProperties.PROXY_USERNAME, String.class); final String password = ClientProperties.getValue( config.getProperties(), ClientProperties.PROXY_PASSWORD, String.class); p.addLast(new HttpProxyHandler(new InetSocketAddress(u.getHost(), u.getPort() == -1 ? 8080 : u.getPort()), userName, password)); } p.addLast(new HttpClientCodec()); p.addLast(new ChunkedWriteHandler()); p.addLast(new HttpContentDecompressor()); p.addLast(new JerseyClientHandler(NettyConnector.this, jerseyRequest, jerseyCallback, settableFuture)); } });
@Override public SslHandler newSSLHandler(SocketChannel channel) { return context.newHandler(channel.alloc()); } }
@Before public void beforeMethod() { socketChannelMock = mock(SocketChannel.class); channelPipelineMock = mock(ChannelPipeline.class); ByteBufAllocator byteBufAllocatorMock = mock(ByteBufAllocator.class); doReturn(channelPipelineMock).when(socketChannelMock).pipeline(); doReturn(byteBufAllocatorMock).when(socketChannelMock).alloc(); }
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()), new HttpVersionChooser(baseUri, container)); }
@Override protected void initChannel(SocketChannel sch) throws Exception { InetSocketAddress serverAddr = (InetSocketAddress) sc.localAddress(); SSLEngine engine = clientCtx.newEngine(sch.alloc(), serverAddr.getHostString(), serverAddr.getPort()); engine.setUseClientMode(true); engine.setEnabledProtocols(protocols); sch.pipeline().addLast(new SslHandler(engine)); sch.pipeline().addLast(ch); } });
@Override public SslHandler newSSLHandler(SocketChannel channel, InetSocketAddress remoteEndpoint) { return context.newHandler( channel.alloc(), remoteEndpoint.getHostName(), remoteEndpoint.getPort()); } }
@Override protected void initChannel(SocketChannel channel) throws Exception { channel.pipeline().addLast("ssl", sslContext.newHandler(channel.alloc())) .addLast("handshake", new ServerHandshakeHandlerAdapter()); } }
@Override public SslHandler newSSLHandler(SocketChannel channel) { return context.newHandler(channel.alloc()); } }
@Override protected void initChannel(SocketChannel ch) { ChannelPipeline p = ch.pipeline(); if (sslCtx != null) { p.addLast(sslCtx.newHandler(ch.alloc(), host, port)); } p.addLast( new HttpClientCodec(), new HttpObjectAggregator(8192), WebSocketClientCompressionHandler.INSTANCE, handler ); } });
public void initChannel(SocketChannel socket) throws IOException, NoSuchAlgorithmException, CertificateException { ChannelPipeline pipeline = socket.pipeline(); if (localEnableSSL) { SslHandler sslHandler = sslBuilder.build(socket.alloc()); pipeline.addLast(SSL_HANDLER, sslHandler); } pipeline.addLast(idleExecutorGroup, IDLESTATE_HANDLER, new IdleStateHandler(localClientInactivityTimeoutSeconds, IDLESTATE_WRITER_IDLE_TIME_SECONDS, localClientInactivityTimeoutSeconds)); pipeline.addLast(BEATS_ACKER, new AckEncoder()); pipeline.addLast(CONNECTION_HANDLER, new ConnectionHandler()); pipeline.addLast(beatsHandlerExecutorGroup, new BeatsParser(), new BeatsHandler(localMessageListener)); }
@Override public SslHandler newSSLHandler(SocketChannel channel) { return context.newHandler(channel.alloc()); } }
@Override protected void initChannel(SocketChannel channel) throws Exception { configureChannel(channel.config()); ChannelPipeline pipeline = channel.pipeline(); if (isSecure) { Assert.notNull(sslContext, "sslContext should not be null"); pipeline.addLast(sslContext.newHandler(channel.alloc(), uri.getHost(), uri.getPort())); } pipeline.addLast(new HttpClientCodec()); pipeline.addLast(new HttpObjectAggregator(maxResponseSize)); if (readTimeout > 0) { pipeline.addLast(new ReadTimeoutHandler(readTimeout, TimeUnit.MILLISECONDS)); } } });
@Override public SslHandler newSSLHandler(SocketChannel channel, InetSocketAddress remoteEndpoint) { return context.newHandler(channel.alloc(), remoteEndpoint.getHostName(), remoteEndpoint.getPort()); } }
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { SslContext sslCtx = SslContextBuilder.build(); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(sslCtx.newHandler(ch.alloc())); // We must wait for the handshake to finish and the protocol to be negotiated before configuring // the HTTP/2 components of the pipeline. pipeline.addLast(new ApplicationProtocolNegotiationHandler("") { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ChannelPipeline p = ctx.pipeline(); p.addLast(connectionHandler); configureEndOfPipeline(p); return; } ctx.close(); throw new IllegalStateException("unknown protocol: " + protocol); } }); }
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { SslContext sslCtx = SslContextBuilder.build(); ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast(sslCtx.newHandler(ch.alloc())); // We must wait for the handshake to finish and the protocol to be negotiated before configuring // the HTTP/2 components of the pipeline. pipeline.addLast(new ApplicationProtocolNegotiationHandler("") { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ChannelPipeline p = ctx.pipeline(); p.addLast(connectionHandler); configureEndOfPipeline(p); return; } ctx.close(); throw new IllegalStateException("unknown protocol: " + protocol); } }); }
@Override protected void initChannel(SocketChannel channel) throws Exception { channel.pipeline().addLast("ssl", sslContext.newHandler(channel.alloc(), address.host(), address.port())) .addLast("handshake", new ClientHandshakeHandlerAdapter(future)); } }
@Override protected void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); try { if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpServerExpectContinueHandler()); if (useGZIP) { pipeline.addLast(new HttpContentCompressor()); } if (isWebSocket) { pipeline.addLast(new WebSocketHandler(blade)); } pipeline.addLast(new MergeRequestHandler()); pipeline.addLast(httpServerHandler); } catch (Exception e) { log.error("Add channel pipeline error", e); } }
@Override protected void initChannel(SocketChannel ch) { ChannelPipeline pipeline = ch.pipeline(); try { if (sslCtx != null) { pipeline.addLast(sslCtx.newHandler(ch.alloc())); } pipeline.addLast(new HttpServerCodec()); pipeline.addLast(new HttpServerExpectContinueHandler()); if (useGZIP) { pipeline.addLast(new HttpContentCompressor()); } if (isWebSocket) { pipeline.addLast(new WebSocketHandler(blade)); } pipeline.addLast(new MergeRequestHandler()); pipeline.addLast(httpServerHandler); } catch (Exception e) { log.error("Add channel pipeline error", e); } }