From 8450521d6cd6afe696db7a1f7a8ae08a32c8a593 Mon Sep 17 00:00:00 2001 From: Don Bourne Date: Thu, 3 Oct 2024 08:54:09 -0400 Subject: [PATCH 1/4] move resource file --- Dockerfile | 1 - .../openliberty/sample/config/CustomConfigSource.java | 10 +++++++--- .../main/webapp/META-INF}/CustomConfigSource.json | 0 3 files changed, 7 insertions(+), 4 deletions(-) rename {resources => src/main/webapp/META-INF}/CustomConfigSource.json (100%) diff --git a/Dockerfile b/Dockerfile index 39d066f7..e7b4ccd2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -16,7 +16,6 @@ LABEL \ description="This image contains a sample application that displays the Java system properties and demonstrates MicroProfile Config, Health and Metrics." COPY --chown=1001:0 src/main/liberty/config/ /config/ -COPY --chown=1001:0 resources/ /output/resources/ RUN features.sh diff --git a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java index 98791b97..cf343122 100644 --- a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java +++ b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java @@ -20,12 +20,14 @@ import java.io.BufferedReader; import java.io.FileReader; +import java.io.InputStream; +import java.io.InputStreamReader; + import org.eclipse.microprofile.config.spi.ConfigSource; public class CustomConfigSource implements ConfigSource { - String fileLocation = System.getProperty("user.dir").split("target")[0] - + "/resources/CustomConfigSource.json"; + String fileLocation = "META-INF/CustomConfigSource.json"; @Override public int getOrdinal() { @@ -83,7 +85,9 @@ public Map getProperties() { public String readFile(String fileName) { String result = ""; try { - BufferedReader br = new BufferedReader(new FileReader(fileName)); + // BufferedReader br = new BufferedReader(new FileReader(fileName)); + InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); + BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line = br.readLine(); while (line != null) { diff --git a/resources/CustomConfigSource.json b/src/main/webapp/META-INF/CustomConfigSource.json similarity index 100% rename from resources/CustomConfigSource.json rename to src/main/webapp/META-INF/CustomConfigSource.json From 02b2c61e4fcd373326e75338c5452c689d14887f Mon Sep 17 00:00:00 2001 From: Don Bourne Date: Thu, 3 Oct 2024 16:14:55 -0400 Subject: [PATCH 2/4] address review comments --- .../java/io/openliberty/sample/config/CustomConfigSource.java | 2 +- src/main/{webapp => resources}/META-INF/CustomConfigSource.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/main/{webapp => resources}/META-INF/CustomConfigSource.json (100%) diff --git a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java index cf343122..8a9eb373 100644 --- a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java +++ b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java @@ -19,7 +19,7 @@ import java.io.StringReader; import java.io.BufferedReader; -import java.io.FileReader; +// import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; diff --git a/src/main/webapp/META-INF/CustomConfigSource.json b/src/main/resources/META-INF/CustomConfigSource.json similarity index 100% rename from src/main/webapp/META-INF/CustomConfigSource.json rename to src/main/resources/META-INF/CustomConfigSource.json From cc76f413cba7c1da0c2d6db86fb2a7b0dfdf265c Mon Sep 17 00:00:00 2001 From: Don Bourne Date: Thu, 3 Oct 2024 16:16:59 -0400 Subject: [PATCH 3/4] remove comment --- .../java/io/openliberty/sample/config/CustomConfigSource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java index 8a9eb373..7e0c0124 100644 --- a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java +++ b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java @@ -19,7 +19,6 @@ import java.io.StringReader; import java.io.BufferedReader; -// import java.io.FileReader; import java.io.InputStream; import java.io.InputStreamReader; From afb69e737e286bba96c1e4666bc3f098b0e7c085 Mon Sep 17 00:00:00 2001 From: Don Bourne Date: Thu, 3 Oct 2024 16:19:39 -0400 Subject: [PATCH 4/4] remove comment --- .../java/io/openliberty/sample/config/CustomConfigSource.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java index 7e0c0124..bbc6b809 100644 --- a/src/main/java/io/openliberty/sample/config/CustomConfigSource.java +++ b/src/main/java/io/openliberty/sample/config/CustomConfigSource.java @@ -84,7 +84,6 @@ public Map getProperties() { public String readFile(String fileName) { String result = ""; try { - // BufferedReader br = new BufferedReader(new FileReader(fileName)); InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName); BufferedReader br = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder();