use of com.hotels.styx.api.exceptions.TransportLostException in project styx by ExpediaGroup.
the class HttpRequestOperation method execute.
public Flux<LiveHttpResponse> execute(NettyConnection nettyConnection) {
AtomicReference<RequestBodyChunkSubscriber> requestRequestBodyChunkSubscriber = new AtomicReference<>();
requestTime = System.currentTimeMillis();
executeCount.incrementAndGet();
Flux<LiveHttpResponse> responseFlux = Flux.create(sink -> {
if (nettyConnection.isConnected()) {
RequestBodyChunkSubscriber bodyChunkSubscriber = new RequestBodyChunkSubscriber(request, nettyConnection);
requestRequestBodyChunkSubscriber.set(bodyChunkSubscriber);
addProxyBridgeHandlers(nettyConnection, sink);
new WriteRequestToOrigin(sink, nettyConnection, request, bodyChunkSubscriber).write();
if (requestLoggingEnabled) {
httpRequestMessageLogger.logRequest(request, nettyConnection.getOrigin());
}
} else {
sink.error(new TransportLostException(nettyConnection.channel(), nettyConnection.getOrigin()));
}
});
if (requestLoggingEnabled) {
responseFlux = responseFlux.doOnNext(response -> {
httpRequestMessageLogger.logResponse(request, response);
});
}
return responseFlux.map(response -> Requests.doFinally(response, cause -> {
if (nettyConnection.isConnected()) {
removeProxyBridgeHandlers(nettyConnection);
if (requestIsOngoing(requestRequestBodyChunkSubscriber.get())) {
LOGGER.warn("Origin responded too quickly to an ongoing request, or it was cancelled. Connection={}, Request={}.", new Object[] { nettyConnection.channel(), this.request });
nettyConnection.close();
}
}
}));
}
use of com.hotels.styx.api.exceptions.TransportLostException in project styx by ExpediaGroup.
the class NettyToStyxResponsePropagator method channelInactive.
@Override
public void channelInactive(ChannelHandlerContext ctx) {
TransportLostException cause = new TransportLostException(ctx.channel().remoteAddress(), origin);
getContentProducer(ctx).channelInactive(cause);
}
use of com.hotels.styx.api.exceptions.TransportLostException in project styx by ExpediaGroup.
the class HttpResponseWriterTest method logsSentAndAcknowledgedBytes.
@Test
public void logsSentAndAcknowledgedBytes() {
EmbeddedChannel ch = new EmbeddedChannel(new SimpleChannelInboundHandler<LiveHttpResponse>() {
@Override
protected void channelRead0(ChannelHandlerContext ctx, LiveHttpResponse response) throws Exception {
HttpResponseWriter writer = new HttpResponseWriter(ctx);
CompletableFuture<Void> future = writer.write(response);
assertThat(future.isDone(), is(false));
contentObservable.onNext(new Buffer("aaa", UTF_8));
assertThat(future.isDone(), is(false));
contentObservable.onNext(new Buffer("bbbb", UTF_8));
assertThat(future.isDone(), is(false));
contentObservable.onError(new TransportLostException(new InetSocketAddress(getLoopbackAddress(), 5050), newOriginBuilder("localhost", 5050).build()));
assertThat(future.isDone(), is(true));
channelRead.set(true);
}
});
ch.writeInbound(response(OK).body(new ByteStream(contentObservable)).build());
assertThat(LOGGER.lastMessage(), is(loggingEvent(Level.WARN, "Content observable error. Written content bytes 7/7 \\(ackd/sent\\). Write events 3/3 \\(ackd/writes\\).*", TransportLostException.class, "Connection to origin lost. origin=\"generic-app:anonymous-origin:localhost:5050\", remoteAddress=\"localhost/127.0.0.1:5050.*")));
}
Aggregations