本文整理汇总了Java中io.netty.handler.codec.http.HttpServerCodec类的典型用法代码示例。如果您正苦于以下问题:Java HttpServerCodec类的具体用法?Java HttpServerCodec怎么用?Java HttpServerCodec使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
HttpServerCodec类属于io.netty.handler.codec.http包,在下文中一共展示了HttpServerCodec类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setupWSChannel
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的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.HttpServerCodec; //导入依赖的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));
}
示例3: initChannel
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的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));
}
示例4: initChannel
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的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));
}
示例5: initChannel
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的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));
}
示例6: initChannel
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的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));
}
示例7: configure
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Override
public void configure(final ChannelPipeline pipeline) {
if (logger.isDebugEnabled())
pipeline.addLast(new LoggingHandler("log-io", LogLevel.DEBUG));
pipeline.addLast("http-server", new HttpServerCodec());
if (logger.isDebugEnabled())
pipeline.addLast(new LoggingHandler("http-io", LogLevel.DEBUG));
pipeline.addLast(new HttpObjectAggregator(settings.maxContentLength));
if (authenticator != null) {
// Cannot add the same handler instance to multiple times unless
// it is marked as @Sharable, indicating a race condition will
// not occur. It may not be a safe assumption that the handler
// is sharable so create a new handler each time.
authenticationHandler = authenticator.getClass() == AllowAllAuthenticator.class ?
null : new HttpBasicAuthenticationHandler(authenticator);
if (authenticationHandler != null)
pipeline.addLast(PIPELINE_AUTHENTICATOR, authenticationHandler);
}
pipeline.addLast("http-gremlin-handler", httpGremlinEndpointHandler);
}
示例8: addByteDecoderWhenFullReactorPipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Test
public void addByteDecoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new LineBasedFrameDecoder(12);
testContext.addHandlerLast("decoder", decoder)
.addHandlerFirst("decoder$extract",
NettyPipeline.inboundHandler(ADD_EXTRACTOR));
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"decoder$extract",
"decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
示例9: addNonByteDecoderWhenFullReactorPipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Test
public void addNonByteDecoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler decoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerLast("decoder", decoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"decoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
示例10: addByteEncoderWhenFullReactorPipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Test
public void addByteEncoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new LineBasedFrameDecoder(12);
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
示例11: addNonByteEncoderWhenFullReactorPipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Test
public void addNonByteEncoderWhenFullReactorPipeline() throws Exception {
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
ChannelHandler encoder = new ChannelHandlerAdapter() {
};
testContext.addHandlerFirst("encoder", encoder);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
示例12: addSeveralByteEncodersWhenCodec
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Test
public void addSeveralByteEncodersWhenCodec() throws Exception {
ChannelHandler encoder1 = new LineBasedFrameDecoder(12);
ChannelHandler encoder2 = new LineBasedFrameDecoder(13);
channel.pipeline()
.addLast(NettyPipeline.HttpCodec, new HttpServerCodec())
.addLast(NettyPipeline.HttpServerHandler, new ChannelDuplexHandler())
.addLast(NettyPipeline.ReactiveBridge, new ChannelHandlerAdapter() {
});
testContext.addHandlerFirst("encoder1", encoder1)
.addHandlerFirst("encoder2", encoder2);
assertEquals(channel.pipeline()
.names(),
Arrays.asList(NettyPipeline.HttpCodec,
NettyPipeline.HttpServerHandler,
"encoder2",
"encoder1",
NettyPipeline.ReactiveBridge,
"DefaultChannelPipeline$TailContext#0"));
}
示例13: configurePipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(new Http2MultiplexCodec(true, new HelloWorldHttp2Handler()));
return;
}
if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
ctx.pipeline().addLast(new HttpServerCodec(),
new HttpObjectAggregator(MAX_CONTENT_LENGTH),
new HelloWorldHttp1Handler("ALPN Negotiation"));
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
示例14: configurePipeline
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
@Override
protected void configurePipeline(ChannelHandlerContext ctx, String protocol) throws Exception {
if (ApplicationProtocolNames.HTTP_2.equals(protocol)) {
ctx.pipeline().addLast(new HelloWorldHttp2HandlerBuilder().build());
return;
}
if (ApplicationProtocolNames.HTTP_1_1.equals(protocol)) {
ctx.pipeline().addLast(new HttpServerCodec(),
new HttpObjectAggregator(MAX_CONTENT_LENGTH),
new HelloWorldHttp1Handler("ALPN Negotiation"));
return;
}
throw new IllegalStateException("unknown protocol: " + protocol);
}
示例15: createInitializer
import io.netty.handler.codec.http.HttpServerCodec; //导入依赖的package包/类
protected ChannelInitializer<Channel> createInitializer() {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(Channel ch) throws Exception {
ChannelPipeline p = ch.pipeline();
p.addLast(new HttpServerCodec() );
p.addLast(new ChunkedWriteHandler());
p.addLast(new HttpObjectAggregator(64 * 1024));
p.addLast(new EchoServerHttpRequestHandler("/ws"));
p.addLast(new WebSocketServerProtocolHandler("/ws"));
p.addLast(new EchoServerWSHandler());
}
};
}