use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.
the class RoutingHandler method doChannelRead.
@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) {
if (msg instanceof HttpRequest) {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
RequestInfo request = state.getRequestInfo();
Pair<Endpoint<?>, String> endpointForExecution = findSingleEndpointForExecution(request);
throwExceptionIfContentLengthHeaderIsLargerThanConfiguredMaxRequestSize((HttpRequest) msg, endpointForExecution.getLeft());
request.setPathParamsBasedOnPathTemplate(endpointForExecution.getRight());
state.setEndpointForExecution(endpointForExecution.getLeft(), endpointForExecution.getRight());
}
return PipelineContinuationBehavior.CONTINUE;
}
use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandler method doChannelRead.
@Override
public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
if (msg instanceof LastOutboundMessage) {
Exception ex = new Exception("Manually created exception to be used for diagnostic stack trace");
HttpProcessingState state = getStateAndCreateIfNeeded(ctx, ex);
finalizeChannelPipeline(ctx, msg, state, ex);
}
return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT;
}
use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.
the class ChannelPipelineFinalizerHandler method doExceptionCaught.
@Override
public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
HttpProcessingState state = getStateAndCreateIfNeeded(ctx, cause);
finalizeChannelPipeline(ctx, null, state, cause);
return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT;
}
use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.
the class ExceptionHandlingHandler method getStateAndCreateIfNeeded.
protected HttpProcessingState getStateAndCreateIfNeeded(ChannelHandlerContext ctx, Throwable cause) {
HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get();
if (state == null) {
// The error must have occurred before RequestStateCleanerHandler could even execute. Create a new state and
// put it into the channel so that we can populate the ResponseInfo for our response sender.
logger.error("No HttpProcessingState was available. This means the error occurred before RequestStateCleanerHandler " + "could execute.", cause);
state = new HttpProcessingState();
ctx.channel().attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY).set(state);
}
return state;
}
use of com.nike.riposte.server.http.HttpProcessingState in project riposte by Nike-Inc.
the class AsyncNettyHelperTest method beforeMethod.
@Before
public void beforeMethod() {
channelMock = mock(Channel.class);
ctxMock = mock(ChannelHandlerContext.class);
stateAttributeMock = mock(Attribute.class);
proxyRouterStateAttrMock = mock(Attribute.class);
state = new HttpProcessingState();
proxyRouterStateMock = mock(ProxyRouterProcessingState.class);
requestInfoMock = mock(RequestInfo.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(state).when(stateAttributeMock).get();
doReturn(proxyRouterStateAttrMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(proxyRouterStateMock).when(proxyRouterStateAttrMock).get();
state.setRequestInfo(requestInfoMock);
runnableMock = mock(Runnable.class);
callableMock = mock(Callable.class);
supplierMock = mock(Supplier.class);
functionMock = mock(Function.class);
biFunctionMock = mock(BiFunction.class);
consumerMock = mock(Consumer.class);
biConsumerMock = mock(BiConsumer.class);
currentSpanStackWhenRequestResourcesReleased = new ArrayList<>();
currentMdcInfoWhenRequestResourcesReleased = new ArrayList<>();
doAnswer(invocation -> {
currentSpanStackWhenRequestResourcesReleased.add(Tracer.getInstance().getCurrentSpanStackCopy());
currentMdcInfoWhenRequestResourcesReleased.add(MDC.getCopyOfContextMap());
return null;
}).when(requestInfoMock).releaseAllResources();
resetTracingAndMdc();
}
Aggregations