Search in sources :

Example 1 with Http2StreamChannelBootstrap

use of io.netty.handler.codec.http2.Http2StreamChannelBootstrap in project netty by netty.

the class Http2MultiplexCodecTest method outboundStreamShouldWriteResetFrameOnClose_headersSent.

@Test
public void outboundStreamShouldWriteResetFrameOnClose_headersSent() {
    childChannelInitializer.handler = new ChannelInboundHandlerAdapter() {

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            ctx.writeAndFlush(new DefaultHttp2HeadersFrame(new DefaultHttp2Headers()));
            ctx.fireChannelActive();
        }
    };
    Http2StreamChannelBootstrap b = new Http2StreamChannelBootstrap();
    b.parentChannel(parentChannel).handler(childChannelInitializer);
    Channel childChannel = b.connect().channel();
    assertTrue(childChannel.isActive());
    Http2HeadersFrame headersFrame = parentChannel.readOutbound();
    assertNotNull(headersFrame);
    assertFalse(Http2CodecUtil.isStreamIdValid(headersFrame.streamId()));
    parentChannel.pipeline().fireUserEventTriggered(new Http2StreamActiveEvent(2, headersFrame));
    childChannel.close();
    parentChannel.runPendingTasks();
    Http2ResetFrame reset = parentChannel.readOutbound();
    assertEquals(2, reset.streamId());
    assertEquals(Http2Error.CANCEL.code(), reset.errorCode());
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Example 2 with Http2StreamChannelBootstrap

use of io.netty.handler.codec.http2.Http2StreamChannelBootstrap in project netty by netty.

the class Http2MultiplexCodecTest method outboundStreamShouldWriteGoAwayWithoutReset.

@Test
public void outboundStreamShouldWriteGoAwayWithoutReset() {
    childChannelInitializer.handler = new ChannelInboundHandlerAdapter() {

        @Override
        public void channelActive(ChannelHandlerContext ctx) throws Exception {
            ctx.writeAndFlush(new DefaultHttp2GoAwayFrame(Http2Error.NO_ERROR));
            ctx.fireChannelActive();
        }
    };
    Http2StreamChannelBootstrap b = new Http2StreamChannelBootstrap();
    b.parentChannel(parentChannel).handler(childChannelInitializer);
    Channel childChannel = b.connect().channel();
    assertTrue(childChannel.isActive());
    Http2GoAwayFrame goAwayFrame = parentChannel.readOutbound();
    assertNotNull(goAwayFrame);
    goAwayFrame.release();
    childChannel.close();
    parentChannel.runPendingTasks();
    Http2ResetFrame reset = parentChannel.readOutbound();
    assertNull(reset);
}
Also used : EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) Channel(io.netty.channel.Channel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) StreamException(io.netty.handler.codec.http2.Http2Exception.StreamException) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter) Test(org.junit.Test)

Example 3 with Http2StreamChannelBootstrap

use of io.netty.handler.codec.http2.Http2StreamChannelBootstrap in project rest.li by linkedin.

the class Http2ChannelLifecycle method doBootstrapStreamChannel.

/**
 * Bootstraps the stream channel from the given parent channel. Returns the stream channel
 * through the success callback if bootstrap succeeds; Return the cause if an exception occurs.
 * @param channel Parent channel to bootstrap the stream channel from.
 * @param callback Callback of the stream channel bootstrap.
 */
private void doBootstrapStreamChannel(Channel channel, Callback<Channel> callback) {
    final Http2StreamChannelBootstrap bootstrap = new Http2StreamChannelBootstrap(channel).handler(new Http2StreamChannelInitializer(_ssl, _maxContentLength));
    bootstrap.open().addListener(future -> {
        if (future.isSuccess()) {
            synchronized (_lock) {
                _childChannelCount++;
            }
            callback.onSuccess((Http2StreamChannel) future.get());
        } else {
            channel.close();
            callback.onError(future.cause());
        }
    });
}
Also used : Http2StreamChannelBootstrap(io.netty.handler.codec.http2.Http2StreamChannelBootstrap)

Example 4 with Http2StreamChannelBootstrap

use of io.netty.handler.codec.http2.Http2StreamChannelBootstrap in project reactor-netty by reactor.

the class HttpClientConfig method openStream.

static Future<Http2StreamChannel> openStream(Channel channel, Http2ConnectionProvider.DisposableAcquire owner, ConnectionObserver observer, ChannelOperations.OnSetup opsFactory, boolean acceptGzip) {
    Http2StreamChannelBootstrap bootstrap = new Http2StreamChannelBootstrap(channel);
    bootstrap.option(ChannelOption.AUTO_READ, false);
    bootstrap.handler(new H2Codec(owner, observer, opsFactory, acceptGzip));
    return bootstrap.open();
}
Also used : Http2StreamChannelBootstrap(io.netty.handler.codec.http2.Http2StreamChannelBootstrap)

