Search in sources :

Example 21 with ChunkedWriteHandler

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

the class HttpCorsServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    CorsConfig corsConfig = CorsConfigBuilder.forAnyOrigin().allowNullOrigin().allowCredentials().build();
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpResponseEncoder());
    pipeline.addLast(new HttpRequestDecoder());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new CorsHandler(corsConfig));
    pipeline.addLast(new OkResponseHandler());
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) CorsConfig(io.netty.handler.codec.http.cors.CorsConfig) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) CorsHandler(io.netty.handler.codec.http.cors.CorsHandler) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 22 with ChunkedWriteHandler

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

the class HttpStaticFileServerInitializer method initChannel.

@Override
public void initChannel(SocketChannel ch) {
    ChannelPipeline pipeline = ch.pipeline();
    if (sslCtx != null) {
        pipeline.addLast(sslCtx.newHandler(ch.alloc()));
    }
    pipeline.addLast(new HttpServerCodec());
    pipeline.addLast(new HttpObjectAggregator(65536));
    pipeline.addLast(new ChunkedWriteHandler());
    pipeline.addLast(new HttpStaticFileServerHandler());
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) ChannelPipeline(io.netty.channel.ChannelPipeline)

Example 23 with ChunkedWriteHandler

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

the class JerseyServerInitializer method configureClearText.

/**
     * Configure the pipeline for a cleartext upgrade from HTTP to HTTP/2.
     */
private void configureClearText(SocketChannel ch) {
    final ChannelPipeline p = ch.pipeline();
    final HttpServerCodec sourceCodec = new HttpServerCodec();
    p.addLast(sourceCodec);
    p.addLast(new HttpServerUpgradeHandler(sourceCodec, new HttpServerUpgradeHandler.UpgradeCodecFactory() {

        @Override
        public HttpServerUpgradeHandler.UpgradeCodec newUpgradeCodec(CharSequence protocol) {
            if (AsciiString.contentEquals(Http2CodecUtil.HTTP_UPGRADE_PROTOCOL_NAME, protocol)) {
                return new Http2ServerUpgradeCodec(new Http2Codec(true, new JerseyHttp2ServerHandler(baseUri, container)));
            } else {
                return null;
            }
        }
    }));
    p.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.
            // "Directly talking: " + msg.protocolVersion() + " (no upgrade was attempted)");
            ChannelPipeline pipeline = ctx.pipeline();
            ChannelHandlerContext thisCtx = pipeline.context(this);
            pipeline.addAfter(thisCtx.name(), null, new JerseyServerHandler(baseUri, container));
            pipeline.replace(this, null, new ChunkedWriteHandler());
            ctx.fireChannelRead(msg);
        }
    });
}
Also used : Http2ServerUpgradeCodec(io.netty.handler.codec.http2.Http2ServerUpgradeCodec) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) HttpServerUpgradeHandler(io.netty.handler.codec.http.HttpServerUpgradeHandler) ChannelPipeline(io.netty.channel.ChannelPipeline) Http2Codec(io.netty.handler.codec.http2.Http2Codec) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec) HttpMessage(io.netty.handler.codec.http.HttpMessage)

Example 24 with ChunkedWriteHandler

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

the class NetServerImpl method initChannel.

@Override
protected void initChannel(ChannelPipeline pipeline) {
    if (sslHelper.isSSL()) {
        SslHandler sslHandler = sslHelper.createSslHandler(vertx);
        pipeline.addLast("ssl", sslHandler);
    }
    if (logEnabled) {
        pipeline.addLast("logging", new LoggingHandler());
    }
    if (sslHelper.isSSL()) {
        // only add ChunkedWriteHandler when SSL is enabled otherwise it is not needed as FileRegion is used.
        // For large file / sendfile support
        pipeline.addLast("chunkedWriter", new ChunkedWriteHandler());
    }
    if (options.getIdleTimeout() > 0) {
        pipeline.addLast("idle", new IdleStateHandler(0, 0, options.getIdleTimeout()));
    }
}
Also used : LoggingHandler(io.netty.handler.logging.LoggingHandler) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) IdleStateHandler(io.netty.handler.timeout.IdleStateHandler) SslHandler(io.netty.handler.ssl.SslHandler)

Example 25 with ChunkedWriteHandler

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

the class CatchupServer method start.

