From fa2325c7ffd2d0def022aa958aeff563c7977864 Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Vazquez Date: Wed, 19 Feb 2025 17:21:35 -0300 Subject: [PATCH 1/2] Support reading the CloudService.config file from filesystem and classLoader. --- .../java/com/genexus/util/GXServices.java | 98 +++++++++++++------ 1 file changed, 66 insertions(+), 32 deletions(-) diff --git a/java/src/main/java/com/genexus/util/GXServices.java b/java/src/main/java/com/genexus/util/GXServices.java index 165dca5aa..82f936258 100644 --- a/java/src/main/java/com/genexus/util/GXServices.java +++ b/java/src/main/java/com/genexus/util/GXServices.java @@ -1,6 +1,9 @@ package com.genexus.util; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; import java.util.Hashtable; import com.genexus.ApplicationContext; @@ -47,32 +50,6 @@ public static void endGXServices() { instance = null; } - public static void loadFromFile(String basePath, String fileName, GXServices services){ - if (basePath.equals("")) { - basePath = services.configBaseDirectory(); - } - String fullPath = basePath + fileName; - XMLReader reader = new XMLReader(); - reader.open(fullPath); - reader.readType(1, "Services"); - reader.read(); - if (reader.getErrCode() == 0) { - while (!reader.getName().equals("Services")) { - services.processService(reader); - reader.read(); - if (reader.getName().equals("Service") && reader.getNodeType() == 2) // - reader.read(); - } - reader.close(); - } - else - { - if (!ApplicationContext.getInstance().getReorganization()) - { - logger.debug("GXServices - Could not load Services Config: " + fullPath + " - " + reader.getErrDescription()); - } - } - } private String configBaseDirectory() { String baseDir = ""; @@ -99,14 +76,71 @@ private String configBaseDirectory() { } private void readServices(String basePath) { - - if (basePath.equals("")) + if (basePath.equals("")) { basePath = configBaseDirectory(); - if (new File(basePath + SERVICES_DEV_FILE).exists()){ - loadFromFile(basePath, SERVICES_DEV_FILE, this); } - if (new File(basePath + SERVICES_FILE).exists()){ - loadFromFile(basePath, SERVICES_FILE, this); + + if (!readFromFileSystem(basePath, SERVICES_DEV_FILE)) { + readFromClasspath(SERVICES_DEV_FILE); + } + + if (!readFromFileSystem(basePath, SERVICES_FILE)) { + readFromClasspath(SERVICES_FILE); + } + } + + private boolean readFromFileSystem(String basePath, String fileName) { + File file = new File(basePath + fileName); + if (file.exists()) { + loadFromFile(basePath, fileName, this); + return true; + } + return false; + } + + private boolean readFromClasspath(String fileName) { + InputStream inputStream = getClass().getClassLoader().getResourceAsStream(fileName); + if (inputStream == null) { + return false; + } + try { + loadFromStream(inputStream, fileName, this); + return true; + } catch (IOException e) { + logger.debug("GXServices - Could not load Services Config from classpath: " + fileName + " - " + e.getMessage()); + } + return false; + } + + public static void loadFromFile(String basePath, String fileName, GXServices services) { + if (basePath.equals("")) { + basePath = services.configBaseDirectory(); + } + String fullPath = basePath + fileName; + try (InputStream inputStream = new FileInputStream(fullPath)) { + loadFromStream(inputStream, fullPath, services); + } catch (IOException e) { + logger.debug("GXServices - Could not load Services Config from file: " + fullPath + " - " + e.getMessage()); + } + } + + public static void loadFromStream(InputStream inputStream, String source, GXServices services) throws IOException { + XMLReader reader = new XMLReader(); + reader.open(inputStream); + reader.readType(1, "Services"); + reader.read(); + if (reader.getErrCode() == 0) { + while (!reader.getName().equals("Services")) { + services.processService(reader); + reader.read(); + if (reader.getName().equals("Service") && reader.getNodeType() == 2) // + reader.read(); + } + reader.close(); + } else { + if (!ApplicationContext.getInstance().getReorganization()) { + logger.debug("GXServices - Could not load Services Config: " + source + " - " + reader.getErrDescription()); + } } } From ca2c064a1731ff7afd4f84499b66f132008d4d1c Mon Sep 17 00:00:00 2001 From: Gonzalo Gallotti Vazquez Date: Wed, 19 Feb 2025 17:32:45 -0300 Subject: [PATCH 2/2] Support reading the CloudService.config file from filesystem and classLoader. --- .../main/java/com/genexus/xml/XMLReader.java | 22 ++++++++++++++++++- .../java/com/genexus/util/GXServices.java | 2 +- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/common/src/main/java/com/genexus/xml/XMLReader.java b/common/src/main/java/com/genexus/xml/XMLReader.java index b9e03a903..58961710a 100644 --- a/common/src/main/java/com/genexus/xml/XMLReader.java +++ b/common/src/main/java/com/genexus/xml/XMLReader.java @@ -814,7 +814,27 @@ public void openResource(String url) } } - + public void openFromInputStream(InputStream inputStream) + { + reset(); + try + { + streamToClose = inputStream; + if (documentEncoding.length() > 0) + inputSource = new XMLInputSource(null, null, null, inputStream, documentEncoding); + else + inputSource = new XMLInputSource(null, null, null, inputStream, null); + + parserConfiguration.setInputSource(inputSource); + } + catch (IOException e) + { + errCode = ERROR_IO; + errDescription = e.getMessage(); + } + } + + public void openFromString(String s) { reset(); diff --git a/java/src/main/java/com/genexus/util/GXServices.java b/java/src/main/java/com/genexus/util/GXServices.java index 82f936258..c386ee800 100644 --- a/java/src/main/java/com/genexus/util/GXServices.java +++ b/java/src/main/java/com/genexus/util/GXServices.java @@ -126,7 +126,7 @@ public static void loadFromFile(String basePath, String fileName, GXServices ser public static void loadFromStream(InputStream inputStream, String source, GXServices services) throws IOException { XMLReader reader = new XMLReader(); - reader.open(inputStream); + reader.openFromInputStream(inputStream); reader.readType(1, "Services"); reader.read(); if (reader.getErrCode() == 0) {