Search in sources :

Example 6 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project java-in-action by xinghalo.

the class ChatServerInitializer method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpObjectAggregator(60 * 1024));
    pipeline.addLast(new HttpRequestHandler("/ws"));
    pipeline.addLast(new WebSocketServerProtocolHandler("/ws"));
    pipeline.addLast(new TextWebSocketFrameHandler(group));
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) WebSocketServerProtocolHandler(io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 7 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project ambry by linkedin.

the class ChannelWriteCallback method createEmbeddedChannel.

/**
 * Creates a new {@link EmbeddedChannel} with a {@link ChunkedWriteHandler} and {@link MockNettyMessageProcessor} in
 * the pipeline.
 * @return the created {@link EmbeddedChannel}.
 */
private EmbeddedChannel createEmbeddedChannel() {
    ChunkedWriteHandler chunkedWriteHandler = new ChunkedWriteHandler();
    MockNettyMessageProcessor processor = new MockNettyMessageProcessor();
    return new EmbeddedChannel(chunkedWriteHandler, processor);
}
Also used : ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel)

Example 8 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project async-http-client by AsyncHttpClient.

the class NettyBodyBody method write.

@Override
public void write(final Channel channel, NettyResponseFuture<?> future) {
    Object msg;
    if (body instanceof RandomAccessBody && !ChannelManager.isSslHandlerConfigured(channel.pipeline()) && !config.isDisableZeroCopy()) {
        msg = new BodyFileRegion((RandomAccessBody) body);
    } else {
        msg = new BodyChunkedInput(body);
        BodyGenerator bg = future.getTargetRequest().getBodyGenerator();
        if (bg instanceof FeedableBodyGenerator && !(bg instanceof ReactiveStreamsBodyGenerator)) {
            final ChunkedWriteHandler chunkedWriteHandler = channel.pipeline().get(ChunkedWriteHandler.class);
            FeedableBodyGenerator.class.cast(bg).setListener(new FeedListener() {

                @Override
                public void onContentAdded() {
                    chunkedWriteHandler.resumeTransfer();
                }

                @Override
                public void onError(Throwable t) {
                }
            });
        }
    }
    channel.write(msg, channel.newProgressivePromise()).addListener(new WriteProgressListener(future, false, getContentLength()) {

        public void operationComplete(ChannelProgressiveFuture cf) {
            closeSilently(body);
            super.operationComplete(cf);
        }
    });
    channel.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT, channel.voidPromise());
}
Also used : WriteProgressListener(org.asynchttpclient.netty.request.WriteProgressListener) FeedListener(org.asynchttpclient.request.body.generator.FeedListener) ChannelProgressiveFuture(io.netty.channel.ChannelProgressiveFuture) ReactiveStreamsBodyGenerator(org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) BodyGenerator(org.asynchttpclient.request.body.generator.BodyGenerator) ReactiveStreamsBodyGenerator(org.asynchttpclient.request.body.generator.ReactiveStreamsBodyGenerator) FeedableBodyGenerator(org.asynchttpclient.request.body.generator.FeedableBodyGenerator) FeedableBodyGenerator(org.asynchttpclient.request.body.generator.FeedableBodyGenerator) RandomAccessBody(org.asynchttpclient.request.body.RandomAccessBody)

Example 9 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler in project cxf by apache.

the class NettyHttpClientPipelineFactory method initChannel.

@Override
protected void initChannel(Channel ch) throws Exception {
    ChannelPipeline pipeline = ch.pipeline();
    SslHandler sslHandler = configureClientSSLOnDemand();
    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 HttpResponseDecoder());
    // TODO need to configure the aggregator size
    pipeline.addLast("aggregator", new HttpObjectAggregator(1048576));
    pipeline.addLast("encoder", new HttpRequestEncoder());
    pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    pipeline.addLast("client", new NettyHttpClientHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler)

Example 10 with ChunkedWriteHandler

use of org.apache.flink.shaded.netty4.io.netty.handler.stream.ChunkedWriteHandler 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"));
}
Also used : WSConfig(io.transport.core.config.Configuration.WSConfig) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) File(java.io.File) WebSocketServerProtocolHandler(io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) SslContext(io.netty.handler.ssl.SslContext)

Aggregations

ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)46 ChannelPipeline (io.netty.channel.ChannelPipeline)24 HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)16 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)11 SslHandler (io.netty.handler.ssl.SslHandler)10 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)9 ByteBuf (io.netty.buffer.ByteBuf)8 SocketChannel (io.netty.channel.socket.SocketChannel)8 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)8 LoggingHandler (io.netty.handler.logging.LoggingHandler)8 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)7 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)7 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)6 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)6 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)5 IOException (java.io.IOException)5 ChannelFuture (io.netty.channel.ChannelFuture)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)4 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)4 HttpContentDecompressor (io.netty.handler.codec.http.HttpContentDecompressor)4