@Override
public synchronized void start() throws Throwable {
    if (channel != null) {
        return;
    }
    workerGroup = new NioEventLoopGroup(0, threadFactory);
    ServerBootstrap bootstrap = new ServerBootstrap().group(workerGroup).channel(NioServerSocketChannel.class).localAddress(listenAddress.socketAddress()).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            CatchupServerProtocol protocol = new CatchupServerProtocol();
            ChannelPipeline pipeline = ch.pipeline();
            pipeline.addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE, 0, 4, 0, 4));
            pipeline.addLast(new LengthFieldPrepender(4));
            pipeline.addLast(new VersionDecoder(logProvider));
            pipeline.addLast(new VersionPrepender());
            pipeline.addLast(new ResponseMessageTypeEncoder());
            pipeline.addLast(new RequestMessageTypeEncoder());
            pipeline.addLast(new TxPullResponseEncoder());
            pipeline.addLast(new CoreSnapshotEncoder());
            pipeline.addLast(new GetStoreIdResponseEncoder());
            pipeline.addLast(new StoreCopyFinishedResponseEncoder());
            pipeline.addLast(new TxStreamFinishedResponseEncoder());
            pipeline.addLast(new FileChunkEncoder());
            pipeline.addLast(new FileHeaderEncoder());
            pipeline.addLast(new ServerMessageTypeHandler(protocol, logProvider));
            pipeline.addLast(decoders(protocol));
            pipeline.addLast(new TxPullRequestHandler(protocol, storeIdSupplier, dataSourceAvailabilitySupplier, transactionIdStoreSupplier, logicalTransactionStoreSupplier, txPullBatchSize, monitors, logProvider));
            pipeline.addLast(new ChunkedWriteHandler());
            pipeline.addLast(new GetStoreRequestHandler(protocol, dataSourceSupplier, checkPointerSupplier, fs, pageCache, logProvider, storeCopyCheckPointMutex));
            pipeline.addLast(new GetStoreIdRequestHandler(protocol, storeIdSupplier));
            if (coreState != null) {
                pipeline.addLast(new CoreSnapshotRequestHandler(protocol, coreState));
            }
            pipeline.addLast(new ExceptionLoggingHandler(log));
            pipeline.addLast(new ExceptionMonitoringHandler(monitors.newMonitor(ExceptionMonitoringHandler.Monitor.class, CatchupServer.class)));
            pipeline.addLast(new ExceptionSwallowingHandler());
        }
    });
    try {
        channel = bootstrap.bind().syncUninterruptibly().channel();
    } catch (Exception e) {
        //noinspection ConstantConditions
        if (e instanceof BindException) {
            userLog.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress);
            log.error("Address is already bound for setting: " + CausalClusteringSettings.transaction_listen_address + " with value: " + listenAddress, e);
            throw e;
        }
    }
}
Also used : SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) ExceptionSwallowingHandler(org.neo4j.causalclustering.handlers.ExceptionSwallowingHandler) VersionPrepender(org.neo4j.causalclustering.VersionPrepender) TxStreamFinishedResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxStreamFinishedResponseEncoder) GetStoreIdResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdResponseEncoder) LengthFieldPrepender(io.netty.handler.codec.LengthFieldPrepender) CoreSnapshotRequestHandler(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotRequestHandler) ExceptionLoggingHandler(org.neo4j.causalclustering.handlers.ExceptionLoggingHandler) FileHeaderEncoder(org.neo4j.causalclustering.catchup.storecopy.FileHeaderEncoder) LengthFieldBasedFrameDecoder(io.netty.handler.codec.LengthFieldBasedFrameDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) TxPullRequestHandler(org.neo4j.causalclustering.catchup.tx.TxPullRequestHandler) GetStoreRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreRequestHandler) FileChunkEncoder(org.neo4j.causalclustering.catchup.storecopy.FileChunkEncoder) BindException(java.net.BindException) VersionDecoder(org.neo4j.causalclustering.VersionDecoder) TxPullResponseEncoder(org.neo4j.causalclustering.catchup.tx.TxPullResponseEncoder) StoreCopyFinishedResponseEncoder(org.neo4j.causalclustering.catchup.storecopy.StoreCopyFinishedResponseEncoder) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) ChannelPipeline(io.netty.channel.ChannelPipeline) BindException(java.net.BindException) ExceptionMonitoringHandler(org.neo4j.causalclustering.handlers.ExceptionMonitoringHandler) CoreSnapshotEncoder(org.neo4j.causalclustering.core.state.snapshot.CoreSnapshotEncoder) ChunkedWriteHandler(io.netty.handler.stream.ChunkedWriteHandler) GetStoreIdRequestHandler(org.neo4j.causalclustering.catchup.storecopy.GetStoreIdRequestHandler)

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