本文整理汇总了Java中io.netty.handler.codec.http.HttpObjectAggregator类的典型用法代码示例。如果您正苦于以下问题:Java HttpObjectAggregator类的具体用法?Java HttpObjectAggregator怎么用?Java HttpObjectAggregator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpObjectAggregator类属于io.netty.handler.codec.http包,在下文中一共展示了HttpObjectAggregator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupWSChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
protected ChannelHandler setupWSChannel(SslContext sslCtx, Configuration conf, DataStore datastore) {
return new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("ssl", sslCtx.newHandler(ch.alloc()));
ch.pipeline().addLast("httpServer", new HttpServerCodec());
ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
ch.pipeline().addLast("sessionExtractor", new WebSocketHttpCookieHandler(config));
ch.pipeline().addLast("idle-handler", new IdleStateHandler(conf.getWebsocket().getTimeout(), 0, 0));
ch.pipeline().addLast("ws-protocol", new WebSocketServerProtocolHandler(WS_PATH, null, true));
ch.pipeline().addLast("wsDecoder", new WebSocketRequestDecoder(datastore, config));
ch.pipeline().addLast("error", new WSExceptionHandler());
}
};
}
示例2: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(409, configuration.getMaxHeaderSize(), 8192));
pipeline.addLast("encoder", new HttpResponseEncoder());
if (configuration.isChunked()) {
pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
}
if (configuration.isCompression()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
pipeline.addLast("handler", channelFactory.getChannelHandler());
}
示例3: appendHttpPipeline
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
public final ChannelPipeline appendHttpPipeline(ChannelPipeline channelPipeline) {
// 服务端,对响应编码。属于ChannelOutboundHandler,逆序执行
channelPipeline.addLast("encoder", new HttpResponseEncoder());
// 服务端,对请求解码。属于ChannelIntboundHandler,按照顺序执行
channelPipeline.addLast("decoder", new HttpRequestDecoder());
//即通过它可以把 HttpMessage 和 HttpContent 聚合成一个 FullHttpRequest,并定义可以接受的数据大小,在文件上传时,可以支持params+multipart
channelPipeline.addLast("aggregator", new HttpObjectAggregator(maxConentLength));
//块写入写出Handler
channelPipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
// 对传输数据进行压缩,这里在客户端需要解压缩处理
// channelPipeline.addLast("deflater", new HttpContentCompressor());
HttpServletHandler servletHandler = new HttpServletHandler();
servletHandler.addInterceptor(new ChannelInterceptor());
//servletHandler.addInterceptor(new HttpSessionInterceptor(getHttpSessionStore()));
// 自定义Handler
channelPipeline.addLast("handler", servletHandler);
// 异步
// channelPipeline.addLast(businessExecutor, new AsyncHttpServletHandler());
return channelPipeline;
}
示例4: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
if(sslCtx!=null)
{
p.addLast(new SslHandler(sslCtx.newEngine(ch.alloc())));
}
p.addLast(new HttpResponseEncoder());//必须放在最前面,如果decoder途中需要回复消息,则decoder前面需要encoder
p.addLast(new HttpRequestDecoder());
p.addLast(new HttpObjectAggregator(65536));//限制contentLength
//大文件传输处理
// p.addLast(new ChunkedWriteHandler());
// p.addLast(new HttpContentCompressor());
//跨域配置
CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
p.addLast(new CorsHandler(corsConfig));
p.addLast(new DefaultListenerHandler<HttpRequest>(listener));
}
示例5: fixHandlerBeforeConnect
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
/**
* 适配
*/
@Override
protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
ChannelHandler result=new ShareableChannelInboundHandler() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Channel ch=ctx.channel();
ch.pipeline().addLast(new HttpClientCodec());
ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
ctx.pipeline().remove(this);//移除当前handler
ctx.pipeline().fireChannelRegistered();//重新从第一个handler抛出事件
}
};
// ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
// @Override
// protected void initChannel(SocketChannel ch) {
// ch.pipeline().addLast(new HttpClientCodec());
// ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
// ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
// ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
// }
// };
return result;
}
示例6: fixHandlerBeforeConnect
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
/**
* 适配
*/
@Override
protected ChannelHandler fixHandlerBeforeConnect(final ChannelHandler handler) {
ChannelHandler result=new ShareableChannelInboundHandler() {
@Override
public void channelRegistered(ChannelHandlerContext ctx) throws Exception {
Channel ch=ctx.channel();
ch.pipeline().addLast(new HttpClientCodec());
ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
ctx.pipeline().remove(this);//移除当前handler
ctx.fireChannelRegistered();//重新从第一个handler抛出事件
}
};
// ChannelInitializer<SocketChannel> result=new ChannelInitializer<SocketChannel>() {
// @Override
// protected void initChannel(SocketChannel ch) {
// ch.pipeline().addLast(new HttpClientCodec());
// ch.pipeline().addLast(new HttpObjectAggregator(64*1024));
// ch.pipeline().addLast(new WebSocketClientProtocolHandler(WebSocketClientHandshakerFactory.newHandshaker(uri, WebSocketVersion.V13, null, false, new DefaultHttpHeaders())));
// ch.pipeline().addLast(new WebSocketConnectedClientHandler(handler));
// }
// };
return result;
}
示例7: init
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
public void init() {
super.init();
b.group(bossGroup, workGroup)
.channel(NioServerSocketChannel.class)
.option(ChannelOption.SO_KEEPALIVE, false)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_BACKLOG, 1024)
.localAddress(new InetSocketAddress(port))
.childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast(defLoopGroup,
new HttpRequestDecoder(), //请求解码器
new HttpObjectAggregator(65536),//将多个消息转换成单一的消息对象
new HttpResponseEncoder(), // 响应编码器
new HttpServerHandler(snowFlake)//自定义处理器
);
}
});
}
示例8: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
try {
ch.config().setOption(ChannelOption.IP_TOS, 0x18);
// ch.config().setOption(ChannelOption.WRITE_BUFFER_HIGH_WATER_MARK, 32 * 1024);
// ch.config().setOption(ChannelOption.WRITE_BUFFER_LOW_WATER_MARK, 8 * 1024);
} catch (ChannelException ex) {
// IP_TOS not supported by platform, ignore
}
ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
PacketRegistry r = new PacketRegistry();
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(65536));
ch.pipeline().addLast(new WebSocketHandler());
ch.pipeline().addLast(new PacketDecoder(r));
ch.pipeline().addLast(new PacketEncoder(r));
ch.pipeline().addLast(new ClientHandler(server));
}
示例9: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
try {
ch.config().setOption(ChannelOption.TCP_NODELAY, true);
ch.config().setOption(ChannelOption.IP_TOS, 0x18);
} catch (ChannelException ex) {
// IP_TOS not supported by platform, ignore
}
ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
PacketRegistry r = new PacketRegistry();
ch.pipeline().addLast("idleStateHandler", new IdleStateHandler(0, 0, 30));
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(65536));
ch.pipeline().addLast(new WebSocketHandler());
ch.pipeline().addLast(new PacketDecoder(r));
ch.pipeline().addLast(new PacketEncoder(r));
ch.pipeline().addLast(mExecutorGroup, "serverHandler", new ClientHandler(mServer));
}
示例10: doStart
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void doStart(Listener listener) throws Throwable {
workerGroup = new NioEventLoopGroup(http_work, new DefaultThreadFactory(ThreadNames.T_HTTP_CLIENT));
b = new Bootstrap();
b.group(workerGroup);
b.channel(NioSocketChannel.class);
b.option(ChannelOption.SO_KEEPALIVE, true);
b.option(ChannelOption.TCP_NODELAY, true);
b.option(ChannelOption.SO_REUSEADDR, true);
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 4000);
b.option(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
b.handler(new ChannelInitializer<SocketChannel>() {
@Override
public void initChannel(SocketChannel ch) throws Exception {
ch.pipeline().addLast("decoder", new HttpResponseDecoder());
ch.pipeline().addLast("aggregator", new HttpObjectAggregator(maxContentLength));
ch.pipeline().addLast("encoder", new HttpRequestEncoder());
ch.pipeline().addLast("handler", new HttpClientHandler(NettyHttpClient.this));
}
});
timer = new HashedWheelTimer(new NamedThreadFactory(T_HTTP_TIMER), 1, TimeUnit.SECONDS, 64);
listener.onSuccess();
}
示例11: channelRead
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof ByteBuf && ctx.channel().isActive()) {
boolean isHttpRequest = false;
ByteBuf buffer = (ByteBuf) msg;
final int len = 11;
if (buffer.readableBytes() > len) {
byte[] dst = new byte[len];
buffer.getBytes(buffer.readerIndex(), dst, 0, len);
int n = HttpMethodUtil.method(dst);
isHttpRequest = n > 2;
}
if (isHttpRequest) {
ChannelPipeline cp = ctx.pipeline();
String currentName = ctx.name();
cp.addAfter(currentName, "HttpRequestDecoder", new HttpRequestDecoder());
cp.addAfter("HttpRequestDecoder", "HttpResponseEncoder", new HttpResponseEncoder());
cp.addAfter("HttpResponseEncoder", "HttpObjectAggregator", new HttpObjectAggregator(512 * 1024));
ChannelHandler handler = serverDef.httpHandlerFactory.create(serverDef);
cp.addAfter("HttpObjectAggregator", "HttpThriftBufDecoder", handler);
cp.remove(currentName);
}
}
ctx.fireChannelRead(msg);
}
示例12: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
try {
ch.config().setOption(ChannelOption.IP_TOS, 0x18);
} catch (ChannelException ex) {
// IP_TOS not supported by platform, ignore
}
ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(65536));
ch.pipeline().addLast(new WebSocketHandler());
ch.pipeline().addLast(new PacketDecoder());
ch.pipeline().addLast(new PacketEncoder());
ch.pipeline().addLast(new ClientHandler(server));
}
示例13: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel channel) throws SSLException {
URI uri = config.getConnectionWebsocketUri();
DefaultHttpHeaders headers = new DefaultHttpHeaders();
headers.add(USER_ID_HEADER, config.getConnectionUserId().toString());
headers.add(USER_PASSWORD_HEADER, config.getConnectionUserPassword());
headers.add(SUPPLIER_ID_HEADER, config.getConnectionServerId());
WebSocketClientHandshaker handshaker = WebSocketClientHandshakerFactory.newHandshaker(uri, WS_VERSION, null, false, headers);
ChannelPipeline pipeline = channel.pipeline();
if (config.isConnectionSecure()) {
try {
SslContext sslContext = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE);
pipeline.addLast(sslContext.newHandler(channel.alloc()));
} catch (SSLException e) {
logger.log(Level.SEVERE, "Shutting down client due to unexpected failure to create SSL context", e);
throw e;
}
}
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(8192));
pipeline.addLast(new AudioConnectClientHandler(handshaker));
}
示例14: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(SocketChannel ch) throws Exception {
try {
ch.config().setOption(ChannelOption.IP_TOS, 0x18);
} catch (ChannelException ex) {
// IP_TOS not supported by platform, ignore
}
ch.config().setAllocator(PooledByteBufAllocator.DEFAULT);
ch.pipeline().addLast(new HttpServerCodec());
ch.pipeline().addLast(new HttpObjectAggregator(65536));
ch.pipeline().addLast(new Handshaker());
ch.pipeline().addLast(new WebSocketHandler());
ch.pipeline().addLast(new PacketDecoder());
ch.pipeline().addLast(new PacketEncoder());
ch.pipeline().addLast(new ClientHandler(server));
}
示例15: initChannel
import io.netty.handler.codec.http.HttpObjectAggregator; //导入依赖的package包/类
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();
//编解码http请求
pipeline.addLast(new HttpServerCodec());
//聚合解码HttpRequest/HttpContent/LastHttpContent到FullHttpRequest
//保证接收的Http请求的完整性
pipeline.addLast(new HttpObjectAggregator(64 *1024));
//写文件内容
pipeline.addLast(new ChunkedWriteHandler());
//处理FullHttpRequest
pipeline.addLast(new HttpRequestHandler("/ws"));
//处理其他的WebSocketFrame
pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
//处理TextWebSocketFrame
pipeline.addLast(new TextWebSocketFrameHandler(group));
}