From 23723510b1d7a9cf0865339b0b4a461fe62a4fbf Mon Sep 17 00:00:00 2001 From: chathurangaj Date: Mon, 20 Jan 2025 11:24:41 +0530 Subject: [PATCH] fix governance registry path used for scheduled tasks --- .../registry/MicroIntegratorRegistry.java | 1 + .../core/impl/FileBasedTaskRepository.java | 26 +++++++++++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/components/mediation/registry/org.wso2.micro.integrator.registry/src/main/java/org/wso2/micro/integrator/registry/MicroIntegratorRegistry.java b/components/mediation/registry/org.wso2.micro.integrator.registry/src/main/java/org/wso2/micro/integrator/registry/MicroIntegratorRegistry.java index 5d11cfeb67..aab3f964ab 100644 --- a/components/mediation/registry/org.wso2.micro.integrator.registry/src/main/java/org/wso2/micro/integrator/registry/MicroIntegratorRegistry.java +++ b/components/mediation/registry/org.wso2.micro.integrator.registry/src/main/java/org/wso2/micro/integrator/registry/MicroIntegratorRegistry.java @@ -206,6 +206,7 @@ public void init(Properties properties) { addConfigProperty(name, value); } } + System.setProperty("mi.registry.gov", govRegistry); log.debug("MI lightweight registry is initialized."); initSecurityRepo(); diff --git a/components/mediation/tasks/org.wso2.micro.integrator.ntask.core/src/main/java/org/wso2/micro/integrator/ntask/core/impl/FileBasedTaskRepository.java b/components/mediation/tasks/org.wso2.micro.integrator.ntask.core/src/main/java/org/wso2/micro/integrator/ntask/core/impl/FileBasedTaskRepository.java index c524f1df96..39f48be558 100644 --- a/components/mediation/tasks/org.wso2.micro.integrator.ntask.core/src/main/java/org/wso2/micro/integrator/ntask/core/impl/FileBasedTaskRepository.java +++ b/components/mediation/tasks/org.wso2.micro.integrator.ntask.core/src/main/java/org/wso2/micro/integrator/ntask/core/impl/FileBasedTaskRepository.java @@ -17,6 +17,7 @@ */ package org.wso2.micro.integrator.ntask.core.impl; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.micro.integrator.ntask.common.TaskException; @@ -39,6 +40,8 @@ import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; +import java.net.URI; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; @@ -54,11 +57,9 @@ public class FileBasedTaskRepository implements TaskRepository { private static final Log log = LogFactory.getLog(FileBasedTaskRepository.class); private static final String REG_TASK_BASE_PATH = "/repository/components/org.wso2.carbon.tasks"; - private static final String REG_TASK_REPO_BASE_PATH = REG_TASK_BASE_PATH + "/" + "definitions"; private static final char URL_SEPARATOR_CHAR = '/'; - private static String resourcePath = - getHome() + File.separator + "registry" + File.separator + "governance" + File.separator; + private static String resourcePath = getGovernanceRegistryPath(); private static Marshaller taskMarshaller; private static Unmarshaller taskUnmarshaller; private static final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory(); @@ -84,12 +85,21 @@ public FileBasedTaskRepository(int tenantId, String taskType) { this.taskType = taskType; } - private static String getHome() { - String carbonHome = System.getProperty("carbon.home"); - if (carbonHome == null || "".equals(carbonHome) || ".".equals(carbonHome)) { - carbonHome = getSystemDependentPath(new File(".").getAbsolutePath()); + private static String getGovernanceRegistryPath() { + + String systemStoredGovRegistryPath = System.getProperty("mi.registry.gov"); + try { + URI govRegistryUri = new URI(systemStoredGovRegistryPath); + String governanceRegistryPath = govRegistryUri.getPath(); + if (governanceRegistryPath == null || "".equals(governanceRegistryPath) || ".".equals(governanceRegistryPath)) { + governanceRegistryPath = getSystemDependentPath(new File(".").getAbsolutePath()) + + File.separator + "registry" + File.separator + "governance" + File.separator; + } + return governanceRegistryPath; + } catch (URISyntaxException e) { + log.error("The governance registry path: '" + systemStoredGovRegistryPath + "' is not valid."); + return StringUtils.EMPTY; } - return carbonHome; } private static String getSystemDependentPath(String path) {