From 173438d199ce0aa2bc03e28218eeb609d9ec92bb Mon Sep 17 00:00:00 2001 From: Arunan Date: Mon, 16 Dec 2024 15:01:15 +0530 Subject: [PATCH] Improve CApp classloader to handle connector dependencies --- .../deployer/CarbonApplication.java | 9 +++++++ .../synapse/deployer/SynapseAppDeployer.java | 24 ++++++++++++------- 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/components/org.wso2.micro.integrator.core/src/main/java/org/wso2/micro/application/deployer/CarbonApplication.java b/components/org.wso2.micro.integrator.core/src/main/java/org/wso2/micro/application/deployer/CarbonApplication.java index 652ac0bc70..c9e00c20e2 100644 --- a/components/org.wso2.micro.integrator.core/src/main/java/org/wso2/micro/application/deployer/CarbonApplication.java +++ b/components/org.wso2.micro.integrator.core/src/main/java/org/wso2/micro/application/deployer/CarbonApplication.java @@ -32,6 +32,7 @@ public class CarbonApplication { private String appVersion; private boolean deploymentCompleted; private String mainSequence; + private ClassLoader classLoader; private ApplicationConfiguration appConfig; @@ -109,5 +110,13 @@ public String getMainSequence() { public void setMainSequence(String mainSequence) { this.mainSequence = mainSequence; } + + public ClassLoader getClassLoader() { + return classLoader; + } + + public void setClassLoader(ClassLoader classLoader) { + this.classLoader = classLoader; + } } diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java index 4e17173cf2..cf21f8cf28 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/deployment/synapse/deployer/SynapseAppDeployer.java @@ -129,8 +129,8 @@ public void deployArtifacts(CarbonApplication carbonApp, AxisConfiguration axisC List artifacts = carbonApp.getAppConfig().getApplicationArtifact() .getDependencies(); - deployClassMediators(artifacts, axisConfig); - deploySynapseLibrary(artifacts, axisConfig); + deployClassMediators(artifacts, axisConfig, carbonApp); + deploySynapseLibrary(artifacts, axisConfig, carbonApp); Map> artifactTypeMap = getOrderedArtifactsMap(artifacts); //deploy artifacts @@ -335,8 +335,8 @@ && handleMainFaultSeqUndeployment(artifact, axisConfig)) { * @param axisConfig AxisConfiguration of the current tenant * @throws DeploymentException if something goes wrong while deployment */ - private void deployClassMediators(List artifacts, - AxisConfiguration axisConfig) throws DeploymentException { + private void deployClassMediators(List artifacts, AxisConfiguration axisConfig, + CarbonApplication carbonApplication) throws DeploymentException { for (Artifact.Dependency dependency : artifacts) { Artifact artifact = dependency.getArtifact(); @@ -354,7 +354,9 @@ private void deployClassMediators(List artifacts, String artifactPath = artifact.getExtractedPath() + File.separator + fileName; try { - deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer)); + DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer); + deploymentFileData.setClassLoader(carbonApplication.getClassLoader()); + deployer.deploy(deploymentFileData); artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED); } catch (DeploymentException e) { artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED); @@ -372,8 +374,8 @@ private void deployClassMediators(List artifacts, * @param axisConfig AxisConfiguration of the current tenant * @throws DeploymentException if something goes wrong while deployment */ - private void deploySynapseLibrary(List artifacts, - AxisConfiguration axisConfig) throws DeploymentException { + private void deploySynapseLibrary(List artifacts, AxisConfiguration axisConfig, + CarbonApplication carbonApplication) throws DeploymentException { for (Artifact.Dependency dependency : artifacts) { Artifact artifact = dependency.getArtifact(); @@ -397,7 +399,9 @@ private void deploySynapseLibrary(List artifacts, artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED); } else { try { - deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer)); + DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer); + deploymentFileData.setClassLoader(carbonApplication.getClassLoader()); + deployer.deploy(deploymentFileData); artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED); try { String artifactName = getArtifactName(artifactPath, axisConfig); @@ -1122,7 +1126,9 @@ public void deployArtifactType(List artifacts, CarbonApplic } else { try { setCustomLogContent(deployer, carbonApp); - deployer.deploy(new DeploymentFileData(new File(artifactPath), deployer)); + DeploymentFileData deploymentFileData = new DeploymentFileData(new File(artifactPath), deployer); + deploymentFileData.setClassLoader(carbonApp.getClassLoader()); + deployer.deploy(deploymentFileData); artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_DEPLOYED); } catch (DeploymentException e) { artifact.setDeploymentStatus(AppDeployerConstants.DEPLOYMENT_STATUS_FAILED);