@Test public void getRequestAndBaseUri_ResourceWithRegexGiven_ShouldEscapeRegex() { GatewayRequestAndLambdaContext validRequestAndLambdaContext = new GatewayRequestBuilder() .domain(TEST_CUSTOM_DOMAIN) .basePath("base") .resource("/a.c") .buildWrapped(); RequestAndBaseUri validUris = gatewayHandler.getRequestAndBaseUri(validRequestAndLambdaContext); assertEquals(URI.create(TEST_CUSTOM_DOMAIN_WITH_SCHEME + "/base/"), validUris.getBaseUri()); assertEquals(URI.create(TEST_CUSTOM_DOMAIN_WITH_SCHEME + "/base/a.c"), validUris.getRequestUri()); GatewayRequestAndLambdaContext invalidRequestAndLambdaContext = new GatewayRequestBuilder() .domain(TEST_CUSTOM_DOMAIN) .basePath("base") .resource("/a.c") .path("/base/abc") .buildWrapped(); RequestAndBaseUri invalidUris = gatewayHandler.getRequestAndBaseUri(invalidRequestAndLambdaContext); assertEquals(URI.create("/"), invalidUris.getBaseUri()); assertEquals(URI.create("/base/abc"), invalidUris.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();   }