use of io.netty.handler.codec.http.HttpContent in project aws-sdk-java-v2 by aws.
the class LastHttpContentSwallowerTest method testOtherHttpObjectRead_doesNotSwallowObject.
@Test
public void testOtherHttpObjectRead_doesNotSwallowObject() {
HttpContent content = mock(HttpContent.class);
lastHttpContentSwallower.channelRead0(mockCtx, content);
verify(mockCtx).fireChannelRead(eq(content));
}
use of io.netty.handler.codec.http.HttpContent in project aws-sdk-java-v2 by aws.
the class PublisherAdapterTest method errorOccurred_shouldInvokeResponseHandler.
@Test
public void errorOccurred_shouldInvokeResponseHandler() {
RuntimeException exception = new RuntimeException("boom");
Flowable<HttpContent> testPublisher = Flowable.error(exception);
StreamedHttpResponse streamedHttpResponse = new DefaultStreamedHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.ACCEPTED, testPublisher);
ResponseHandler.PublisherAdapter publisherAdapter = new ResponseHandler.PublisherAdapter(streamedHttpResponse, ctx, requestContext, executeFuture);
TestSubscriber subscriber = new TestSubscriber();
publisherAdapter.subscribe(subscriber);
verify(ctx, times(0)).read();
verify(ctx).close();
assertThat(subscriber.errorOccurred).isEqualTo(true);
verify(channelPool).release(channel);
assertThat(executeFuture).isCompletedExceptionally();
verify(responseHandler).onError(exception);
}
use of io.netty.handler.codec.http.HttpContent in project aws-sdk-java-v2 by aws.
the class HttpToHttp2OutboundAdapter method write.
/**
* Handles conversion of {@link HttpMessage} and {@link HttpContent} to HTTP/2 frames.
*/
@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) {
if (!(msg instanceof HttpMessage || msg instanceof HttpContent)) {
ctx.write(msg, promise);
return;
}
boolean release = true;
SimpleChannelPromiseAggregator promiseAggregator = new SimpleChannelPromiseAggregator(promise, ctx.channel(), ctx.executor());
try {
boolean endStream = false;
if (msg instanceof HttpMessage) {
HttpMessage httpMsg = (HttpMessage) msg;
// Convert and write the headers.
Http2Headers http2Headers = HttpConversionUtil.toHttp2Headers(httpMsg, false);
endStream = msg instanceof FullHttpMessage && !((FullHttpMessage) msg).content().isReadable();
ctx.write(new DefaultHttp2HeadersFrame(http2Headers), promiseAggregator.newPromise());
}
if (!endStream && msg instanceof HttpContent) {
boolean isLastContent = false;
HttpHeaders trailers = EmptyHttpHeaders.INSTANCE;
Http2Headers http2Trailers = EmptyHttp2Headers.INSTANCE;
if (msg instanceof LastHttpContent) {
isLastContent = true;
// Convert any trailing headers.
LastHttpContent lastContent = (LastHttpContent) msg;
trailers = lastContent.trailingHeaders();
http2Trailers = HttpConversionUtil.toHttp2Headers(trailers, false);
}
// Write the data
ByteBuf content = ((HttpContent) msg).content();
endStream = isLastContent && trailers.isEmpty();
release = false;
ctx.write(new DefaultHttp2DataFrame(content, endStream), promiseAggregator.newPromise());
if (!trailers.isEmpty()) {
// Write trailing headers.
ctx.write(new DefaultHttp2HeadersFrame(http2Trailers, true), promiseAggregator.newPromise());
}
ctx.flush();
}
} catch (Throwable t) {
promiseAggregator.setFailure(t);
} finally {
if (release) {
ReferenceCountUtil.release(msg);
}
promiseAggregator.doneAllocatingPromises();
}
}
use of io.netty.handler.codec.http.HttpContent in project aws-sdk-java-v2 by aws.
the class HttpStreamsHandler method unbufferedWrite.
protected void unbufferedWrite(final ChannelHandlerContext ctx, final Outgoing out) {
if (out.message instanceof FullHttpMessage) {
// Forward as is
ctx.writeAndFlush(out.message, out.promise);
out.promise.addListener(new ChannelFutureListener() {
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
executeInEventLoop(ctx, new Runnable() {
@Override
public void run() {
sentOutMessage(ctx);
outgoing.remove();
flushNext(ctx);
}
});
}
});
} else if (out.message instanceof StreamedHttpMessage) {
StreamedHttpMessage streamed = (StreamedHttpMessage) out.message;
HandlerSubscriber<HttpContent> subscriber = new HandlerSubscriber<HttpContent>(ctx.executor()) {
@Override
protected void error(Throwable error) {
out.promise.tryFailure(error);
ctx.close();
}
@Override
protected void complete() {
executeInEventLoop(ctx, new Runnable() {
@Override
public void run() {
completeBody(ctx);
}
});
}
};
sendLastHttpContent = true;
// DON'T pass the promise through, create a new promise instead.
ctx.writeAndFlush(out.message);
ctx.pipeline().addAfter(ctx.name(), ctx.name() + "-body-subscriber", subscriber);
subscribeSubscriberToStream(streamed, subscriber);
}
}
use of io.netty.handler.codec.http.HttpContent in project aws-sdk-java-v2 by aws.
the class HttpStreamsClientHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof HttpResponse && awaiting100Continue != null && withServer == 0) {
HttpResponse response = (HttpResponse) msg;
if (response.status().equals(HttpResponseStatus.CONTINUE)) {
super.subscribeSubscriberToStream(awaiting100ContinueMessage, awaiting100Continue);
awaiting100Continue = null;
awaiting100ContinueMessage = null;
if (msg instanceof FullHttpResponse) {
ReferenceCountUtil.release(msg);
} else {
ignoreResponseBody = true;
}
} else {
awaiting100ContinueMessage.subscribe(new CancelledSubscriber<HttpContent>());
awaiting100ContinueMessage = null;
awaiting100Continue.onSubscribe(new NoOpSubscription());
awaiting100Continue.onComplete();
awaiting100Continue = null;
super.channelRead(ctx, msg);
}
} else if (ignoreResponseBody && msg instanceof HttpContent) {
ReferenceCountUtil.release(msg);
if (msg instanceof LastHttpContent) {
ignoreResponseBody = false;
}
} else {
super.channelRead(ctx, msg);
}
}
Aggregations