use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project cxf by apache.
the class NettyHttpServletPipelineFactory method getDefaulHttpChannelPipeline.
protected ChannelPipeline getDefaulHttpChannelPipeline(Channel channel) throws Exception {
// Create a default pipeline implementation.
ChannelPipeline pipeline = channel.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.log(Level.FINE, "Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(maxChunkContentSize));
// Remove the following line if you don't want automatic content
// compression.
pipeline.addLast("deflater", new HttpContentCompressor());
// Set up the idle handler
pipeline.addLast("idle", new IdleStateHandler(nettyHttpServerEngine.getReadIdleTime(), nettyHttpServerEngine.getWriteIdleTime(), 0));
return pipeline;
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator 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.HttpObjectAggregator in project BRFS by zhangnianli.
the class NettyChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
final ChannelPipeline pipeline = ch.pipeline();
// server端发送的是httpResponse,所以要使用HttpResponseEncoder进行编码
pipeline.addLast(new HttpResponseEncoder());
// server端接收到的是httpRequest,所以要使用HttpRequestDecoder进行解码
pipeline.addLast(new HttpRequestDecoder());
pipeline.addLast(new HttpObjectAggregator(65536));
pipeline.addLast(new ChunkedWriteHandler());
contextHandlers.forEach(new Consumer<NettyHttpContextHandler>() {
@Override
public void accept(NettyHttpContextHandler handler) {
pipeline.addLast(handler);
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator 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.HttpObjectAggregator in project reactor-netty by reactor.
the class HttpClientOperations method withWebsocketSupport.
final Mono<Void> withWebsocketSupport(URI url, String protocols, BiFunction<? super WebsocketInbound, ? super WebsocketOutbound, ? extends Publisher<Void>> websocketHandler) {
// prevent further header to be sent for handshaking
if (markSentHeaders()) {
addHandlerFirst(NettyPipeline.HttpAggregator, new HttpObjectAggregator(8192));
HttpClientWSOperations ops = new HttpClientWSOperations(url, protocols, this);
if (replace(ops)) {
Mono<Void> handshake = FutureMono.from(ops.handshakerResult).then(Mono.defer(() -> Mono.from(websocketHandler.apply(ops, ops))));
if (websocketHandler != noopHandler()) {
handshake = handshake.doAfterSuccessOrError(ops);
}
return handshake;
}
} else if (isWebsocket()) {
HttpClientWSOperations ops = (HttpClientWSOperations) get(channel());
if (ops != null) {
Mono<Void> handshake = FutureMono.from(ops.handshakerResult);
if (websocketHandler != noopHandler()) {
handshake = handshake.then(Mono.defer(() -> Mono.from(websocketHandler.apply(ops, ops))).doAfterSuccessOrError(ops));
}
return handshake;
}
} else {
log.error("Cannot enable websocket if headers have already been sent");
}
return Mono.error(new IllegalStateException("Failed to upgrade to websocket"));
}
Aggregations