use of com.nike.riposte.server.http.ProxyRouterProcessingState in project riposte by Nike-Inc.
the class ExceptionHandlingHandlerTest method beforeMethod.
@Before
public void beforeMethod() {
riposteErrorHandlerMock = mock(RiposteErrorHandler.class);
riposteUnhandledErrorHandlerMock = mock(RiposteUnhandledErrorHandler.class);
distributedTracingConfigMock = mock(DistributedTracingConfig.class);
serverSpanNamingAndTaggingStrategyMock = mock(ServerSpanNamingAndTaggingStrategy.class);
doReturn(serverSpanNamingAndTaggingStrategyMock).when(distributedTracingConfigMock).getServerSpanNamingAndTaggingStrategy();
handler = new ExceptionHandlingHandler(riposteErrorHandlerMock, riposteUnhandledErrorHandlerMock, distributedTracingConfigMock);
channelMock = mock(Channel.class);
ctxMock = mock(ChannelHandlerContext.class);
stateAttributeMock = mock(Attribute.class);
proxyRouterStateAttributeMock = mock(Attribute.class);
state = new HttpProcessingState();
proxyRouterStateSpy = spy(new ProxyRouterProcessingState());
doReturn(channelMock).when(ctxMock).channel();
doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(state).when(stateAttributeMock).get();
doReturn(proxyRouterStateAttributeMock).when(channelMock).attr(ChannelAttributes.PROXY_ROUTER_PROCESSING_STATE_ATTRIBUTE_KEY);
doReturn(proxyRouterStateSpy).when(proxyRouterStateAttributeMock).get();
}
use of com.nike.riposte.server.http.ProxyRouterProcessingState in project riposte by Nike-Inc.
the class StreamingAsyncHttpClientTest method streamDownstreamCall_setsHostHeaderCorrectly.
@DataProvider(value = { "80 | false | localhost | localhost", "80 | true | localhost | localhost:80", "8080 | false | localhost | localhost:8080", "443 | true | localhost | localhost", "443 | false | localhost | localhost:443", "8080 | true | localhost | localhost:8080" }, splitBy = "\\|")
@Test
public void streamDownstreamCall_setsHostHeaderCorrectly(int downstreamPort, boolean isSecure, String downstreamHost, String expectedHostHeader) {
// given
DefaultHttpRequest request = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "");
ChannelHandlerContext ctx = mockChannelHandlerContext();
StreamingCallback streamingCallback = mock(StreamingCallback.class);
ProxyRouterProcessingState proxyState = ChannelAttributes.getProxyRouterProcessingStateForChannel(ctx).get();
RequestInfo<?> requestInfoMock = mock(RequestInfo.class);
// when
new StreamingAsyncHttpClient(200, 200, true, mock(DistributedTracingConfig.class)).streamDownstreamCall(downstreamHost, downstreamPort, request, isSecure, false, streamingCallback, 200, true, true, proxyState, requestInfoMock, ctx);
// then
assertThat(request.headers().get(HOST)).isEqualTo(expectedHostHeader);
}
use of com.nike.riposte.server.http.ProxyRouterProcessingState in project riposte by Nike-Inc.
the class ExceptionHandlingHandler method doExceptionCaught.
@Override
public PipelineContinuationBehavior doExceptionCaught(ChannelHandlerContext ctx, @NotNull Throwable cause) {
// We expect to end up here when handlers previously in the pipeline throw an error, so do the normal
// processError call.
HttpProcessingState state = getStateAndCreateIfNeeded(ctx, cause);
// Ensure that a RequestInfo is set on the state, no matter what.
getRequestInfo(state, null);
if (state.isResponseSendingStarted()) {
String infoMessage = "A response has already been started. Ignoring this exception since it's secondary. NOTE: This often " + "occurs when an error happens repeatedly on multiple chunks of a request or response - only the " + "first one is processed into the error sent to the user. The original error is probably higher up in " + "the logs. ignored_secondary_exception=\"{}\"";
if (cause instanceof NullPointerException)
logger.info(infoMessage, cause.toString(), cause);
else
logger.info(infoMessage, cause.toString());
return PipelineContinuationBehavior.DO_NOT_FIRE_CONTINUE_EVENT;
} else {
ResponseInfo<ErrorResponseBody> responseInfo = processError(state, null, cause);
if (shouldForceConnectionCloseAfterResponseSent(cause))
responseInfo.setForceConnectionCloseAfterResponseSent(true);
state.setResponseInfo(responseInfo, cause);
// We're about to send a full error response back to the original caller, so any proxy/router streaming is
// invalid. Cancel request and response streaming for proxy/router endpoints.
Endpoint<?> endpoint = state.getEndpointForExecution();
if (endpoint instanceof ProxyRouterEndpoint) {
ProxyRouterProcessingState proxyRouterState = getProxyRouterProcessingStateForChannel(ctx).get();
if (proxyRouterState != null) {
proxyRouterState.cancelRequestStreaming(cause, ctx);
proxyRouterState.cancelDownstreamRequest(cause);
}
}
addErrorAnnotationToOverallRequestSpan(state, responseInfo, cause);
}
return PipelineContinuationBehavior.CONTINUE;
}
Aggregations