use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project duangframework by tcrct.
the class HttpChannelInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if (bootStrap.isSslEnabled()) {
sslContext = bootStrap.getSslContext();
}
// HttpServerCodec包含了默认的HttpRequestDecoder(请求消息解码器)和HttpResponseEncoder(响应解码器)
p.addLast(new HttpServerCodec());
// 为http响应内容添加gizp压缩器
p.addLast(new HttpContentCompressor());
// 目的是将多个消息转换为单一的request或者response对象
p.addLast(new HttpObjectAggregator(1048576));
// 目的是支持异步大文件传输
p.addLast(new ChunkedWriteHandler());
// 真正处理HTTP业务逻辑的地方,针对每个TCP连接创建一个新的ChannelHandler实例
p.addLast(new HttpBaseHandler(bootStrap));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project java by wavefrontHQ.
the class PlainTextOrHttpFrameDecoder method decode.
/**
* Dynamically adds the appropriate encoder/decoder(s) to the pipeline based on the detected
* protocol.
*/
@Override
protected void decode(final ChannelHandlerContext ctx, final ByteBuf buffer, List<Object> out) throws Exception {
// read the first 2 bytes to use for protocol detection
if (buffer.readableBytes() < 2) {
logger.warning("buffer has less that 2 readable bytes");
return;
}
final int firstByte = buffer.getUnsignedByte(buffer.readerIndex());
final int secondByte = buffer.getUnsignedByte(buffer.readerIndex() + 1);
// determine the protocol and add the encoder/decoder
final ChannelPipeline pipeline = ctx.pipeline();
if (isHttp(firstByte, secondByte)) {
pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("aggregator", new HttpObjectAggregator(16 * 1024 * 1024));
pipeline.addLast("deflate", new HttpContentCompressor());
pipeline.addLast("handler", this.handler);
} else {
pipeline.addLast("line", new LineBasedFrameDecoder(4096));
pipeline.addLast("decoder", STRING_DECODER);
pipeline.addLast("encoder", STRING_ENCODER);
pipeline.addLast("handler", this.handler);
}
pipeline.remove(this);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project summer by foxsugar.
the class WebSocketServerInitializer method initChannel.
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
// 处理日志
// pipeline.addLast(new LoggingHandler(LogLevel.INFO));
// 处理心跳
// pipeline.addLast(new IdleStateHandler(15, 0, 0, TimeUnit.SECONDS));
// pipeline.addLast(new ChatHeartbeatHandler());
// // 获取职责链
// pipeline.addLast("http-codec", new HttpServerCodec());
// pipeline.addLast("aggregator", new HttpObjectAggregator(64*1024));
// pipeline.addLast("http-chunked", new ChunkedWriteHandler());
// // pipeline.addLast(new WebSocketServerCompressionHandler());
//
// // pipeline.addLast("encoder", new WsEncoder());
// // pipeline.addLast("decoder", new WsDecoder());
// pipeline.addLast("handshake",new WebSocketServerProtocolHandler("/ws"));
// pipeline.addLast(new WsCodec());
// // pipeline.addLast(new WsGameMsgHandler());
// pipeline.addLast(new WsHandler());
// // pipeline.addLast("codec", new WsEncoder());
// //websocket定义了传递数据的6中frame类型
// // pipeline.addLast(new GameMsgHandler());
//
pipeline.addLast(new HttpServerCodec());
pipeline.addLast(new HttpObjectAggregator(64 * 1024));
pipeline.addLast(new WebSocketServerProtocolHandler("/websocket", null, true));
pipeline.addLast(new WsCodec());
pipeline.addLast(new GameMsgHandler());
// ChannelPipeline pipeline = ch.pipeline();
// pipeline.addLast(new HttpServerCodec());
// pipeline.addLast(new HttpObjectAggregator(65536));
// // pipeline.addLast(new WebSocketServerCompressionHandler());
// // pipeline.addLast(new WebSocketServerProtocolHandler(WEBSOCKET_PATH, null, true));
// // pipeline.addLast(new WebSocketIndexPageHandler(WEBSOCKET_PATH));
// pipeline.addLast(new WebSocketServerHandler());
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project dubbo by alibaba.
the class QosProcessHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if (in.readableBytes() < 1) {
return;
}
// read one byte to guess protocol
final int magic = in.getByte(in.readerIndex());
ChannelPipeline p = ctx.pipeline();
p.addLast(new LocalHostPermitHandler(acceptForeignIp));
if (isHttp(magic)) {
// no welcome output for http protocol
if (welcomeFuture != null && welcomeFuture.isCancellable()) {
welcomeFuture.cancel(false);
}
p.addLast(new HttpServerCodec());
p.addLast(new HttpObjectAggregator(1048576));
p.addLast(new HttpProcessHandler());
p.remove(this);
} else {
p.addLast(new LineBasedFrameDecoder(2048));
p.addLast(new StringDecoder(CharsetUtil.UTF_8));
p.addLast(new StringEncoder(CharsetUtil.UTF_8));
p.addLast(new IdleStateHandler(0, 0, 5 * 60));
p.addLast(new TelnetIdleEventHandler());
p.addLast(new TelnetProcessHandler());
p.remove(this);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project cxf by apache.
the class NettyHttpServletPipelineFactory method getDefaultHttp2ChannelPipeline.
protected ChannelPipeline getDefaultHttp2ChannelPipeline(Channel channel) throws Exception {
// Create a default pipeline implementation with HTTP/2 support
ChannelPipeline pipeline = channel.pipeline();
SslContext sslCtx = configureServerHttp2SSLOnDemand();
if (sslCtx != null) {
final SslHandler sslHandler = sslCtx.newHandler(channel.alloc());
LOG.log(Level.FINE, "Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast(sslHandler, new Http2OrHttpHandler());
return pipeline;
}
final UpgradeCodecFactory upgradeCodecFactory = new UpgradeCodecFactory() {
@Override
public UpgradeCodec newUpgradeCodec(CharSequence protocol) {
if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
return new Http2ServerUpgradeCodec(Http2FrameCodecBuilder.forServer().build(), new Http2MultiplexHandler(createHttp2ChannelInitializer()));
} else {
return null;
}
}
};
final HttpServerCodec sourceCodec = new HttpServerCodec();
final HttpServerUpgradeHandler upgradeHandler = new HttpServerUpgradeHandler(sourceCodec, upgradeCodecFactory);
final CleartextHttp2ServerUpgradeHandler cleartextUpgradeHandler = new CleartextHttp2ServerUpgradeHandler(sourceCodec, upgradeHandler, createHttp2ChannelInitializerPriorKnowledge());
pipeline.addLast(cleartextUpgradeHandler);
pipeline.addLast(new SimpleChannelInboundHandler<HttpMessage>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, HttpMessage msg) throws Exception {
// If this handler is hit then no upgrade has been attempted and the client is just talking HTTP
final ChannelPipeline pipeline = ctx.pipeline();
pipeline.addAfter(applicationExecutor, ctx.name(), "handler", getServletHandler());
pipeline.replace(this, "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));
ctx.fireChannelRead(ReferenceCountUtil.retain(msg));
}
});
return pipeline;
}
Aggregations