Search in sources :

Example 1 with BadRequestException

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());
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) BadRequestException(com.hotels.styx.server.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 2 with BadRequestException

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());
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) BadRequestException(com.hotels.styx.server.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 3 with BadRequestException

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());
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) BadRequestException(com.hotels.styx.server.BadRequestException) Test(org.junit.jupiter.api.Test)

Example 4 with BadRequestException

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);
    }
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) LiveHttpRequest(com.hotels.styx.api.LiveHttpRequest) BadRequestException(com.hotels.styx.server.BadRequestException) ByteBuf(io.netty.buffer.ByteBuf) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) HttpContent(io.netty.handler.codec.http.HttpContent) MalformedURLException(java.net.MalformedURLException) TooLongFrameException(io.netty.handler.codec.TooLongFrameException) BadRequestException(com.hotels.styx.server.BadRequestException)

Example 5 with BadRequestException

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());
}
Also used : DecoderException(io.netty.handler.codec.DecoderException) BadRequestException(com.hotels.styx.server.BadRequestException) Test(org.junit.jupiter.api.Test)

Aggregations

BadRequestException (com.hotels.styx.server.BadRequestException)5 DecoderException (io.netty.handler.codec.DecoderException)4 Test (org.junit.jupiter.api.Test)4 TooLongFrameException (io.netty.handler.codec.TooLongFrameException)3 LiveHttpRequest (com.hotels.styx.api.LiveHttpRequest)1 ByteBuf (io.netty.buffer.ByteBuf)1 HttpContent (io.netty.handler.codec.http.HttpContent)1 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 MalformedURLException (java.net.MalformedURLException)1