This is an automated email from the ASF dual-hosted git repository. gary pushed a commit to branch release-1.8 in repository https://gitbox.apache.org/repos/asf/flink.git
commit 9b66985fe0589b7b8239f3c3d48eb8719ec6e8b2 Author: Gary Yao <[email protected]> AuthorDate: Tue Feb 26 11:48:27 2019 +0100 [FLINK-10585][runtime] Use java.net.URL to build restBaseUrl In URLs, IPv6 addresses have to be put inside "[" and "]", which is handled by the URL class. --- .../flink/runtime/rest/RestServerEndpoint.java | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java index 28f47ff..195b714 100644 --- a/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java +++ b/flink-runtime/src/main/java/org/apache/flink/runtime/rest/RestServerEndpoint.java @@ -57,6 +57,7 @@ import java.io.IOException; import java.io.Serializable; import java.net.BindException; import java.net.InetSocketAddress; +import java.net.URL; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; @@ -161,7 +162,7 @@ public abstract class RestServerEndpoint implements AutoCloseableAsync { RouterHandler handler = new RouterHandler(router, responseHeaders); // SSL should be the first handler in the pipeline - if (sslHandlerFactory != null) { + if (isHttpsEnabled()) { ch.pipeline().addLast("ssl", new RedirectingSslHandler(restAddress, restAddressFuture, sslHandlerFactory)); } @@ -231,15 +232,7 @@ public abstract class RestServerEndpoint implements AutoCloseableAsync { log.info("Rest endpoint listening at {}:{}", advertisedAddress, port); - final String protocol; - - if (sslHandlerFactory != null) { - protocol = "https://"; - } else { - protocol = "http://"; - } - - restBaseUrl = protocol + advertisedAddress + ':' + port; + restBaseUrl = new URL(determineProtocol(), advertisedAddress, port, "").toString(); restAddressFuture.complete(restBaseUrl); @@ -409,6 +402,14 @@ public abstract class RestServerEndpoint implements AutoCloseableAsync { } } + private boolean isHttpsEnabled() { + return sslHandlerFactory != null; + } + + private String determineProtocol() { + return isHttpsEnabled() ? "https" : "http"; + } + private static void registerHandler(Router router, Tuple2<RestHandlerSpecification, ChannelInboundHandler> specificationHandler, Logger log) { final String handlerURL = specificationHandler.f0.getTargetRestEndpointURL(); // setup versioned urls
