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());
}
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);
}
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());
}
});
}
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();
}
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);
}
Aggregations