@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" throw new InvalidRipostePipelineException( "Expected msg to be a OutboundMessage, but instead found: " + msg.getClass().getName() + ". invalid_riposte_pipeline=true" throw new InvalidRipostePipelineException( "Found null HttpProcessingState in the channel, which is not allowed at this point. " + "invalid_riposte_pipeline=true" 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" 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" throw new InvalidRipostePipelineException( "ResponseInfo.isChunkedResponse() indicates a full response, but the message was not a " + "LastOutboundMessageSendFullResponseInfo. msg_type=" + msg.getClass().getName()
@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" throw new InvalidRipostePipelineException( "Expected msg to be a OutboundMessage, but instead found: " + msg.getClass().getName() + ". invalid_riposte_pipeline=true" throw new InvalidRipostePipelineException( "Found null HttpProcessingState in the channel, which is not allowed at this point. " + "invalid_riposte_pipeline=true" 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" 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" throw new InvalidRipostePipelineException( "ResponseInfo.isChunkedResponse() indicates a full response, but the message was not a " + "LastOutboundMessageSendFullResponseInfo. msg_type=" + msg.getClass().getName()
@Test public void cause_constructor_works() { // given Throwable cause = new Exception("kaboom"); // when InvalidRipostePipelineException ex = new InvalidRipostePipelineException(cause); // then assertThat(ex).hasMessage(cause.toString()).hasCause(cause); }
@Test public void message_and_cause_constructor_works() { // given Throwable cause = new Exception("kaboom"); // when InvalidRipostePipelineException ex = new InvalidRipostePipelineException("foo", cause); // then assertThat(ex).hasMessage("foo").hasCause(cause); } }
@Test public void zero_arg_constructor_works() { // when InvalidRipostePipelineException ex = new InvalidRipostePipelineException(); // then assertThat(ex).hasMessage(null).hasCause(null); }
@Test public void message_constructor_works() { // when InvalidRipostePipelineException ex = new InvalidRipostePipelineException("foo"); // then assertThat(ex).hasMessage("foo").hasCause(null); }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { // We expect to be here for normal message processing, but only as a pass-through. If the state indicates that // the request was not handled then that's a pipeline misconfiguration and we need to throw an error. HttpProcessingState state = getStateAndCreateIfNeeded(ctx, null); if (!state.isRequestHandled()) { runnableWithTracingAndMdc(() -> { String errorMsg = "In ExceptionHandlingHandler's channelRead method, but the request has not yet been " + "handled. This should not be possible and indicates the pipeline is not set up " + "properly or some unknown and unexpected error state was triggered. Sending " + "unhandled error response"; logger.error(errorMsg); Exception ex = new InvalidRipostePipelineException(errorMsg); ResponseInfo<ErrorResponseBody> responseInfo = processUnhandledError(state, msg, ex); state.setResponseInfo(responseInfo, ex); addErrorAnnotationToOverallRequestSpan(state, responseInfo, ex); }, ctx).run(); } return PipelineContinuationBehavior.CONTINUE; }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) { // We expect to be here for normal message processing, but only as a pass-through. If the state indicates that // the request was not handled then that's a pipeline misconfiguration and we need to throw an error. HttpProcessingState state = getStateAndCreateIfNeeded(ctx, null); if (!state.isRequestHandled()) { runnableWithTracingAndMdc(() -> { String errorMsg = "In ExceptionHandlingHandler's channelRead method, but the request has not yet been " + "handled. This should not be possible and indicates the pipeline is not set up " + "properly or some unknown and unexpected error state was triggered. Sending " + "unhandled error response"; logger.error(errorMsg); Exception ex = new InvalidRipostePipelineException(errorMsg); ResponseInfo<ErrorResponseBody> responseInfo = processUnhandledError(state, msg, ex); state.setResponseInfo(responseInfo, ex); addErrorAnnotationToOverallRequestSpan(state, responseInfo, ex); }, ctx).run(); } return PipelineContinuationBehavior.CONTINUE; }