use of com.hotels.styx.client.BadHttpResponseException in project styx by ExpediaGroup.
the class NettyToStyxResponsePropagator method channelRead0.
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
FlowControllingHttpContentProducer producer = getContentProducer(ctx);
if (msg instanceof io.netty.handler.codec.http.HttpResponse) {
io.netty.handler.codec.http.HttpResponse nettyResponse = (io.netty.handler.codec.http.HttpResponse) msg;
if (!responseReceived.compareAndSet(false, true)) {
LOGGER.warn("Unexpected additional response received: " + nettyResponse);
ctx.channel().close();
return;
}
if (nettyResponse.getDecoderResult().isFailure()) {
emitResponseError(new BadHttpResponseException(origin, nettyResponse.getDecoderResult().cause()));
return;
}
ctx.channel().config().setAutoRead(false);
ctx.channel().read();
// Can be started with flow controlling disabled
EventLoop eventLoop = ctx.channel().eventLoop();
Publisher<Buffer> contentPublisher = new ContentPublisher(eventLoop, producer);
if ("close".equalsIgnoreCase(nettyResponse.headers().get(CONNECTION))) {
toBeClosed = true;
}
LiveHttpResponse response = toStyxResponse(nettyResponse, contentPublisher, origin);
this.sink.next(response);
}
if (msg instanceof HttpContent) {
ByteBuf content = ((ByteBufHolder) msg).content();
if (content.isReadable()) {
producer.newChunk(retain(content));
}
if (msg instanceof LastHttpContent) {
// Note: Netty may send a LastHttpContent as a response to TCP connection close.
// In this case channelReadComplete event will _not_ follow the LastHttpContent.
producer.lastHttpContent();
if (toBeClosed) {
ctx.channel().close();
}
}
}
}
use of com.hotels.styx.client.BadHttpResponseException in project styx by ExpediaGroup.
the class NettyToStyxResponsePropagatorTest method doesNotPropagateErrorsTwice.
@Test
public void doesNotPropagateErrorsTwice() throws Exception {
NettyToStyxResponsePropagator handler = new NettyToStyxResponsePropagator(responseSubscriber, SOME_ORIGIN);
EmbeddedChannel channel = new EmbeddedChannel(handler);
channel.writeInbound(httpResponseHeaders);
LiveHttpResponse response = verifyNextCalledOnResponseSubscriber();
StepVerifier.create(response.body()).then(// Execute onSubscribe in FSM
channel::runPendingTasks).then(// Will emit BadHttpResponseException
() -> channel.pipeline().fireExceptionCaught(new RuntimeException())).then(// Will emit TransportLostException
() -> channel.pipeline().fireChannelInactive()).expectError(BadHttpResponseException.class).verify();
verify(responseSubscriber, atMostOnce()).error(any());
}
use of com.hotels.styx.client.BadHttpResponseException in project styx by ExpediaGroup.
the class HttpErrorStatusMetricsTest method backendFaultArgs.
private static Stream<Arguments> backendFaultArgs() {
Id appId = Id.id("fakeApp");
Id originId = Id.id("fakeApp1");
Origin origin = Origin.newOriginBuilder("fakeHost", 9999).applicationId(appId).id(originId.toString()).build();
Exception cause = new Exception();
return Stream.of(Arguments.of(new NoAvailableHostsException(appId), "noHostsLiveForApplication"), Arguments.of(new OriginUnreachableException(origin, cause), "cannotConnect"), Arguments.of(new BadHttpResponseException(origin, cause), "badHttpResponse"), Arguments.of(new MaxPendingConnectionTimeoutException(origin, 1), "connectionsHeldTooLong"), Arguments.of(new MaxPendingConnectionsExceededException(origin, 1, 1), "tooManyConnections"), Arguments.of(new ResponseTimeoutException(origin, "test", 1, 1, 1, 1), "responseTooSlow"));
}
Aggregations