diff --git a/.gitignore b/.gitignore index 4dfe2e2c29..b57fa07ebf 100644 --- a/.gitignore +++ b/.gitignore @@ -103,6 +103,7 @@ typings/ # dotenv environment variables file .env .env.test +!test.env # parcel-bundler cache (https://parceljs.org/) .cache diff --git a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/test/java/org/wso2/micro/integrator/management/apis/security/handler/TestMessageContext.java b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/test/java/org/wso2/micro/integrator/management/apis/security/handler/TestMessageContext.java index 31d033f6b1..b11e9e6a28 100644 --- a/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/test/java/org/wso2/micro/integrator/management/apis/security/handler/TestMessageContext.java +++ b/components/org.wso2.micro.integrator.extensions/org.wso2.micro.integrator.management.apis/src/test/java/org/wso2/micro/integrator/management/apis/security/handler/TestMessageContext.java @@ -387,6 +387,21 @@ public String getMessageString() { public void setMessageFlowTracingState(int tracingState){ } + @Override + public Object getVariable(String s) { + return null; + } + + @Override + public void setVariable(String s, Object o) { + // + } + + @Override + public Set getVariableKeySet() { + return null; + } + public int getMessageFlowTracingState(){ return SynapseConstants.TRACING_OFF; } diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/AppDeployerServiceComponent.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/AppDeployerServiceComponent.java index 6c5cf96d29..f93c5e4cc9 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/AppDeployerServiceComponent.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/AppDeployerServiceComponent.java @@ -37,6 +37,7 @@ import org.wso2.micro.integrator.initializer.StartupFinalizer; import org.wso2.micro.integrator.initializer.dashboard.HeartBeatComponent; import org.wso2.micro.integrator.initializer.deployment.application.deployer.CappDeployer; +import org.wso2.micro.integrator.initializer.deployment.config.deployer.ConfigDeployer; import org.wso2.micro.integrator.initializer.deployment.synapse.deployer.FileRegistryResourceDeployer; import org.wso2.micro.integrator.initializer.deployment.synapse.deployer.SynapseAppDeployer; import org.wso2.micro.integrator.initializer.deployment.user.store.deployer.UserStoreDeployer; @@ -169,6 +170,7 @@ private void addCAppDeployer(DeploymentEngine deploymentEngine) { cappDeployer.init(configCtx); // Register application deployment handlers + cappDeployer.registerDeploymentHandler(new ConfigDeployer()); cappDeployer.registerDeploymentHandler(new FileRegistryResourceDeployer( synapseEnvironmentService.getSynapseEnvironment().getSynapseConfiguration().getRegistry())); cappDeployer.registerDeploymentHandler(new DataSourceCappDeployer()); diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/config/deployer/ConfigDeployer.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/config/deployer/ConfigDeployer.java new file mode 100644 index 0000000000..b9a62620d2 --- /dev/null +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/config/deployer/ConfigDeployer.java @@ -0,0 +1,259 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.micro.integrator.initializer.deployment.config.deployer; + +import org.apache.axis2.deployment.DeploymentException; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.synapse.commons.property.PropertyHolder; +import org.apache.synapse.transport.nhttp.config.SslSenderTrustStoreHolder; +import org.wso2.micro.application.deployer.CarbonApplication; +import org.wso2.micro.application.deployer.config.ApplicationConfiguration; +import org.wso2.micro.application.deployer.config.Artifact; +import org.wso2.micro.application.deployer.config.CappFile; +import org.wso2.micro.application.deployer.handler.AppDeploymentHandler; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileWriter; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.cert.Certificate; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.Properties; + +public class ConfigDeployer implements AppDeploymentHandler { + + private static final Log log = LogFactory.getLog(ConfigDeployer.class); + + private static final String PROPERTY_TYPE = "config/property"; + + private static final String LOCAL_CONFIG_FILE_NAME = "config.properties"; + private static final String GLOBAL_CONFIG_FILE_NAME = "file.properties"; + private Properties globalProperties; + + public static final char URL_SEPARATOR_CHAR = '/'; + + public ConfigDeployer() { + } + + @Override + public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) + throws DeploymentException { + if (log.isDebugEnabled()) { + log.debug("Deploying properties - " + carbonApp.getAppName()); + } + ApplicationConfiguration appConfig = carbonApp.getAppConfig(); + List deps = appConfig.getApplicationArtifact().getDependencies(); + + List artifacts = new ArrayList(); + for (Artifact.Dependency dep : deps) { + if (dep.getArtifact() != null) { + artifacts.add(dep.getArtifact()); + } + } + deployConfigArtifacts(artifacts); + } + + @Override + public void undeployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisConfig) + throws DeploymentException { + + } + + private void deployConfigArtifacts(List artifacts) { + artifacts.stream().filter(artifact -> PROPERTY_TYPE.equals(artifact.getType())).forEach(artifact -> { + if (log.isDebugEnabled()) { + log.debug("Deploying config artifact: " + artifact.getName()); + } + writePropertyToMap(artifact); + }); + } + + private void writePropertyToMap(Artifact artifact) { + // get the file path of the registry config file + List files = artifact.getFiles(); + if (files.size() == 1) { + Path confFolder = Paths.get(getHome(), "conf"); + Path globalPropertiesFilePath = confFolder.resolve(GLOBAL_CONFIG_FILE_NAME) ; + Path serverConfPropertyPath = confFolder.resolve(LOCAL_CONFIG_FILE_NAME); + String configFilePath = artifact.getExtractedPath() + File.separator + LOCAL_CONFIG_FILE_NAME; + processConfFile(artifact.getName(), configFilePath, globalPropertiesFilePath.toString(), + serverConfPropertyPath.toString()); + } else { + log.error("config/property type must have a single file which declares " + + "config. But " + files.size() + " files found."); + } + } + + private void processConfFile(String integrationName, String configFilePath, String globalPropertiesFilePath, + String serverConfPropertyPath) { + File configFile = new File(configFilePath); + // Load capp conf property file + Properties configProperties = loadPropertiesFromFile(configFile); + // Load global conf property file + this.globalProperties = loadPropertiesFromFile(new File(globalPropertiesFilePath)); + // Load sever conf property file + Properties serverConfigProperties = loadPropertiesFromFile(new File(serverConfPropertyPath)); + + Properties newServerConfigProperties = new Properties(); + if (serverConfigProperties.isEmpty() && configProperties.isEmpty() ) { + if (log.isDebugEnabled()) { + log.debug(String.format("No configuration is used in the integration[%s]", integrationName)); + } + } else { + for (Map.Entry entry : serverConfigProperties.entrySet()) { + String key = entry.getKey().toString(); + String type = entry.getValue().toString(); + if (configProperties.containsKey(key)) { + type = configProperties.getProperty(key); + configProperties.remove(key); + } + newServerConfigProperties.setProperty(key, type); + processConfigProperties(key, type); + } + for (Map.Entry entry : configProperties.entrySet()) { + String key = entry.getKey().toString(); + String type = entry.getValue().toString(); + newServerConfigProperties.setProperty(key, type); + processConfigProperties(key, type); + } + writeServerConfFile(serverConfPropertyPath, newServerConfigProperties); + } + } + + private void processConfigProperties(String key, String type) { + String value = getValueOfKey(key); + if (value != null) { + if (Objects.equals(type, "cert")) { + deployCert(key, value); + } + if (PropertyHolder.getInstance().hasKey(key)) { + String oldValue = PropertyHolder.getInstance().getPropertyValue(key); + if (!Objects.equals(oldValue, value)) { + log.info(String.format("The value of the key:[%s] has been " + + "replaced with the new value.", key)); + } + } + PropertyHolder.getInstance().setProperty(key, value); + } else { + log.error(String.format("The value of the key:[%s] is not found.", key)); + } + } + + private void deployCert(String key, String path) { + // Load the truststore properties + char[] password = SslSenderTrustStoreHolder.getInstance().getPassword().toCharArray(); + String type = SslSenderTrustStoreHolder.getInstance().getType(); + Path trustStorePath = Paths.get(getHome(), SslSenderTrustStoreHolder.getInstance().getLocation()); + try (FileInputStream trustStoreStream = new FileInputStream(trustStorePath.toFile())) { + KeyStore trustStore = KeyStore.getInstance(type); + trustStore.load(trustStoreStream, password); + if (!trustStore.containsAlias(key)) { + // Load the certificate file + CertificateFactory certFactory = CertificateFactory.getInstance("X.509"); + try (FileInputStream certStream = new FileInputStream(path)) { + Certificate cert = certFactory.generateCertificate(certStream); + // Add the certificate to the truststore + trustStore.setCertificateEntry(key, cert); + log.info("Certificate added with alias: " + key); + } + // Save the truststore with the new certificate + try (FileOutputStream outputStream = new FileOutputStream(trustStorePath.toFile())) { + trustStore.store(outputStream, password); + log.info("Truststore updated successfully at: " + trustStorePath); + } + } else { + log.info(String.format("The trust store already contains a certificate " + + "with the alias [%s].", key)); + } + } catch (FileNotFoundException e) { + log.error(String.format("File not found for importing the certificate: %s", key)); + } catch (IOException e) { + log.error(String.format("Certificate import failed: %s", key)); + } catch (CertificateException e) { + log.error(String.format("An error occurred while processing the certificate: %s", key)); + } catch (KeyStoreException e) { + log.error(String.format("An error occurred while processing the truststore: %s", key)); + } catch (NoSuchAlgorithmException e) { + log.error(String.format("An error occurred while loading the certificate: %s", key)); + } + } + + private void writeServerConfFile(String file, Properties newServerConfigProperties) { + try (FileWriter writer = new FileWriter(file)) { + Enumeration propertyNames = newServerConfigProperties.propertyNames(); + while (propertyNames.hasMoreElements()) { + String key = (String) propertyNames.nextElement(); + String value = newServerConfigProperties.getProperty(key); + writer.write(key + ":" + value + "\n"); + } + } catch (IOException e) { + log.error("Failed to add the config.properties file to the server conf folder: " + + e.getMessage()); + } + } + + private Properties loadPropertiesFromFile(File file) { + Properties properties = new Properties(); + if (file.exists()) { + try (FileInputStream serverConfigFileReader = new FileInputStream(file)) { + properties.load(serverConfigFileReader); + } catch (IOException e) { + log.error("Error occurred while loading properties from file:" + e.getMessage()); + } + } + return properties; + } + + private String getValueOfKey(String key) { + String value = System.getenv(key); + if (value == null) { + value = System.getProperty(key); + if (value == null) { + value = this.globalProperties.getProperty(key); + } + } + return value; + } + + private String getHome() { + String carbonHome = System.getProperty("carbon.home"); + if (carbonHome == null || "".equals(carbonHome) || ".".equals(carbonHome)) { + carbonHome = getSystemDependentPath(new File(".").getAbsolutePath()); + } + return carbonHome; + } + + private String getSystemDependentPath(String path) { + return path.replace(URL_SEPARATOR_CHAR, File.separatorChar); + } +} diff --git a/distribution/src/scripts/micro-integrator.bat b/distribution/src/scripts/micro-integrator.bat index d67fb29b2e..001fecea91 100644 --- a/distribution/src/scripts/micro-integrator.bat +++ b/distribution/src/scripts/micro-integrator.bat @@ -103,6 +103,12 @@ if ""%1""==""car"" goto setCar if ""%1""==""-car"" goto setCar if ""%1""==""--car"" goto setCar +@REM Check if the argument starts with --env-file= +set "envfile=%~1" +if "!envfile:~0,11!"=="--env-file=" ( + set "file_path=!envfile:~11!" + call :export_env_file "!file_path!" +) shift goto setupArgs @@ -133,6 +139,40 @@ echo Stopping the Micro Integrator Server taskkill /F /PID %processId% goto end +:export_env_file +setlocal EnableDelayedExpansion + +set "file_path=%~1" + +REM Check if the file exists +if not exist "!file_path!" ( + echo Error: File '!file_path!' not found. + exit /b 1 +) + +REM Read each line in the file +for /f "usebackq tokens=1,* delims==" %%A in ("!file_path!") do ( + set "line=%%A" + + REM Ignore lines that start with '#' (comments) or are empty + if not "!line!"=="" ( + if "!line:~0,1!" neq "#" ( + set "key=%%A" + set "value=%%B" + + REM Trim surrounding whitespace from key and value + for /f "tokens=* delims= " %%i in ("!key!") do set "key=%%i" + for /f "tokens=* delims= " %%i in ("!value!") do set "value=%%i" + + REM Set the environment variable + setx "!key!" "!value!" >nul + set "!key!=!value!" + ) + ) +) +echo Environment variables loaded from !file_path!. +exit /b 0 + rem ----- commandLifecycle ----------------------------------------------------- :commandLifecycle goto findJdk diff --git a/distribution/src/scripts/micro-integrator.sh b/distribution/src/scripts/micro-integrator.sh index 3b483e8701..853048427a 100644 --- a/distribution/src/scripts/micro-integrator.sh +++ b/distribution/src/scripts/micro-integrator.sh @@ -118,6 +118,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -142,6 +174,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$ARGUMENT" = "car" ]; then diff --git a/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/CarbonServerExtension.java b/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/CarbonServerExtension.java index fa74436514..183d10cb01 100644 --- a/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/CarbonServerExtension.java +++ b/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/CarbonServerExtension.java @@ -27,6 +27,7 @@ import org.wso2.carbon.automation.extensions.ExtensionConstants; import javax.xml.xpath.XPathExpressionException; +import java.util.Map; public class CarbonServerExtension extends ExecutionListenerExtension { private static TestServerManager serverManager; @@ -80,6 +81,14 @@ public static void restartServer() { } } + public static void restartServer(Map commandMap) { + try { + serverManager.restartServer(commandMap); + } catch (AutomationFrameworkException e) { + throw new RuntimeException("Exception occurred while restarting the server", e); + } + } + public static void startServer() { try { serverManager.startMIServer(); diff --git a/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/TestServerManager.java b/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/TestServerManager.java index 6379fdfbc6..8d4363d836 100644 --- a/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/TestServerManager.java +++ b/integration/automation-extensions/src/main/java/org/wso2/esb/integration/common/extensions/carbonserver/TestServerManager.java @@ -153,6 +153,14 @@ void restartServer() throws AutomationFrameworkException { log.info("Server restarted successfully ..."); } + void restartServer(Map commands) throws AutomationFrameworkException { + log.info("Preparing to restart the server ..."); + commandMap.putAll(commands); + carbonServer.serverShutdown(portOffset, true); + carbonServer.startServerUsingCarbonHome(carbonHome, commandMap); + log.info("Server restarted successfully ..."); + } + void startMIServer() throws AutomationFrameworkException { log.info("Preparing to start the MI server ..."); diff --git a/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/bin/integrator.sh b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/bin/integrator.sh +++ b/integration/dataservice-hosting-tests/tests-integration/tests/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-mediator-1/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-mediator-1/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-mediator-1/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-mediator-1/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-mediator-2/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-mediator-2/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-mediator-2/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-mediator-2/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/api/ApiWithConfigurablePropertyTestCase.java b/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/api/ApiWithConfigurablePropertyTestCase.java new file mode 100644 index 0000000000..4f978b7816 --- /dev/null +++ b/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/api/ApiWithConfigurablePropertyTestCase.java @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.esb.resource.test.api; + +import org.apache.commons.lang3.StringUtils; +import org.junit.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; +import org.wso2.esb.integration.common.utils.CarbonLogReader; +import org.wso2.esb.integration.common.utils.ESBIntegrationTest; +import org.wso2.esb.integration.common.utils.Utils; +import org.wso2.esb.integration.common.utils.common.ServerConfigurationManager; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertTrue; + +public class ApiWithConfigurablePropertyTestCase extends ESBIntegrationTest { + + private ServerConfigurationManager serverConfigurationManager; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + CarbonLogReader carbonLogReader = new CarbonLogReader(); + carbonLogReader.start(); + serverConfigurationManager = new ServerConfigurationManager(context); + File capp = new File(getESBResourceLocation() + File.separator + "config.var" + File.separator + + "testApiWithConfigurationProperty_1.0.0.car"); + serverConfigurationManager.copyToCarbonapps(capp); + assertTrue(Utils.checkForLog(carbonLogReader, "Successfully Deployed Carbon Application : " + + "testApiWithConfigurationProperty_1.0.0", 20), "Did not receive the expected info log"); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 1) + public void testConfigurablePropertyWithFile() throws IOException { + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("apiConfig/test_api")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(StringUtils.normalizeSpace(httpResponse.getData()), + StringUtils.normalizeSpace("{ \"name\": \"file\", \"msg\": \"Gd mng\" }"), + StringUtils.normalizeSpace(httpResponse.getData())); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 2) + public void testConfigurablePropertyWithSystemProperty() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("-Dname", "sys"); + commands.put("-Dmsg", "Hi"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("apiConfig/test_api")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(StringUtils.normalizeSpace(httpResponse.getData()), + StringUtils.normalizeSpace("{ \"name\": \"sys\", \"msg\": \"Hi\" }"), + StringUtils.normalizeSpace(httpResponse.getData())); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 3) + public void testConfigurablePropertyWithEnvVariable() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("apiConfig/test_api")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(StringUtils.normalizeSpace(httpResponse.getData()), + StringUtils.normalizeSpace("{ \"name\": \"env\", \"msg\": \"Hello\" }"), + StringUtils.normalizeSpace(httpResponse.getData())); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 4) + public void testConfigurableProperty() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("-Dname", "sys"); + commands.put("-Dmsg", "Hi"); + commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("apiConfig/test_api")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(StringUtils.normalizeSpace(httpResponse.getData()), + StringUtils.normalizeSpace("{ \"name\": \"env\", \"msg\": \"Hello\" }"), + StringUtils.normalizeSpace(httpResponse.getData())); + } + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + serverConfigurationManager.removeFromCarbonapps("testApiWithConfigurationProperty_1.0.0.car"); + super.cleanup(); + } +} diff --git a/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/endpoint/EndpointWithConfigurablePropertyTestCase.java b/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/endpoint/EndpointWithConfigurablePropertyTestCase.java new file mode 100644 index 0000000000..d9a9bf32a7 --- /dev/null +++ b/integration/mediation-tests/tests-other/src/test/java/org/wso2/carbon/esb/resource/test/endpoint/EndpointWithConfigurablePropertyTestCase.java @@ -0,0 +1,112 @@ +/* + * Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). + * + * WSO2 LLC. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.esb.resource.test.endpoint; + +import org.junit.Assert; +import org.testng.annotations.AfterClass; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.automation.engine.frameworkutils.FrameworkPathUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpRequestUtil; +import org.wso2.carbon.automation.test.utils.http.client.HttpResponse; +import org.wso2.carbon.integration.common.utils.exceptions.AutomationUtilException; +import org.wso2.esb.integration.common.utils.CarbonLogReader; +import org.wso2.esb.integration.common.utils.ESBIntegrationTest; +import org.wso2.esb.integration.common.utils.Utils; +import org.wso2.esb.integration.common.utils.common.ServerConfigurationManager; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.HashMap; +import java.util.Map; + +import static org.testng.Assert.assertTrue; + +public class EndpointWithConfigurablePropertyTestCase extends ESBIntegrationTest { + + private ServerConfigurationManager serverConfigurationManager; + + @BeforeClass(alwaysRun = true) + public void init() throws Exception { + super.init(); + CarbonLogReader carbonLogReader = new CarbonLogReader(); + carbonLogReader.start(); + serverConfigurationManager = new ServerConfigurationManager(context); + File capp = new File(getESBResourceLocation() + File.separator + "config.var" + File.separator + + "testConfiguration_1.0.0.car"); + serverConfigurationManager.copyToCarbonapps(capp); + assertTrue(Utils.checkForLog(carbonLogReader, "Successfully Deployed Carbon Application : " + + "testConfiguration_1.0.0", 20), "Did not receive the expected info log"); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 1) + public void testConfigurablePropertyWithFile() throws IOException { + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("getdata/file")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(httpResponse.getData(), "{\"msg\": \"file\"}", httpResponse.getData()); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 2) + public void testConfigurablePropertyWithSystemProperty() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("-Dendpoint_url", "http://localhost:8480/endpoint/sys"); + commands.put("-Dcommon_url", "http://localhost:8480/endpoint/sys"); + commands.put("-Durl", "http://localhost:8480/endpoint/sys"); + commands.put("-Durl_value", "http://localhost:8480/endpoint/sys"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("getdata/sys")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(httpResponse.getData(), "{\"msg\": \"sys\"}", httpResponse.getData()); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 3) + public void testConfigurablePropertyWithEnvVariable() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("getdata/env")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(httpResponse.getData(), "{\"msg\": \"env\"}", httpResponse.getData()); + } + + @Test(groups = {"wso2.esb"}, description = "Configurable property", priority = 4) + public void testConfigurableProperty() throws IOException, AutomationUtilException { + Map commands = new HashMap<>(); + commands.put("-Dcommon_url", "http://localhost:8480/endpoint/sys"); + commands.put("--env-file", FrameworkPathUtil.getSystemResourceLocation() + "test.env"); + serverConfigurationManager.restartMicroIntegrator(commands); + Map headers = new HashMap<>(); + URL endpoint = new URL(getApiInvocationURL("getdata/common")); + HttpResponse httpResponse = HttpRequestUtil.doGet(endpoint.toString(), headers); + Assert.assertEquals(httpResponse.getResponseCode(), 200); + Assert.assertEquals(httpResponse.getData(), "{\"msg\": \"hi\"}", httpResponse.getData()); + } + + @AfterClass(alwaysRun = true) + public void destroy() throws Exception { + serverConfigurationManager.removeFromCarbonapps("testConfiguration_1.0.0.car"); + super.cleanup(); + } +} diff --git a/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testApiWithConfigurationProperty_1.0.0.car b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testApiWithConfigurationProperty_1.0.0.car new file mode 100644 index 0000000000..298a9709be Binary files /dev/null and b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testApiWithConfigurationProperty_1.0.0.car differ diff --git a/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testConfiguration_1.0.0.car b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testConfiguration_1.0.0.car new file mode 100644 index 0000000000..8f089dff1c Binary files /dev/null and b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/config.var/testConfiguration_1.0.0.car differ diff --git a/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/server/conf/file.properties b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/server/conf/file.properties new file mode 100644 index 0000000000..b8bcc0c574 --- /dev/null +++ b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/server/conf/file.properties @@ -0,0 +1,25 @@ +# +# Copyright (c) 2024, WSO2 LLC. (https://www.wso2.com). +# +# WSO2 LLC. licenses this file to you under the Apache License, +# Version 2.0 (the "License"); you may not use this file except +# in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +#/ + +stockQuoteEP=http://localhost:9000/services/SimpleStockQuoteService +common_url=http://localhost:8480/endpoint/file +url=http://localhost:8480/endpoint/file +endpoint_url=http://localhost:8290/endpoint/file +url_value=http://localhost:8290/endpoint/file +name=file +msg= Gd mng diff --git a/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/serviceCatalog/micro-integrator.sh b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/serviceCatalog/micro-integrator.sh index 3d268f53e1..2d9b951789 100755 --- a/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/serviceCatalog/micro-integrator.sh +++ b/integration/mediation-tests/tests-other/src/test/resources/artifacts/ESB/serviceCatalog/micro-integrator.sh @@ -118,6 +118,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -139,6 +171,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then @@ -192,9 +234,10 @@ fi # ---------- Handle the SSL Issue with proper JDK version -------------------- java_version=$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}') java_version_formatted=$(echo "$java_version" | awk -F. '{printf("%02d%02d",$1,$2);}') -if [ $java_version_formatted -lt 0107 ] || [ $java_version_formatted -gt 1100 ]; then +if [ $java_version_formatted -lt 1100 ] || [ $java_version_formatted -gt 2100 ]; then echo " Starting WSO2 MI (in unsupported JDK)" - echo " [ERROR] MI is supported only on JDK 1.8, 9, 10 and 11" + echo " [ERROR] WSO2 MI is supported only between JDK 11 and JDK 21" + exit 0 fi CARBON_XBOOTCLASSPATH="" diff --git a/integration/mediation-tests/tests-other/src/test/resources/test.env b/integration/mediation-tests/tests-other/src/test/resources/test.env new file mode 100644 index 0000000000..ce5957c4bd --- /dev/null +++ b/integration/mediation-tests/tests-other/src/test/resources/test.env @@ -0,0 +1,6 @@ +name=env +msg=Hello +common_url=http://localhost:8480/endpoint/common +url_value=http://localhost:8480/endpoint/env +url=http://localhost:8480/endpoint/file +endpoint_url=http://localhost:8480/endpoint/sys diff --git a/integration/mediation-tests/tests-patches-with-smb2/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-patches-with-smb2/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-patches-with-smb2/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-patches-with-smb2/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/passthru/transport/enableCorrelation/micro-integrator.sh b/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/passthru/transport/enableCorrelation/micro-integrator.sh index 01ffcb3087..0ad5ba74ee 100644 --- a/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/passthru/transport/enableCorrelation/micro-integrator.sh +++ b/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/passthru/transport/enableCorrelation/micro-integrator.sh @@ -118,6 +118,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -139,6 +171,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/vfs/micro-integrator.sh b/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/vfs/micro-integrator.sh index 6c65c36eaa..bfa2908c4b 100755 --- a/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/vfs/micro-integrator.sh +++ b/integration/mediation-tests/tests-patches/src/test/resources/artifacts/ESB/vfs/micro-integrator.sh @@ -118,6 +118,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -142,6 +174,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$ARGUMENT" = "car" ]; then diff --git a/integration/mediation-tests/tests-patches/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-patches/src/test/resources/bin/integrator.sh index 2a6a189918..a64b37ca1c 100755 --- a/integration/mediation-tests/tests-patches/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-patches/src/test/resources/bin/integrator.sh @@ -136,6 +136,37 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +190,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-platform/tests-rabbitmq/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-platform/tests-rabbitmq/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-platform/tests-rabbitmq/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-platform/tests-rabbitmq/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-platform/tests-userstore/src/test/resources/artifacts/ESB/server/bin/micro-integrator.sh b/integration/mediation-tests/tests-platform/tests-userstore/src/test/resources/artifacts/ESB/server/bin/micro-integrator.sh index 370944c5ed..b8800d84eb 100755 --- a/integration/mediation-tests/tests-platform/tests-userstore/src/test/resources/artifacts/ESB/server/bin/micro-integrator.sh +++ b/integration/mediation-tests/tests-platform/tests-userstore/src/test/resources/artifacts/ESB/server/bin/micro-integrator.sh @@ -118,6 +118,37 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -139,6 +170,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then @@ -192,9 +233,10 @@ fi # ---------- Handle the SSL Issue with proper JDK version -------------------- java_version=$("$JAVACMD" -version 2>&1 | awk -F '"' '/version/ {print $2}') java_version_formatted=$(echo "$java_version" | awk -F. '{printf("%02d%02d",$1,$2);}') -if [ $java_version_formatted -lt 0107 ] || [ $java_version_formatted -gt 1100 ]; then +if [ $java_version_formatted -lt 1100 ] || [ $java_version_formatted -gt 2100 ]; then echo " Starting WSO2 MI (in unsupported JDK)" - echo " [ERROR] MI is supported only on JDK 1.8, 9, 10 and 11" + echo " [ERROR] WSO2 MI is supported only between JDK 11 and JDK 21" + exit 0 fi CARBON_XBOOTCLASSPATH="" diff --git a/integration/mediation-tests/tests-platform/tests-wso2mb/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-platform/tests-wso2mb/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-platform/tests-wso2mb/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-platform/tests-wso2mb/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-sample/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-sample/src/test/resources/bin/integrator.sh index 2a6a189918..a64b37ca1c 100755 --- a/integration/mediation-tests/tests-sample/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-sample/src/test/resources/bin/integrator.sh @@ -136,6 +136,37 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +190,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-service/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-service/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-service/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-service/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/mediation-tests/tests-transport/src/test/resources/bin/integrator.sh b/integration/mediation-tests/tests-transport/src/test/resources/bin/integrator.sh index 2a6a189918..5aeb5c0a4d 100755 --- a/integration/mediation-tests/tests-transport/src/test/resources/bin/integrator.sh +++ b/integration/mediation-tests/tests-transport/src/test/resources/bin/integrator.sh @@ -136,6 +136,38 @@ if [ -e "$CARBON_HOME/wso2carbon.pid" ]; then fi # ----- Process the input command ---------------------------------------------- + +# Function to export variables from the given .env file +export_env_file() { + local file_path="$1" + + # Check if the file exists + if [ ! -f "$file_path" ]; then + echo "Error: File '$file_path' not found." + return 1 # Return with an error status + fi + + # Read the .env file and export each variable to the environment + while IFS='=' read -r key value; do + # Ignore lines starting with '#' (comments) or empty lines + case "$key" in + \#*|"") + # Skip comments or empty lines + continue + ;; + *) + # Trim surrounding whitespace from key and value + key=$(echo "$key" | xargs) + value=$(echo "$value" | xargs) + # Export the key-value pair to the environment + export "$key=$value" + ;; + esac + done < "$file_path" + + echo "Environment variables loaded from $file_path." +} + args="" for c in $* do @@ -159,6 +191,16 @@ do else args="$args $c" fi + # Check if the argument starts with --env-file= + case "$c" in + --env-file=*) + file_path="${c#--env-file=}" + export_env_file "$file_path" + ;; + *) + continue + ;; + esac done if [ "$CMD" = "--debug" ]; then diff --git a/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/common/ServerConfigurationManager.java b/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/common/ServerConfigurationManager.java index be512b3327..265a80455d 100644 --- a/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/common/ServerConfigurationManager.java +++ b/integration/tests-common/integration-test-utils/src/main/java/org/wso2/esb/integration/common/utils/common/ServerConfigurationManager.java @@ -46,6 +46,7 @@ import java.time.Duration; import java.util.ArrayList; import java.util.List; +import java.util.Map; import java.util.Properties; import java.util.function.BooleanSupplier; import javax.xml.xpath.XPathExpressionException; @@ -388,6 +389,10 @@ public void restartMicroIntegrator() throws AutomationUtilException { org.wso2.esb.integration.common.extensions.carbonserver.CarbonServerExtension.restartServer(); } + public void restartMicroIntegrator(Map commandMap) throws AutomationUtilException { + org.wso2.esb.integration.common.extensions.carbonserver.CarbonServerExtension.restartServer(commandMap); + } + /** * Restart Server Gracefully from admin user * diff --git a/pom.xml b/pom.xml index c94e368b3e..b56428be11 100644 --- a/pom.xml +++ b/pom.xml @@ -1606,7 +1606,6 @@ 2.4.0-b180830.0359 2.3.0 2.3.1 - 4.0.0-wso2v143 [4.0.0, 4.0.1) 4.7.215