use of software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse 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 software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse in project aws-sdk-java-v2 by aws.
the class ResponseHandler method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext channelContext, HttpObject msg) throws Exception {
RequestContext requestContext = channelContext.channel().attr(REQUEST_CONTEXT_KEY).get();
if (msg instanceof HttpResponse) {
HttpResponse response = (HttpResponse) msg;
SdkHttpResponse sdkResponse = SdkHttpFullResponse.builder().headers(fromNettyHeaders(response.headers())).statusCode(response.status().code()).statusText(response.status().reasonPhrase()).build();
channelContext.channel().attr(RESPONSE_STATUS_CODE).set(response.status().code());
channelContext.channel().attr(RESPONSE_CONTENT_LENGTH).set(responseContentLength(response));
channelContext.channel().attr(KEEP_ALIVE).set(shouldKeepAlive(response));
requestContext.handler().onHeaders(sdkResponse);
}
CompletableFuture<Void> ef = executeFuture(channelContext);
if (msg instanceof StreamedHttpResponse) {
requestContext.handler().onStream(new DataCountingPublisher(channelContext, new PublisherAdapter((StreamedHttpResponse) msg, channelContext, requestContext, ef)));
} else if (msg instanceof FullHttpResponse) {
ByteBuf fullContent = null;
try {
// Be prepared to take care of (ignore) a trailing LastHttpResponse
// from the HttpClientCodec if there is one.
channelContext.pipeline().replace(HttpStreamsClientHandler.class, channelContext.name() + "-LastHttpContentSwallower", LastHttpContentSwallower.getInstance());
fullContent = ((FullHttpResponse) msg).content();
ByteBuffer bb = copyToByteBuffer(fullContent);
requestContext.handler().onStream(new DataCountingPublisher(channelContext, new FullResponseContentPublisher(channelContext, bb, ef)));
try {
validateResponseContentLength(channelContext);
finalizeResponse(requestContext, channelContext);
} catch (IOException e) {
exceptionCaught(channelContext, e);
}
} finally {
Optional.ofNullable(fullContent).ifPresent(ByteBuf::release);
}
}
}
use of software.amazon.awssdk.http.nio.netty.internal.nrs.StreamedHttpResponse in project aws-sdk-java-v2 by aws.
the class PublisherAdapterTest method successfulStreaming_shouldNotInvokeChannelRead.
@Test
public void successfulStreaming_shouldNotInvokeChannelRead() {
Flowable<HttpContent> testPublisher = Flowable.just(fullHttpResponse);
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, times(0)).close();
assertThat(subscriber.isCompleted).isEqualTo(true);
verify(channelPool).release(channel);
executeFuture.join();
assertThat(executeFuture).isCompleted();
}
Aggregations