kpatelatwork commented on a change in pull request #10530: URL: https://github.com/apache/kafka/pull/10530#discussion_r616783892
########## File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java ########## @@ -369,9 +370,31 @@ else if (serverConnector != null && serverConnector.getHost() != null && serverC else if (serverConnector != null && serverConnector.getPort() > 0) builder.port(serverConnector.getPort()); - log.info("Advertised URI: {}", builder.build()); + URI uri = builder.build(); + validateUriHost(uri); + log.info("Advertised URI: {}", uri); - return builder.build(); + return uri; + } + + /** + * Parses the uri and throws a more definitive error + * when the internal node to node communication can't happen due to an invalid host name. + */ + static void validateUriHost(URI uri) { + if (uri.getHost() == null) { + String host = Utils.getHost(uri.getAuthority()); + String errorMsg = "Could not parse host from advertised URL=" + uri.toString(); Review comment: fixed ########## File path: connect/runtime/src/main/java/org/apache/kafka/connect/runtime/rest/RestServer.java ########## @@ -369,9 +370,31 @@ else if (serverConnector != null && serverConnector.getHost() != null && serverC else if (serverConnector != null && serverConnector.getPort() > 0) builder.port(serverConnector.getPort()); - log.info("Advertised URI: {}", builder.build()); + URI uri = builder.build(); + validateUriHost(uri); + log.info("Advertised URI: {}", uri); - return builder.build(); + return uri; + } + + /** + * Parses the uri and throws a more definitive error + * when the internal node to node communication can't happen due to an invalid host name. + */ + static void validateUriHost(URI uri) { + if (uri.getHost() == null) { + String host = Utils.getHost(uri.getAuthority()); + String errorMsg = "Could not parse host from advertised URL=" + uri.toString(); + if (host != null) { + try { + IDN.toASCII(host, IDN.USE_STD3_ASCII_RULES); + } catch (IllegalArgumentException e) { + errorMsg += ", as it doesn't conform to RFC 1123 specification, reason=" + e.getMessage(); Review comment: fixed ########## File path: connect/runtime/src/test/java/org/apache/kafka/connect/runtime/rest/RestServerTest.java ########## @@ -185,6 +189,25 @@ public void testAdvertisedUri() { Assert.assertEquals("http://plaintext-localhost:4761/", server.advertisedUrl().toString()); } + @Test + public void testValidateUriHost() { + validateUriHost(URI.create("http://localhost:8080")); + validateUriHost(URI.create("http://172.217.2.110:80")); + validateUriHost(URI.create("http://[2607:f8b0:4006:818::2004]:80")); Review comment: done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org