From d35247b7b16b9734012daf9b35a2e4e7323545f7 Mon Sep 17 00:00:00 2001 From: Bryan Bende Date: Wed, 14 Feb 2024 11:11:10 -0500 Subject: [PATCH] NIFI-12788 Avoid host URI encoding errors for Jetty Server Connector This closes #8404 Signed-off-by: David Handermann --- .../java/org/apache/nifi/web/server/JettyServer.java | 9 +++++++-- .../java/org/apache/nifi/registry/jetty/JettyServer.java | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java index 526cc6906c..fe83b16d2b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-web/nifi-jetty/src/main/java/org/apache/nifi/web/server/JettyServer.java @@ -28,6 +28,7 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.URI; +import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -153,7 +154,7 @@ public class JettyServer implements NiFiServer, ExtensionUiLoader { private static final String WAR_EXTENSION = ".war"; private static final int WEB_APP_MAX_FORM_CONTENT_SIZE = 600000; - private static final String APPLICATION_URL_FORMAT = "%s://%s:%d/nifi"; + private static final String APPLICATION_PATH = "/nifi"; private static final String HTTPS_SCHEME = "https"; private static final String HTTP_SCHEME = "http"; private static final String HOST_UNSPECIFIED = "0.0.0.0"; @@ -725,7 +726,11 @@ public class JettyServer implements NiFiServer, ExtensionUiLoader { final int port = serverConnector.getLocalPort(); final String connectorHost = serverConnector.getHost(); final String host = StringUtils.defaultIfEmpty(connectorHost, HOST_UNSPECIFIED); - return URI.create(String.format(APPLICATION_URL_FORMAT, scheme, host, port)); + try { + return new URI(scheme, null, host, port, APPLICATION_PATH, null, null); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } }) .collect(Collectors.toList()); } diff --git a/nifi-registry/nifi-registry-core/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java b/nifi-registry/nifi-registry-core/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java index 852c1802c5..df03bedc01 100644 --- a/nifi-registry/nifi-registry-core/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java +++ b/nifi-registry/nifi-registry-core/nifi-registry-jetty/src/main/java/org/apache/nifi/registry/jetty/JettyServer.java @@ -34,6 +34,7 @@ import java.net.InetAddress; import java.net.NetworkInterface; import java.net.SocketException; import java.net.URI; +import java.net.URISyntaxException; import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -48,7 +49,7 @@ public class JettyServer { private static final Logger logger = LoggerFactory.getLogger(JettyServer.class); - private static final String APPLICATION_URL_FORMAT = "%s://%s:%d/nifi-registry"; + private static final String APPLICATION_PATH = "/nifi-registry"; private static final String HTTPS_SCHEME = "https"; @@ -142,7 +143,11 @@ public class JettyServer { final int port = serverConnector.getLocalPort(); final String connectorHost = serverConnector.getHost(); final String host = StringUtils.defaultIfEmpty(connectorHost, HOST_UNSPECIFIED); - return URI.create(String.format(APPLICATION_URL_FORMAT, scheme, host, port)); + try { + return new URI(scheme, null, host, port, APPLICATION_PATH, null, null); + } catch (URISyntaxException e) { + throw new RuntimeException(e); + } }) .collect(Collectors.toList()); }