use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project transporter by wang4ever.
the class WSChildHandlerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
WSConfig conf = this.config.getWsConfig();
if (logger.isDebugEnabled())
logger.debug("Initital channel handler...\twebsocketPath={}", conf.getWebsocketPath());
ChannelPipeline p = ch.pipeline();
// Configure SSL.
if (conf.getSslEnable()) {
/*
* SelfSignedCertificate ssc = new SelfSignedCertificate();
* SslContext sslCtx =
* SslContextBuilder.forServer(ssc.certificate(),
* ssc.privateKey()).build();
*/
File keyCertChainFile = new File(Resources.getResource(conf.getKeyCertChainFile()).getFile());
File keyFile = new File(Resources.getResource(conf.getKeyFile()).getFile());
SslContext sslCtx = SslContextBuilder.forServer(keyCertChainFile, keyFile).build();
p.addLast(sslCtx.newHandler(ch.alloc()));
if (logger.isDebugEnabled())
logger.debug("The ssl(wss) handler has been enabled. sslCtx={}", sslCtx.toString());
}
// pipeline管理channel中的Handler,在channel队列中添加一个handler来处理业务
if (conf.getLoggingEnable()) {
p.addLast(new LoggingHandler(LogLevel.valueOf(conf.getLoggingLevel())));
if (logger.isInfoEnabled())
logger.info("Netty internal log has been used. (WS)level={}", conf.getLoggingLevel());
}
IdleStateHandler idleHandler = new IdleStateHandler(conf.getReadIdleSeconds(), conf.getWriteIdleSeconds(), conf.getAllIdleSeconds());
p.addLast(idleHandler);
// 将请求和应答消息解码为HTTP消息
p.addLast("http-codec", new HttpServerCodec());
// 将HTTP消息的多个部分合成一条完整的HTTP消息
p.addLast("aggregator", new HttpObjectAggregator(65536));
// 向客户端发送HTML5文件
p.addLast("http-chunked", new ChunkedWriteHandler());
p.addLast("ws-protocol", new WebSocketServerProtocolHandler(conf.getWebsocketPath(), null, true));
p.addLast("text-handler", SpringContextHolder.getBean("textWSFrameHandler"));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project brave by openzipkin.
the class ITNettyHttpTracing method init.
@Override
protected void init() throws Exception {
stop();
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(NettyHttpTracing.create(httpTracing).serverHandler());
p.addLast(new TestHandler(httpTracing));
}
});
Channel ch = b.bind(0).sync().channel();
port = ((InetSocketAddress) ch.localAddress()).getPort();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project brave by openzipkin.
the class NettyHttpServerBenchmarks method initServer.
@Override
protected int initServer() throws InterruptedException {
bossGroup = new NioEventLoopGroup(1);
workerGroup = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.option(ChannelOption.SO_BACKLOG, 1024);
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<Channel>() {
@Override
protected void initChannel(final Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec());
p.addLast(new TracingDispatchHandler());
p.addLast(new HelloWorldHandler());
}
});
Channel ch = b.bind(0).sync().channel();
return ((InetSocketAddress) ch.localAddress()).getPort();
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project BRFS by zhangnianli.
the class NettyMessageServer method bind.
public void bind(int port) throws Exception {
// 配置服务端的NIO线程组
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).option(ChannelOption.SO_BACKLOG, 100).handler(new LoggingHandler(LogLevel.INFO)).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) {
ch.pipeline().addLast("http-decoder", new HttpRequestDecoder());
ch.pipeline().addLast("http-servercodec", new HttpServerCodec());
// 定义缓冲数据量
ch.pipeline().addLast("http-aggegator", new HttpObjectAggregator(1024 * 1024 * 64));
// ch.pipeline().addLast(new ProtobufVarint32FrameDecoder());
// ch.pipeline().addLast(
// new ProtobufDecoder(NettyMessageProto.NettyMessageReqRes.getDefaultInstance()));
// ch.pipeline().addLast(new ProtobufVarint32LengthFieldPrepender());
// ch.pipeline().addLast(new ProtobufEncoder());
// ch.pipeline().addLast("http-chunked",new ChunkedWriteHandler());
ch.pipeline().addLast(new NettyMessageServerHandler());
ch.pipeline().addLast("http-responseencoder", new HttpResponseEncoder());
}
});
// 绑定端口,同步等待成功
ChannelFuture f = b.bind(port).sync();
System.out.println("init start");
// 等待服务端监听端口关闭
f.channel().closeFuture().sync();
} finally {
// 优雅退出,释放线程池资源
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpServerCodec in project ballerina by ballerina-lang.
the class WebSocketRemoteServerInitializer method initChannel.
@Override
public void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
if (sslCtx != null) {
pipeline.addLast(sslCtx.newHandler(ch.alloc()));
}
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new WebSocketServerCompressionHandler());
pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
WebSocketRemoteServerFrameHandler frameHandler = new WebSocketRemoteServerFrameHandler();
FRAME_HANDLERS.add(frameHandler);
pipeline.addLast(frameHandler);
}
Aggregations