Search in sources :

Example 1 with OutboundMessage

use of com.nike.riposte.server.channelpipeline.message.OutboundMessage in project riposte by Nike-Inc.

the class ResponseFilterHandlerTest method doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_a_first_chunk.

@Test
public void doChannelRead_does_nothing_and_returns_CONTINUE_if_msg_is_not_a_first_chunk() throws Exception {
    // given
    Object msg = new OutboundMessage() {
    };
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    verify(handlerSpy, never()).executeResponseFilters(any());
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) OutboundMessage(com.nike.riposte.server.channelpipeline.message.OutboundMessage) Test(org.junit.Test)

Example 2 with OutboundMessage

use of com.nike.riposte.server.channelpipeline.message.OutboundMessage in project riposte by Nike-Inc.

the class ResponseFilterHandlerTest method doChannelRead_delegates_to_executeResponseFilters_and_returns_CONTINUE_if_msg_is_first_chunk_of_response.

@DataProvider(value = { "true", "false" }, splitBy = "\\|")
@Test
public void doChannelRead_delegates_to_executeResponseFilters_and_returns_CONTINUE_if_msg_is_first_chunk_of_response(boolean chunkedResponse) throws Exception {
    // given
    OutboundMessage msg = (chunkedResponse) ? mock(OutboundMessageSendHeadersChunkFromResponseInfo.class) : mock(LastOutboundMessageSendFullResponseInfo.class);
    doNothing().when(handlerSpy).executeResponseFilters(any());
    // when
    PipelineContinuationBehavior result = handlerSpy.doChannelRead(ctxMock, msg);
    // then
    assertThat(result).isEqualTo(CONTINUE);
    verify(handlerSpy).executeResponseFilters(ctxMock);
}
Also used : PipelineContinuationBehavior(com.nike.riposte.server.handler.base.PipelineContinuationBehavior) OutboundMessageSendHeadersChunkFromResponseInfo(com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo) OutboundMessage(com.nike.riposte.server.channelpipeline.message.OutboundMessage) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo) DataProvider(com.tngtech.java.junit.dataprovider.DataProvider) Test(org.junit.Test)

Example 3 with OutboundMessage

use of com.nike.riposte.server.channelpipeline.message.OutboundMessage in project riposte by Nike-Inc.

the class RequestHasBeenHandledVerificationHandler method doChannelRead.

@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
    if (msg == null) {
        throw new InvalidRipostePipelineException("msg cannot be null at this stage of the pipeline. An endpoint handler should have fired a valid " + "OutboundMessage. invalid_riposte_pipeline=true");
    }
    if (!(msg instanceof OutboundMessage)) {
        throw new InvalidRipostePipelineException("Expected msg to be a OutboundMessage, but instead found: " + msg.getClass().getName() + ". invalid_riposte_pipeline=true");
    }
    HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
    if (state == null) {
        throw new InvalidRipostePipelineException("Found null HttpProcessingState in the channel, which is not allowed at this point. " + "invalid_riposte_pipeline=true");
    }
    ResponseInfo<?> responseInfo = state.getResponseInfo();
    if (responseInfo == null) {
        throw new InvalidRipostePipelineException("Found null ResponseInfo in the channel state, which is not allowed at this point. " + "An endpoint handler should have set a ResponseInfo on the state. invalid_riposte_pipeline=true");
    }
    if (responseInfo.isChunkedResponse() && !(msg instanceof ChunkedOutboundMessage)) {
        throw new InvalidRipostePipelineException("ResponseInfo.isChunkedResponse() indicates a chunked response, but the message was not a " + "ChunkedOutboundMessage. msg_type=" + msg.getClass().getName() + ", invalid_riposte_pipeline=true");
    }
    if (!responseInfo.isChunkedResponse() && !(msg instanceof LastOutboundMessageSendFullResponseInfo)) {
        throw new InvalidRipostePipelineException("ResponseInfo.isChunkedResponse() indicates a full response, but the message was not a " + "LastOutboundMessageSendFullResponseInfo. msg_type=" + msg.getClass().getName() + ", invalid_riposte_pipeline=true");
    }
    return CONTINUE;
}
Also used : HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChunkedOutboundMessage(com.nike.riposte.server.channelpipeline.message.ChunkedOutboundMessage) OutboundMessage(com.nike.riposte.server.channelpipeline.message.OutboundMessage) InvalidRipostePipelineException(com.nike.riposte.server.error.exception.InvalidRipostePipelineException) ChunkedOutboundMessage(com.nike.riposte.server.channelpipeline.message.ChunkedOutboundMessage) LastOutboundMessageSendFullResponseInfo(com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)

Aggregations

OutboundMessage (com.nike.riposte.server.channelpipeline.message.OutboundMessage)3 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)2 PipelineContinuationBehavior (com.nike.riposte.server.handler.base.PipelineContinuationBehavior)2 Test (org.junit.Test)2 ChunkedOutboundMessage (com.nike.riposte.server.channelpipeline.message.ChunkedOutboundMessage)1 OutboundMessageSendHeadersChunkFromResponseInfo (com.nike.riposte.server.channelpipeline.message.OutboundMessageSendHeadersChunkFromResponseInfo)1 InvalidRipostePipelineException (com.nike.riposte.server.error.exception.InvalidRipostePipelineException)1 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)1 DataProvider (com.tngtech.java.junit.dataprovider.DataProvider)1