public DownstreamIdleChannelTimeoutException(long timeoutValueMillis, Channel channel) { super("The downstream channel was idle too long. downstream_channel_timeout_value_millis=" + timeoutValueMillis + ", idle_channel_id=" + getChannelId(channel) ); this.timeoutValueMillis = timeoutValueMillis; this.channelId = getChannelId(channel); }
public DownstreamChannelClosedUnexpectedlyException(Channel channel) { super("The channel used to talk to the downstream system was closed while the call was active - probably by " + "the downstream system, but also possibly by us if an unrecoverable error occurred and we " + "preemptively closed the channel. closed_channel_id=" + getChannelId(channel) ); this.channelId = getChannelId(channel); }
void throwExceptionIfNotSuccessfullyDecoded(HttpObject httpObject) { Throwable decoderFailure = getDecoderFailure(httpObject); if (decoderFailure == null) { return; } throw new InvalidHttpRequestException( "Detected HttpObject that was not successfully decoded.", decoderFailure ); }
@Test public void should_honor_constructor_params() { //given Endpoint<?> endpoint1 = new EndpointOne(); Endpoint<?> endpoint2 = new EndpointTwo(); List<Endpoint<?>> endpointList = Arrays.asList(endpoint1, endpoint2); String requestPath = UUID.randomUUID().toString(); String requestMethod = UUID.randomUUID().toString(); String message = UUID.randomUUID().toString(); //when MultipleMatchingEndpointsException ex = new MultipleMatchingEndpointsException(message, endpointList, requestPath, requestMethod); //then assertThat(ex.getMessage(), is(message)); assertThat(ex.matchingEndpointsDetails, is(Arrays.asList(EndpointOne.class.getName(), EndpointTwo.class.getName()))); assertThat(ex.requestPath, is(requestPath)); assertThat(ex.requestMethod, is(requestMethod)); }
@Override public void validateSecureRequestForEndpoint(RequestInfo<?> requestInfo, Endpoint<?> endpoint) { requestInfo.addRequestAttribute(SECURITY_VALIDATOR_EXECUTED_HEADER_KEY, true); if ("true".equals(requestInfo.getHeaders().get(FORCE_SECURITY_ERROR_HEADER_KEY))) { requestInfo.addRequestAttribute(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY, true); throw new Unauthorized401Exception("Forcing Security Error.", requestInfo.getPath(), null); } else requestInfo.addRequestAttribute(SECURITY_VALIDATOR_THREW_ERROR_HEADER_KEY, false); }
private void throwExceptionIfContentLengthHeaderIsLargerThanConfiguredMaxRequestSize(HttpRequest msg, Endpoint<?> endpoint) { int configuredMaxRequestSize = getConfiguredMaxRequestSize(endpoint, globalConfiguredMaxRequestSizeInBytes); if (!isMaxRequestSizeValidationDisabled(configuredMaxRequestSize) && HttpHeaders.isContentLengthSet(msg) && HttpHeaders.getContentLength(msg) > configuredMaxRequestSize) { throw new RequestTooBigException( "Content-Length header value exceeded configured max request size of " + configuredMaxRequestSize ); } }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { // First chunk in the request. See if this channel has been marked for death. Integer actualNumOpenChannels = ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).get(); if (actualNumOpenChannels != null && actualNumOpenChannels >= maxOpenChannelsThreshold) throw new TooManyOpenChannelsException(actualNumOpenChannels, maxOpenChannelsThreshold); } return PipelineContinuationBehavior.CONTINUE; }
@Test public void two_arg_constructor_works_as_expected_null_inputs() { // when MissingRequiredContentException ex = new MissingRequiredContentException(null, null); // then assertThat(ex.endpointClassName).isEqualTo("null"); assertThat(ex.method).isEqualTo("null"); assertThat(ex.path).isEqualTo("null"); }
@Test public void should_honor_constructor_params() { //given long timeoutValue = 42; //when NonblockingEndpointCompletableFutureTimedOut ex = new NonblockingEndpointCompletableFutureTimedOut(timeoutValue); //then assertThat(ex.timeoutValueMillis, is(timeoutValue)); }
@Test public void should_handle_DownstreamChannelClosedUnexpectedlyException() { verifyExceptionHandled(new DownstreamChannelClosedUnexpectedlyException(null), singletonError(testProjectApiErrors.getTemporaryServiceProblemApiError())); }
@Test public void shouldHandlePathNotFound404Exception() { verifyExceptionHandled(new PathNotFound404Exception("intentional boom"), singletonError(testProjectApiErrors.getNotFoundApiError())); }
@Test public void shouldHandleHostnameResolutionException() { verifyExceptionHandled(new HostnameResolutionException("foo", null), singletonError(testProjectApiErrors.getTemporaryServiceProblemApiError())); }
public static Map<String, String> decodePathParams(String pathTemplate, String path) { // Ignore trailing slashes on either the template or path. if (pathTemplate.endsWith("/")) pathTemplate = pathTemplate.substring(0, pathTemplate.length() - 1); if (path.endsWith("/")) path = path.substring(0, path.length() - 1); if (!pathParamExtractor.match(pathTemplate, path)) { throw new PathParameterMatchingException( "Cannot decode path params - path template and URI path do not match.", pathTemplate, path); } return pathParamExtractor.extractUriTemplateVariables(pathTemplate, path); }
@Test public void should_handle_Forbidden403Exception() { verifyExceptionHandled(new Forbidden403Exception("foo", "/bar", "blah"), singletonError(testProjectApiErrors.getForbiddenApiError())); }
@Test public void should_handle_Unauthorized401Exception() { verifyExceptionHandled(new Unauthorized401Exception("foo", "/bar", "blah"), singletonError(testProjectApiErrors.getUnauthorizedApiError())); }
void throwExceptionIfNotSuccessfullyDecoded(HttpObject httpObject) { Throwable decoderFailure = getDecoderFailure(httpObject); if (decoderFailure == null) { return; } throw new InvalidHttpRequestException( "Detected HttpObject that was not successfully decoded.", decoderFailure ); }
private void throwExceptionIfContentLengthHeaderIsLargerThanConfiguredMaxRequestSize(HttpRequest msg, Endpoint<?> endpoint) { int configuredMaxRequestSize = getConfiguredMaxRequestSize(endpoint, globalConfiguredMaxRequestSizeInBytes); if (!isMaxRequestSizeValidationDisabled(configuredMaxRequestSize) && HttpHeaders.isContentLengthSet(msg) && HttpHeaders.getContentLength(msg) > configuredMaxRequestSize) { throw new RequestTooBigException( "Content-Length header value exceeded configured max request size of " + configuredMaxRequestSize ); } }
@Override public PipelineContinuationBehavior doChannelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { // First chunk in the request. See if this channel has been marked for death. Integer actualNumOpenChannels = ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).get(); if (actualNumOpenChannels != null && actualNumOpenChannels >= maxOpenChannelsThreshold) throw new TooManyOpenChannelsException(actualNumOpenChannels, maxOpenChannelsThreshold); } return PipelineContinuationBehavior.CONTINUE; }
@Test public void no_arg_constructor_works_as_expected() { MissingRequiredContentException ex = new MissingRequiredContentException(); assertThat(ex.endpointClassName).isEqualTo("null"); assertThat(ex.method).isEqualTo("null"); assertThat(ex.path).isEqualTo("null"); }
@Test public void shouldHandlePathParameterMatchingException() { verifyExceptionHandled(new PathParameterMatchingException("intentional boom", null, null), singletonError(testProjectApiErrors.getGenericServiceError())); }