From 78a00e934289f4de2c787b91ee3c9a09cd5c14f1 Mon Sep 17 00:00:00 2001 From: Rosen Silva Date: Fri, 29 Dec 2023 21:14:22 +0530 Subject: [PATCH] Fix connector deployment issue in synapse-libs related issue: https://github.com/wso2/micro-integrator/issues/3067 --- .../utils/SynapseArtifactInitUtils.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java index e241d6bbf4..4b79487164 100644 --- a/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java +++ b/components/org.wso2.micro.integrator.initializer/src/main/java/org/wso2/micro/integrator/initializer/utils/SynapseArtifactInitUtils.java @@ -111,11 +111,10 @@ public boolean accept(File dir, String name) { log.error("Error while extracting Connector zip : " + connectorZip.getAbsolutePath(), e); continue; } - String packageName = retrievePackageName(connectorExtractedPath); - - // Retrieve connector name - String connectorName = connectorZip.getName().substring(0, connectorZip.getName().lastIndexOf('-')); - QName qualifiedName = new QName(packageName, connectorName); + QName qualifiedName = retrieveQualifiedConnectorName(connectorExtractedPath); + if (qualifiedName == null) { + continue; + } File importFile = new File(importsDir, qualifiedName.toString() + ".xml"); if (!importFile.exists()) { @@ -155,8 +154,7 @@ private static void generateImportConfig (QName qualifiedName, File targetImport } - private static String retrievePackageName(String extractedPath) { - String packageName = null; + private static QName retrieveQualifiedConnectorName(String extractedPath) { File connectorXml = new File(extractedPath + CONNECTOR_XML); if (!connectorXml.exists()) { log.error("connector.xml file not found at : " + extractedPath); @@ -165,8 +163,11 @@ private static String retrievePackageName(String extractedPath) { try (InputStream xmlInputStream = new FileInputStream(connectorXml)) { OMElement connectorDef = new StAXOMBuilder(xmlInputStream).getDocumentElement(); OMAttribute packageAttr = connectorDef.getFirstElement().getAttribute(new QName("package")); - if (packageAttr != null) { - packageName = packageAttr.getAttributeValue(); + OMAttribute nameAttr = connectorDef.getFirstElement().getAttribute(new QName("name")); + if (nameAttr != null && packageAttr != null) { + String connectorName = nameAttr.getAttributeValue(); + String packageName = packageAttr.getAttributeValue(); + return new QName(packageName, connectorName); } } catch (XMLStreamException e) { log.error("Error while parsing the connector.xml file ", e); @@ -175,7 +176,7 @@ private static String retrievePackageName(String extractedPath) { } catch (IOException e) { log.error("Error occurred while reading: " + connectorXml.getPath()); } - return packageName; + return null; }