From 1f9817762c19c97be24c42ac9f0480e888e42117 Mon Sep 17 00:00:00 2001 From: Uellington Damasceno Date: Fri, 22 Nov 2024 00:04:15 -0300 Subject: [PATCH] If applied, this commit will add gateway real ip --- src/main/java/dlt/id/manager/model/IDManager.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/main/java/dlt/id/manager/model/IDManager.java b/src/main/java/dlt/id/manager/model/IDManager.java index 64003d3..1bd5d20 100644 --- a/src/main/java/dlt/id/manager/model/IDManager.java +++ b/src/main/java/dlt/id/manager/model/IDManager.java @@ -23,11 +23,11 @@ public IDManager() { public void start() { try { - this.ip = InetAddress.getLocalHost().getHostAddress().trim(); + this.ip = this.getEnvOrDefault("GATEWAY_REAL_IP", InetAddress.getLocalHost().getHostAddress().trim()); this.id = UUID.randomUUID().toString(); this.log = Logger.getLogger(IDManager.class.getName()); - this.log.info("IP: " + this.ip); + this.log.log(Level.INFO, "IP: {0}", this.ip); } catch (UnknownHostException ex) { Logger.getLogger(IDManager.class.getName()).log(Level.SEVERE, null, ex); } @@ -45,5 +45,10 @@ public String getIP() { public String getID() { return this.id; } + + private String getEnvOrDefault(String env, String defaultValue){ + String value = System.getenv(env); + return value == null ? defaultValue : value; + } }