Example 5 with Http2StreamChannelBootstrap

use of io.netty.handler.codec.http2.Http2StreamChannelBootstrap in project ambry by linkedin.

the class MultiplexedChannelRecord method acquireClaimedStream.

void acquireClaimedStream(Promise<Channel> promise) {
    NettyUtils.doInEventLoop(parentChannel.eventLoop(), () -> {
        if (state != RecordState.OPEN) {
            String message;
            // GOAWAY
            if (state == RecordState.CLOSED_TO_NEW) {
                message = String.format("Connection %s received GOAWAY with Last Stream ID %d. Unable to open new " + "streams on this connection.", parentChannel, lastStreamId);
            } else {
                message = String.format("Connection %s was closed while acquiring new stream.", parentChannel);
            }
            log.warn(message);
            promise.setFailure(new IOException(message));
            return;
        }
        Future<Http2StreamChannel> streamFuture = new Http2StreamChannelBootstrap(parentChannel).handler(streamChannelInitializer).open();
        streamFuture.addListener((GenericFutureListener<Future<Http2StreamChannel>>) future -> {
            NettyUtils.warnIfNotInEventLoop(parentChannel.eventLoop());
            if (!future.isSuccess()) {
                promise.setFailure(future.cause());
                return;
            }
            Http2StreamChannel channel = future.getNow();
            streamChannels.put(channel.id(), channel);
            promise.setSuccess(channel);
            if (closeIfIdleTask == null && allowedIdleTimeInMs != null && allowedIdleTimeInMs > 0) {
                enableCloseIfIdleTask();
            }
        });
    }, promise);
}
Also used : Logger(org.slf4j.Logger) ChannelInitializer(io.netty.channel.ChannelInitializer) Promise(io.netty.util.concurrent.Promise) ScheduledFuture(io.netty.util.concurrent.ScheduledFuture) ChannelId(io.netty.channel.ChannelId) LoggerFactory(org.slf4j.LoggerFactory) GenericFutureListener(io.netty.util.concurrent.GenericFutureListener) IOException(java.io.IOException) HashMap(java.util.HashMap) Http2GoAwayFrame(io.netty.handler.codec.http2.Http2GoAwayFrame) ArrayList(java.util.ArrayList) NettyUtils(com.github.ambry.commons.NettyUtils) Channel(io.netty.channel.Channel) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) Http2StreamChannelBootstrap(io.netty.handler.codec.http2.Http2StreamChannelBootstrap) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Map(java.util.Map) ChannelOutboundInvoker(io.netty.channel.ChannelOutboundInvoker) Http2StreamChannel(io.netty.handler.codec.http2.Http2StreamChannel) Future(io.netty.util.concurrent.Future) Http2StreamChannelBootstrap(io.netty.handler.codec.http2.Http2StreamChannelBootstrap) ScheduledFuture(io.netty.util.concurrent.ScheduledFuture) Future(io.netty.util.concurrent.Future) IOException(java.io.IOException) Http2StreamChannel(io.netty.handler.codec.http2.Http2StreamChannel)

Aggregations

Channel (io.netty.channel.Channel)4 Http2StreamChannelBootstrap (io.netty.handler.codec.http2.Http2StreamChannelBootstrap)4 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)2 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)2 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)2 StreamException (io.netty.handler.codec.http2.Http2Exception.StreamException)2 Http2StreamChannel (io.netty.handler.codec.http2.Http2StreamChannel)2 Test (org.junit.Test)2 NettyUtils (com.github.ambry.commons.NettyUtils)1 Bootstrap (io.netty.bootstrap.Bootstrap)1 ChannelId (io.netty.channel.ChannelId)1 ChannelInitializer (io.netty.channel.ChannelInitializer)1 ChannelOutboundInvoker (io.netty.channel.ChannelOutboundInvoker)1 EventLoopGroup (io.netty.channel.EventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)1 DefaultHttp2Headers (io.netty.handler.codec.http2.DefaultHttp2Headers)1 DefaultHttp2HeadersFrame (io.netty.handler.codec.http2.DefaultHttp2HeadersFrame)1 Http2GoAwayFrame (io.netty.handler.codec.http2.Http2GoAwayFrame)1 Http2HeadersFrame (io.netty.handler.codec.http2.Http2HeadersFrame)1