use of com.hotels.styx.server.BadRequestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method tooLongFrameExceptionOccursInIdleStateAndTcpConnectionRemainsActive.
@Test
public void tooLongFrameExceptionOccursInIdleStateAndTcpConnectionRemainsActive() throws Exception {
setupHandlerTo(WAITING_FOR_RESPONSE);
RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new TooLongFrameException("too long frame")));
handler.exceptionCaught(ctx, cause);
verify(errorListener).proxyErrorOccurred(REQUEST_ENTITY_TOO_LARGE, cause);
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
verify(responseWriter).write(response(REQUEST_ENTITY_TOO_LARGE).header(CONTENT_LENGTH, 24).header(CONNECTION, "close").build());
}
use of com.hotels.styx.server.BadRequestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method badRequestExceptionExceptionOccursInIdleStateAndTcpConnectionRemainsActive.
@Test
public void badRequestExceptionExceptionOccursInIdleStateAndTcpConnectionRemainsActive() throws Exception {
setupHandlerTo(WAITING_FOR_RESPONSE);
RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new RuntimeException("random bad request failure")));
handler.exceptionCaught(ctx, cause);
verify(errorListener).proxyErrorOccurred(BAD_REQUEST, cause);
verify(responseEnhancer).enhance(any(LiveHttpResponse.Transformer.class), eq(request));
verify(responseWriter).write(response(BAD_REQUEST).header(CONTENT_LENGTH, 11).header(CONNECTION, "close").build());
}
use of com.hotels.styx.server.BadRequestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method tooLongFrameExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive.
@Test
public void tooLongFrameExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive() throws Exception {
setupHandlerTo(WAITING_FOR_RESPONSE);
RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new TooLongFrameException("too long frame")));
handler.exceptionCaught(ctx, cause);
verify(errorListener).proxyErrorOccurred(REQUEST_ENTITY_TOO_LARGE, cause);
responseWriter.write(response(REQUEST_ENTITY_TOO_LARGE).build());
}
use of com.hotels.styx.server.BadRequestException 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.server.BadRequestException in project styx by ExpediaGroup.
the class HttpPipelineHandlerTest method badRequestExceptionExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive.
@Test
public void badRequestExceptionExceptionOccursInWaitingForResponseStateAndTcpConnectionRemainsActive() throws Exception {
setupHandlerTo(WAITING_FOR_RESPONSE);
RuntimeException cause = new DecoderException("timeout occurred", new BadRequestException("bad request", new RuntimeException("random bad request failure")));
handler.exceptionCaught(ctx, cause);
verify(errorListener).proxyErrorOccurred(BAD_REQUEST, cause);
responseWriter.write(response(BAD_REQUEST).build());
}
Aggregations