This is an automated email from the ASF dual-hosted git repository.

exceptionfactory pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git


The following commit(s) were added to refs/heads/main by this push:
     new d35247b7b1 NIFI-12788 Avoid host URI encoding errors for Jetty Server 
Connector
d35247b7b1 is described below

commit d35247b7b16b9734012daf9b35a2e4e7323545f7
Author: Bryan Bende <bbe...@apache.org>
AuthorDate: Wed Feb 14 11:11:10 2024 -0500

    NIFI-12788 Avoid host URI encoding errors for Jetty Server Connector
    
    This closes #8404
    
    Signed-off-by: David Handermann <exceptionfact...@apache.org>
---
 .../src/main/java/org/apache/nifi/web/server/JettyServer.java    | 9 +++++++--
 .../main/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());
     }

Reply via email to