@Test public void getRequestAndBaseUri_CustomDomainGiven_ShouldNotAddContextStageToUri() { GatewayRequestAndLambdaContext requestAndLambdaContext = new GatewayRequestBuilder() .domain(TEST_CUSTOM_DOMAIN) .requestContextStage("dev") .resource("/users") .buildWrapped(); RequestAndBaseUri uris = gatewayHandler.getRequestAndBaseUri(requestAndLambdaContext); assertEquals(URI.create(TEST_CUSTOM_DOMAIN_WITH_SCHEME + "/"), uris.getBaseUri()); assertEquals(URI.create(TEST_CUSTOM_DOMAIN_WITH_SCHEME + "/users"), uris.getRequestUri()); }
@Nonnull protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); URI baseUri; URI baseUriWithoutBasePath; try { UriBuilder baseUriBuilder; String host = getHost(request); String basePath = getBasePathUri(request); boolean hostPresent = !isBlank(host); boolean validBasePath = basePath != null; if (!hostPresent) { LOG.warn("no host header available; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else if (!validBasePath) { LOG.warn("couldn't determine basePath; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else { baseUriBuilder = UriBuilder.fromUri("https: if (isDirectApiGatewayInvocation(host)) { addStagePathIfAvailable(baseUriBuilder, request); } } baseUriWithoutBasePath = baseUriBuilder.build(); if (hostPresent && validBasePath) { baseUriBuilder.path(basePath); baseUriBuilder.path("/"); } baseUri = baseUriBuilder.build(); } catch (RuntimeException e) { LOG.error("baseUriCreationFailure; using baseUri=/ as fallback", e); baseUri = BASE_ROOT_URI; baseUriWithoutBasePath = baseUri; } UriBuilder requestUriBuilder = UriBuilder.fromUri(baseUriWithoutBasePath).path(request.getPath()); addQueryParametersIfAvailable(requestUriBuilder, request); return new RequestAndBaseUri(baseUri, requestUriBuilder.build()); }
GatewayRequestHandler extends SimpleRequestHandler<GatewayRequestAndLambdaContext, GatewayResponse> { @Nonnull protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); URI baseUri; URI baseUriWithoutBasePath; try { UriBuilder baseUriBuilder; String host = getHost(request); String basePath = getBasePathUri(request); boolean hostPresent = !isBlank(host); boolean validBasePath = basePath != null; if (!hostPresent) { LOG.warn("no host header available; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else if (!validBasePath) { LOG.warn("couldn't determine basePath; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else { baseUriBuilder = UriBuilder.fromUri("https: if (isDirectApiGatewayInvocation(host)) { addStagePathIfAvailable(baseUriBuilder, request); } } baseUriWithoutBasePath = baseUriBuilder.build(); if (hostPresent && validBasePath) { baseUriBuilder.path(basePath); baseUriBuilder.path("/"); } baseUri = baseUriBuilder.build(); } catch (RuntimeException e) { LOG.error("baseUriCreationFailure; using baseUri=/ as fallback", e); baseUri = BASE_ROOT_URI; baseUriWithoutBasePath = baseUri; } UriBuilder requestUriBuilder = UriBuilder.fromUri(baseUriWithoutBasePath).path(request.getPath()); addQueryParametersIfAvailable(requestUriBuilder, request); return new RequestAndBaseUri(baseUri, requestUriBuilder.build()); } }
GatewayRequestHandler extends SimpleRequestHandler<GatewayRequestAndLambdaContext, GatewayResponse> { @Nonnull protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); URI baseUri; URI baseUriWithoutBasePath; try { UriBuilder baseUriBuilder; String host = getHost(request); String basePath = getBasePathUri(request); boolean hostPresent = !isBlank(host); boolean validBasePath = basePath != null; if (!hostPresent) { LOG.warn("no host header available; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else if (!validBasePath) { LOG.warn("couldn't determine basePath; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else { baseUriBuilder = UriBuilder.fromUri("https: if (isDirectApiGatewayInvocation(host)) { addStagePathIfAvailable(baseUriBuilder, request); } } baseUriWithoutBasePath = baseUriBuilder.build(); if (hostPresent && validBasePath) { baseUriBuilder.path(basePath); baseUriBuilder.path("/"); } baseUri = baseUriBuilder.build(); } catch (RuntimeException e) { LOG.error("baseUriCreationFailure; using baseUri=/ as fallback", e); baseUri = BASE_ROOT_URI; baseUriWithoutBasePath = baseUri; } UriBuilder requestUriBuilder = UriBuilder.fromUri(baseUriWithoutBasePath).path(request.getPath()); addQueryParametersIfAvailable(requestUriBuilder, request); return new RequestAndBaseUri(baseUri, requestUriBuilder.build()); } protected  GatewayRequestHandler(); }
GatewayRequestHandler extends SimpleRequestHandler<GatewayRequestAndLambdaContext, GatewayResponse> { @Nonnull protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); URI baseUri; URI baseUriWithoutBasePath; try { UriBuilder baseUriBuilder; String host = getHost(request); String basePath = getBasePathUri(request); boolean hostPresent = !isBlank(host); boolean validBasePath = basePath != null; if (!hostPresent) { LOG.warn("no host header available; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else if (!validBasePath) { LOG.warn("couldn't determine basePath; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else { baseUriBuilder = UriBuilder.fromUri("https: if (isDirectApiGatewayInvocation(host)) { addStagePathIfAvailable(baseUriBuilder, request); } } baseUriWithoutBasePath = baseUriBuilder.build(); if (hostPresent && validBasePath) { baseUriBuilder.path(basePath); baseUriBuilder.path("/"); } baseUri = baseUriBuilder.build(); } catch (RuntimeException e) { LOG.error("baseUriCreationFailure; using baseUri=/ as fallback", e); baseUri = BASE_ROOT_URI; baseUriWithoutBasePath = baseUri; } UriBuilder requestUriBuilder = UriBuilder.fromUri(baseUriWithoutBasePath).path(request.getPath()); addQueryParametersIfAvailable(requestUriBuilder, request); return new RequestAndBaseUri(baseUri, requestUriBuilder.build()); } protected  GatewayRequestHandler();  }
GatewayRequestHandler extends SimpleRequestHandler<GatewayRequestAndLambdaContext, GatewayResponse> { @Nonnull protected RequestAndBaseUri getRequestAndBaseUri(@Nonnull GatewayRequestAndLambdaContext requestAndLambdaContext) { GatewayRequest request = requestAndLambdaContext.getGatewayRequest(); URI baseUri; URI baseUriWithoutBasePath; try { UriBuilder baseUriBuilder; String host = getHost(request); String basePath = getBasePathUri(request); boolean hostPresent = !isBlank(host); boolean validBasePath = basePath != null; if (!hostPresent) { LOG.warn("no host header available; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else if (!validBasePath) { LOG.warn("couldn't determine basePath; using baseUri=/ as fallback"); baseUriBuilder = UriBuilder.fromUri(BASE_ROOT_URI); } else { baseUriBuilder = UriBuilder.fromUri("https: if (isDirectApiGatewayInvocation(host)) { addStagePathIfAvailable(baseUriBuilder, request); } } baseUriWithoutBasePath = baseUriBuilder.build(); if (hostPresent && validBasePath) { baseUriBuilder.path(basePath); baseUriBuilder.path("/"); } baseUri = baseUriBuilder.build(); } catch (RuntimeException e) { LOG.error("baseUriCreationFailure; using baseUri=/ as fallback", e); baseUri = BASE_ROOT_URI; baseUriWithoutBasePath = baseUri; } UriBuilder requestUriBuilder = UriBuilder.fromUri(baseUriWithoutBasePath).path(request.getPath()); addQueryParametersIfAvailable(requestUriBuilder, request); return new RequestAndBaseUri(baseUri, requestUriBuilder.build()); } protected  GatewayRequestHandler();   }