use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project camel by apache.
the class HttpServerInitializerFactory method initChannel.
@Override
protected void initChannel(Channel ch) throws Exception {
// create a new pipeline
ChannelPipeline pipeline = ch.pipeline();
SslHandler sslHandler = configureServerSSLOnDemand();
if (sslHandler != null) {
//TODO must close on SSL exception
// sslHandler.setCloseOnSSLException(true);
LOG.debug("Server SSL handler configured and added as an interceptor against the ChannelPipeline: {}", sslHandler);
pipeline.addLast("ssl", sslHandler);
}
pipeline.addLast("decoder", new HttpRequestDecoder(4096, configuration.getMaxHeaderSize(), 8192));
List<ChannelHandler> decoders = consumer.getConfiguration().getDecoders();
for (int x = 0; x < decoders.size(); x++) {
ChannelHandler decoder = decoders.get(x);
if (decoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
}
pipeline.addLast("decoder-" + x, decoder);
}
pipeline.addLast("encoder", new HttpResponseEncoder());
List<ChannelHandler> encoders = consumer.getConfiguration().getEncoders();
for (int x = 0; x < encoders.size(); x++) {
ChannelHandler encoder = encoders.get(x);
if (encoder instanceof ChannelHandlerFactory) {
// use the factory to create a new instance of the channel as it may not be shareable
encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
}
pipeline.addLast("encoder-" + x, encoder);
}
pipeline.addLast("aggregator", new HttpObjectAggregator(configuration.getChunkedMaxContentLength()));
if (supportCompressed()) {
pipeline.addLast("deflater", new HttpContentCompressor());
}
int port = consumer.getConfiguration().getPort();
ChannelHandler handler = consumer.getEndpoint().getComponent().getMultiplexChannelHandler(port).getChannelHandler();
if (consumer.getConfiguration().isUsingExecutorService()) {
EventExecutorGroup applicationExecutor = consumer.getEndpoint().getComponent().getExecutorService();
pipeline.addLast(applicationExecutor, "handler", handler);
} else {
pipeline.addLast("handler", handler);
}
}
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 TelnetProcessHandler());
p.remove(this);
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project xian by happyyangyuan.
the class OAuthServer method startServer.
public void startServer() {
synchronized (LOCK) {
if (started.get()) {
LOG.warn("已启动,不允许重复启动");
return;
}
EventLoopGroup bossGroup = new NioEventLoopGroup();
EventLoopGroup workerGroup = new NioEventLoopGroup();
try {
ServerBootstrap b = new ServerBootstrap();
b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer() {
protected void initChannel(Channel ch) throws Exception {
ch.pipeline().addLast("encoder", new HttpResponseEncoder()).addLast("decoder", new HttpRequestDecoder()).addLast("aggregator", new HttpObjectAggregator(4096)).addLast("handler", new OAuth20Handler());
}
}).option(ChannelOption.SO_BACKLOG, 10240).option(ChannelOption.SO_REUSEADDR, true);
LOG.info(String.format("[OAuth] oauth server is about to start on port {%s} ", PORT));
parentChannel = b.bind(PORT).sync().channel();
LOG.info(String.format("[OAuth] oauth server started on port {%s} ", PORT));
ThreadPoolManager.execute(() -> {
try {
LOG.debug("[OAuth] Wait until the server socket is closed.");
parentChannel.closeFuture().sync();
} catch (Throwable ee) {
LOG.error(ee);
} finally {
LOG.info("[OAuth] 准备shutdown oauth server");
bossGroup.shutdownGracefully();
workerGroup.shutdownGracefully();
LOG.info("[OAuth] oauth server shutdown完毕!");
}
});
started.set(true);
} catch (Throwable e) {
LOG.error("[OAuth] oauth server 启动失败", e);
started.set(false);
}
}
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project xian by happyyangyuan.
the class HttpFileServer method doStart.
private void doStart(int port) throws InterruptedException {
EventLoopGroup boosGroup = new NioEventLoopGroup();
EventLoopGroup workerGrop = new NioEventLoopGroup();
ServerBootstrap b = new ServerBootstrap();
b.group(boosGroup, workerGrop).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel channel) throws Exception {
// 请求消息解码器
channel.pipeline().addLast("http-decoder", new HttpRequestDecoder());
channel.pipeline().addLast("http-aggregator", new HttpObjectAggregator(1000000));
// 响应消息解码器
channel.pipeline().addLast("http-encoder", new HttpResponseEncoder());
channel.pipeline().addLast("fileServerHandler", new HttpFileHandler());
}
});
ChannelFuture f = b.bind(port).sync();
channel = f.channel();
LOG.info("qcloud-xml-api 服务器启动成功,路径是:http://" + EnvUtil.getLocalIp() + ":" + port);
ThreadPoolManager.execute(() -> {
try {
// 等待channel关闭通知/回调:客户端或者服务端主动关闭
channel.closeFuture().sync();
LOG.info("qcloud-xml-api 服务器完蛋了--");
} catch (InterruptedException e) {
LOG.error(e);
} finally {
boosGroup.shutdownGracefully();
workerGrop.shutdownGracefully();
}
});
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project activemq-artemis by apache.
the class NettyWSTransport method addAdditionalHandlers.
@Override
protected void addAdditionalHandlers(ChannelPipeline pipeline) {
pipeline.addLast(new HttpClientCodec());
pipeline.addLast(new HttpObjectAggregator(8192));
}
Aggregations