io.netty.handler.ssl.ApplicationProtocolNegotiationHandler Java Examples
The following examples show how to use
io.netty.handler.ssl.ApplicationProtocolNegotiationHandler.
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 File: Http2ClientInitializer.java From netty-4.1.22 with Apache License 2.0 | 6 votes |
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { 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); } }); }
Example #2
Source File: Http2ClientInitializer.java From product-microgateway with Apache License 2.0 | 6 votes |
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { 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); } }); }
Example #3
Source File: Http2ClientInitializer.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSsl(SocketChannel ch) { SslContext sslCtx = SslContextBuilder.buildForClient(); 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); } }); }
Example #4
Source File: Http2ServerChannelInitializer.java From sofa-rpc with Apache License 2.0 | 6 votes |
/** * Configure the pipeline for TLS NPN negotiation to HTTP/2. */ private void configureSSL(SocketChannel ch) { final ChannelPipeline p = ch.pipeline(); // 先通过 SSL/TLS 协商版本 p.addLast(sslCtx.newHandler(ch.alloc())); // 根据版本加载不同的 ChannelHandler p.addLast(new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_1_1) { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ctx.pipeline().addLast(bizGroup, "Http2ChannelHandler", new Http2ChannelHandlerBuilder(serverHandler).build()); return; } if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) { ctx.pipeline().addLast("HttpServerCodec", new HttpServerCodec()); ctx.pipeline().addLast("HttpObjectAggregator", new HttpObjectAggregator(maxHttpContentLength)); ctx.pipeline().addLast(bizGroup, "Http1ChannelHandler", new Http1ServerChannelHandler(serverHandler)); return; } throw new IllegalStateException("unknown protocol: " + protocol); } }); }
Example #5
Source File: Http2Util.java From tutorials with MIT License | 6 votes |
public static ApplicationProtocolNegotiationHandler getServerAPNHandler() { ApplicationProtocolNegotiationHandler serverAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ctx.pipeline() .addLast(Http2FrameCodecBuilder.forServer() .build(), new Http2ServerResponseHandler()); return; } throw new IllegalStateException("Protocol: " + protocol + " not supported"); } }; return serverAPNHandler; }
Example #6
Source File: Http2Util.java From tutorials with MIT License | 5 votes |
public static ApplicationProtocolNegotiationHandler getClientAPNHandler(int maxContentLength, Http2SettingsHandler settingsHandler, Http2ClientResponseHandler responseHandler) { final Http2FrameLogger logger = new Http2FrameLogger(INFO, Http2Util.class); final Http2Connection connection = new DefaultHttp2Connection(false); HttpToHttp2ConnectionHandler connectionHandler = new HttpToHttp2ConnectionHandlerBuilder() .frameListener(new DelegatingDecompressorFrameListener(connection, new InboundHttp2ToHttpAdapterBuilder(connection).maxContentLength(maxContentLength) .propagateSettings(true) .build())) .frameLogger(logger) .connection(connection) .build(); ApplicationProtocolNegotiationHandler clientAPNHandler = new ApplicationProtocolNegotiationHandler(ApplicationProtocolNames.HTTP_2) { @Override protected void configurePipeline(ChannelHandlerContext ctx, String protocol) { if (ApplicationProtocolNames.HTTP_2.equals(protocol)) { ChannelPipeline p = ctx.pipeline(); p.addLast(connectionHandler); p.addLast(settingsHandler, responseHandler); return; } ctx.close(); throw new IllegalStateException("Protocol: " + protocol + " not supported"); } }; return clientAPNHandler; }