use of com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpResponse in project couchbase-jvm-clients by couchbase.
the class NonChunkedHttpMessageHandler method channelRead.
/**
* Parses the full http response and sends it to decode into the request.
*
* @param ctx the channel handler context.
* @param msg the FullHttpResponse from the server.
*/
@Override
public void channelRead(final ChannelHandlerContext ctx, final Object msg) {
try {
if (msg instanceof FullHttpResponse) {
try {
currentRequest.context().dispatchLatency(System.nanoTime() - dispatchTimingStart);
if (currentDispatchSpan != null) {
currentDispatchSpan.end();
}
FullHttpResponse httpResponse = (FullHttpResponse) msg;
ResponseStatus responseStatus = HttpProtocol.decodeStatus(httpResponse.status());
if (!currentRequest.completed()) {
if (responseStatus == ResponseStatus.SUCCESS) {
Response response = currentRequest.decode(httpResponse, channelContext);
currentRequest.succeed(response);
} else {
String body = httpResponse.content().toString(StandardCharsets.UTF_8);
Exception error = currentRequest.bypassExceptionTranslation() ? failRequestWithHttpStatusCodeException(httpResponse.status(), body, currentRequest) : failRequestWith(httpResponse.status(), body, currentRequest);
currentRequest.fail(error);
}
} else {
ioContext.environment().orphanReporter().report(currentRequest);
}
} catch (Throwable ex) {
currentRequest.fail(ex);
} finally {
currentRequest = null;
currentDispatchSpan = null;
endpoint.markRequestCompletion();
}
} else {
ioContext.environment().eventBus().publish(new UnsupportedResponseTypeReceivedEvent(ioContext, msg));
closeChannelWithReason(ioContext, ctx, ChannelClosedProactivelyEvent.Reason.INVALID_RESPONSE_FORMAT_DETECTED);
}
} finally {
ReferenceCountUtil.release(msg);
}
}
use of com.couchbase.client.core.deps.io.netty.handler.codec.http.FullHttpResponse in project couchbase-jvm-clients by couchbase.
the class NonChunkedHttpMessageHandlerTest method callsMarkRequestCompletedOnceFinished.
@Test
void callsMarkRequestCompletedOnceFinished() throws Exception {
channel.pipeline().addFirst(NonChunkedHttpMessageHandler.IDENTIFIER, new TestNonChunkedHttpMessageHandler(endpoint));
channel.pipeline().fireChannelActive();
CoreHttpRequest request = CoreHttpRequest.builder(CoreCommonOptions.of(Duration.ofSeconds(1), BestEffortRetryStrategy.INSTANCE, null), endpoint.context(), HttpMethod.GET, CoreHttpPath.path("/"), RequestTarget.views("bucket")).build();
channel.writeAndFlush(request);
FullHttpRequest written = channel.readOutbound();
assertEquals("/", written.uri());
FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
channel.writeInbound(response);
assertEquals(ResponseStatus.SUCCESS, request.response().get().status());
verify(endpoint, times(1)).markRequestCompletion();
}
Aggregations