use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class BackendServicesRouterTest method doesNotMatchRequestIfFinalSlashIsMissing.
@Test
public void doesNotMatchRequestIfFinalSlashIsMissing() {
BackendServicesRouter router = new BackendServicesRouter(serviceClientFactory, environment, executor);
router.onChange(added(appB().newCopy().path("/appB/hotel/details.html").build()));
LiveHttpRequest request = get("/ba/").build();
Optional<HttpHandler> route = router.route(request, context);
assertThat(route, is(Optional.empty()));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpErrorStatusCauseLoggerTest method logsInternalServerErrorWithRequest.
@Test
public void logsInternalServerErrorWithRequest() {
LiveHttpRequest request = LiveHttpRequest.get("/foo").build();
Exception exception = new Exception("This is just a test");
httpErrorStatusCauseLogger.proxyErrorOccurred(request, InetSocketAddress.createUnresolved("localhost", 80), INTERNAL_SERVER_ERROR, exception);
assertThat(loggingTestSupport.log(), hasItem(loggingEvent(ERROR, "Failure status=\"500 Internal Server Error\" during request=" + FORMATTED_REQUEST + ", clientAddress=localhost:80", "java.lang.Exception", "This is just a test")));
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class PathPrefixRouterTest method testRequestRoute.
private void testRequestRoute(PathPrefixRouter router, String path, RoutingObject handler) {
LiveHttpRequest request = LiveHttpRequest.get(path).build();
router.handle(request, context);
verify(handler).handle(request, context);
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class NettyToStyxRequestDecoder method decode.
@Override
protected void decode(ChannelHandlerContext ctx, HttpObject httpObject, List<Object> out) throws Exception {
if (httpObject.getDecoderResult().isFailure()) {
String formattedHttpObject = httpMessageFormatter.formatNettyMessage(httpObject);
throw new BadRequestException("Error while decoding request: " + formattedHttpObject, httpMessageFormatter.wrap(httpObject.getDecoderResult().cause()));
}
try {
if (httpObject instanceof HttpRequest) {
this.producer = new FlowControllingHttpContentProducer(ctx, this.flowControlEnabled);
Observable<ByteBuf> contentObservable = Observable.create(contentSubscriber -> {
contentSubscriber.setProducer(this.producer);
this.producer.subscriptionStart(contentSubscriber);
});
HttpRequest request = (HttpRequest) httpObject;
LiveHttpRequest styxRequest = toStyxRequest(request, contentObservable);
out.add(styxRequest);
} else if (httpObject instanceof HttpContent && this.producer != null) {
this.producer.onNext(content(httpObject));
if (httpObject instanceof LastHttpContent) {
this.producer.onCompleted();
}
}
} catch (BadRequestException ex) {
throw ex;
} catch (Exception ex) {
throw new BadRequestException(ex.getMessage() + " in " + httpObject, ex);
}
}
use of com.hotels.styx.api.LiveHttpRequest in project styx by ExpediaGroup.
the class HttpPipelineHandler method onLegitimateRequest.
private State onLegitimateRequest(LiveHttpRequest request, ChannelHandlerContext ctx) {
statsSink.onRequest(request.id());
LiveHttpRequest v11Request = request.newBuilder().version(HTTP_1_1).build();
tracker.trackRequest(request, () -> this.state().toString());
ongoingRequest = request;
// generates a response.
try {
Eventual<LiveHttpResponse> responseEventual = httpPipeline.handle(v11Request, new HttpInterceptorContext(this.secure, remoteAddress(ctx), ctx.executor()));
responseEventual.subscribe(new BaseSubscriber<LiveHttpResponse>() {
@Override
public void hookOnSubscribe(Subscription s) {
subscription = s;
s.request(1);
}
@Override
public void hookOnComplete() {
eventProcessor.submit(new ResponseObservableCompletedEvent(ctx, request.id()));
}
@Override
public void hookOnError(Throwable cause) {
eventProcessor.submit(new ResponseObservableErrorEvent(ctx, cause, request.id()));
}
@Override
public void hookOnNext(LiveHttpResponse response) {
eventProcessor.submit(new ResponseReceivedEvent(response, ctx));
}
});
return WAITING_FOR_RESPONSE;
} catch (Throwable cause) {
LiveHttpResponse response = exceptionToResponse(cause, request, originsHeaderName);
httpErrorStatusListener.proxyErrorOccurred(request, remoteAddress(ctx), response.status(), cause);
statsSink.onTerminate(request.id());
tracker.endTrack(ongoingRequest);
if (ctx.channel().isActive()) {
respondAndClose(ctx, response);
}
return TERMINATED;
}
}
Aggregations