Search in sources :

Example 41 with HttpProcessingState

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;
}
Also used : HttpRequest(io.netty.handler.codec.http.HttpRequest) Endpoint(com.nike.riposte.server.http.Endpoint) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) RequestInfo(com.nike.riposte.server.http.RequestInfo)

Example 42 with HttpProcessingState

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;
}
Also used : LastOutboundMessage(com.nike.riposte.server.channelpipeline.message.LastOutboundMessage) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 43 with HttpProcessingState

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;
}
Also used : HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState)

Example 44 with HttpProcessingState

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;
}
Also used : HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState)

Example 45 with HttpProcessingState

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();
}
Also used : Attribute(io.netty.util.Attribute) Channel(io.netty.channel.Channel) HttpProcessingState(com.nike.riposte.server.http.HttpProcessingState) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ProxyRouterProcessingState(com.nike.riposte.server.http.ProxyRouterProcessingState) RequestInfo(com.nike.riposte.server.http.RequestInfo) Callable(java.util.concurrent.Callable) BiFunction(java.util.function.BiFunction) Function(java.util.function.Function) BiConsumer(java.util.function.BiConsumer) Consumer(java.util.function.Consumer) BiFunction(java.util.function.BiFunction) Supplier(java.util.function.Supplier) BiConsumer(java.util.function.BiConsumer) Before(org.junit.Before)

Aggregations

HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)54 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)22 Before (org.junit.Before)20 Channel (io.netty.channel.Channel)19 Attribute (io.netty.util.Attribute)19 RequestInfo (com.nike.riposte.server.http.RequestInfo)14 ResponseInfo (com.nike.riposte.server.http.ResponseInfo)11 Test (org.junit.Test)9 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)8 ErrorResponseBody (com.nike.riposte.server.error.handler.ErrorResponseBody)8 Endpoint (com.nike.riposte.server.http.Endpoint)6 ProxyRouterProcessingState (com.nike.riposte.server.http.ProxyRouterProcessingState)6 Span (com.nike.wingtips.Span)5 ChannelFuture (io.netty.channel.ChannelFuture)5 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)5 LastOutboundMessageSendFullResponseInfo (com.nike.riposte.server.channelpipeline.message.LastOutboundMessageSendFullResponseInfo)4 IncompleteHttpCallTimeoutException (com.nike.riposte.server.error.exception.IncompleteHttpCallTimeoutException)4 TooManyOpenChannelsException (com.nike.riposte.server.error.exception.TooManyOpenChannelsException)4 RequestAndResponseFilter (com.nike.riposte.server.http.filter.RequestAndResponseFilter)4 HttpRequest (io.netty.handler.codec.http.HttpRequest)4