From a46ab84f10c231686140749cd535a82e3301dba5 Mon Sep 17 00:00:00 2001 From: LSmyrnaios Date: Mon, 6 Dec 2021 20:27:39 +0200 Subject: [PATCH] - Increase the lower and upper limits for the Java Heap Size. - Update the "ServerBaseURL" to the Public IP Address of the machine which is running the app. --- build.gradle | 6 ++++ .../urls_controller/util/UriBuilder.java | 34 ++++++++++++++++--- 2 files changed, 36 insertions(+), 4 deletions(-) diff --git a/build.gradle b/build.gradle index b902fd7..bc174c4 100644 --- a/build.gradle +++ b/build.gradle @@ -55,6 +55,12 @@ dependencies { testImplementation "org.springframework.boot:spring-boot-starter-test" } +// Set increased lower and upper limits for the java-execution. +tasks.withType(JavaExec) { + jvmArgs = ['-Xms512m', '-Xmx8g'] +} + + configurations { // Eliminates slf4j-log4j12 all*.exclude group: 'org.slf4j', module: 'slf4j-log4j12' diff --git a/src/main/java/eu/openaire/urls_controller/util/UriBuilder.java b/src/main/java/eu/openaire/urls_controller/util/UriBuilder.java index e6ee6df..d47155a 100644 --- a/src/main/java/eu/openaire/urls_controller/util/UriBuilder.java +++ b/src/main/java/eu/openaire/urls_controller/util/UriBuilder.java @@ -5,7 +5,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.env.Environment; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.net.InetAddress; +import java.net.MalformedURLException; +import java.net.URL; public class UriBuilder { @@ -24,7 +28,10 @@ public class UriBuilder { baseUrl += sslEnabled.equals("true") ? "s" : ""; baseUrl += "://"; - String hostName = InetAddress.getLoopbackAddress().getHostName(); // Non-null. + String hostName = getPublicIP(); + if ( hostName == null ) + hostName = InetAddress.getLoopbackAddress().getHostName(); // Non-null. + baseUrl += hostName; String serverPort = environment.getProperty("server.port"); if (serverPort == null) { // This is unacceptable! @@ -34,11 +41,11 @@ public class UriBuilder { baseUrl += ":" + serverPort; String baseInternalPath = environment.getProperty("server.servlet.context-path"); - if (baseInternalPath != null) { - if (!baseInternalPath.startsWith("/")) + if ( baseInternalPath != null ) { + if ( !baseInternalPath.startsWith("/") ) baseUrl += "/"; baseUrl += baseInternalPath; - if (!baseInternalPath.endsWith("/")) + if ( !baseInternalPath.endsWith("/") ) baseUrl += "/"; } else { logger.warn("No property \"server.servlet.context-path\" was found in \"application.properties\"!"); // Yes it's expected. @@ -48,6 +55,25 @@ public class UriBuilder { logger.debug("ServerBaseURL: " + baseUrl); } + private static String getPublicIP() + { + String publicIpAddress = ""; + URL url_name; + try { + url_name = new URL("https://api.ipify.org/"); + } catch (MalformedURLException mue) { + logger.warn(mue.getMessage()); + return null; + } + try (BufferedReader bf = new BufferedReader(new InputStreamReader(url_name.openStream()))) { + publicIpAddress = bf.readLine().trim(); + } catch (Exception e) { + logger.warn("Cannot get the publicIP address for this machine!", e); + return null; + } + return publicIpAddress; + } + public static String getBaseUrl() { return baseUrl; }