Search in sources :

Example 1 with SynapseImport

use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.

the class ImportDeployer method undeploySynapseArtifact.

@Override
public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Undeployment of the Synapse Import named : " + artifactName + " : Started");
    }
    try {
        SynapseImport undeployingImport = getSynapseConfiguration().getSynapseImports().get(artifactName);
        if (undeployingImport != null) {
            getSynapseConfiguration().removeSynapseImport(artifactName);
            // get corresponding library for un-loading this import
            Library synLib = getSynapseConfiguration().getSynapseLibraries().get(artifactName);
            if (synLib != null) {
                // this is a important step -> we need to unload what ever the components loaded thru this import
                synLib.unLoadLibrary();
                synLib.setLibStatus(false);
            }
            log.info("Synapse Import : " + artifactName + "' has been undeployed");
        } else {
            log.warn("Synapse Import : " + artifactName + " has already been undeployed");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Undeployement of Synapse Import named : " + artifactName + " : Failed", e);
    }
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 2 with SynapseImport

use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.

the class ImportDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Synapse Import Deployment from file : " + fileName + " : Started");
    }
    try {
        SynapseImport synImport = SynapseImportFactory.createImport(artifactConfig, properties);
        String synImportQualfiedName = LibDeployerUtils.getQualifiedName(synImport);
        if (synImport == null) {
            handleSynapseArtifactDeploymentError("Synapse Import update failed. The artifact " + "defined in the file: " + fileName + " is not a valid import.");
            return null;
        }
        if (log.isDebugEnabled()) {
            log.debug("Synapse Import: " + synImportQualfiedName + " has been built from the file: " + fileName);
        }
        if (existingArtifactName.equals(synImportQualfiedName)) {
            // normal update ,import Qualified Name(lib name + version) has not changed
            synImport.setFileName((new File(fileName)).getName());
            getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
            // get corresponding library for loading imports if available
            Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
            if (synLib != null) {
                // then reload
                if (synImport.isStatus()) {
                    synLib.unLoadLibrary();
                    LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                } else {
                    synLib.setLibStatus(false);
                    synLib.unLoadLibrary();
                }
            }
            log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
        } else {
            // when updating ,import Qualified Name has been changed !!
            // check for any other import with the same name
            SynapseImport existingImport = getSynapseConfiguration().getSynapseImports().get(synImportQualfiedName);
            if (existingImport != null) {
                // a synapse import with the same name (name + version) already exists
                // we should not allow multiple such imports
                log.warn("Synapse Import with the name : " + synImportQualfiedName + " already exists! " + "Could not load multiple Imports of same type.");
                String backedUp = backupFile(new File(fileName));
                log.info("Synapse Import with the name : " + synImportQualfiedName + " is now backed up in : " + backedUp);
                return null;
            } else {
                synImport.setFileName((new File(fileName)).getName());
                getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
                // get corresponding library for loading imports if available
                Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
                // this is a important step -> we need to unload what ever the components loaded previously
                synLib.unLoadLibrary();
                // then reload
                if (synLib != null) {
                    LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                }
                log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
            }
        }
        log.info("Synapse Import: " + synImportQualfiedName + " has been updated from the file: " + fileName);
        // Give some time for worker threads to release the old sequence
        waitForCompletion();
        return synImportQualfiedName;
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Error while updating the Synapse Import from the " + "file: " + fileName);
    }
    return null;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) File(java.io.File) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 3 with SynapseImport

use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.

the class ImportDeployer method deploySynapseArtifact.

@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
    if (log.isDebugEnabled()) {
        log.debug("Synapse Import Deployment from file : " + fileName + " : Started");
    }
    try {
        SynapseImport synImport = SynapseImportFactory.createImport(artifactConfig, properties);
        String synImportQualfiedName = LibDeployerUtils.getQualifiedName(synImport);
        SynapseImport existingImport = getSynapseConfiguration().getSynapseImports().get(synImportQualfiedName);
        if (existingImport != null) {
            // a synapse import with the same name (name + version) already exists
            // we should not allow multiple such imports
            log.warn("Synapse Import with the name : " + synImportQualfiedName + " already exists! " + "Could not load multiple Imports of same type.");
            String backedUp = backupFile(new File(fileName));
            log.info("Synapse Import with the name : " + synImportQualfiedName + " is now backed up in : " + backedUp);
            return null;
        } else {
            if (synImport != null) {
                synImport.setFileName((new File(fileName)).getName());
                getSynapseConfiguration().addSynapseImport(synImportQualfiedName, synImport);
                // get corresponding library for loading imports if available
                Library synLib = getSynapseConfiguration().getSynapseLibraries().get(synImportQualfiedName);
                if (synLib != null) {
                    if (synImport.isStatus()) {
                        LibDeployerUtils.loadLibArtifacts(synImport, synLib);
                    } else {
                        synLib.setLibStatus(false);
                        synLib.unLoadLibrary();
                    }
                }
                log.info("Synapse Library Import named '" + synImportQualfiedName + " has been deployed from file : " + fileName);
                return synImportQualfiedName;
            } else {
                handleSynapseArtifactDeploymentError("Synapse Import Deployment Failed. " + "The artifact described in the file " + fileName + " is not a valid import");
            }
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Sequence Deployment from the file : " + fileName + " : Failed.", e);
    }
    return null;
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) Library(org.apache.synapse.libraries.model.Library) File(java.io.File) IOException(java.io.IOException) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 4 with SynapseImport

use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.

the class LibraryArtifactDeployer method completeDeployment.

private void completeDeployment(Library lib, String libArtifactName) throws DeploymentException {
    getSynapseConfiguration().addSynapseLibrary(lib.getQName().toString(), lib);
    if (log.isDebugEnabled()) {
        log.debug("Synapse Library Deployment for lib: " + libArtifactName + " Completed");
    }
    // each time a library is deployed we check with available imports and
    // if necessary (ie:- relevant import is available) load the libraries
    SynapseImport synImport = getSynapseConfiguration().getSynapseImports().get(libArtifactName);
    if (synImport != null && synImport.isStatus()) {
        LibDeployerUtils.loadLibArtifacts(synImport, lib);
        if (log.isDebugEnabled()) {
            log.debug("Loading Synapse Library: " + libArtifactName + " into memory for Import");
        }
        LibDeployerUtils.deployingLocalEntries(lib, getSynapseConfiguration());
    }
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport)

Example 5 with SynapseImport

use of org.apache.synapse.libraries.imports.SynapseImport in project wso2-synapse by wso2.

the class SynapseImportFactoryTest method testCreateImport.

/**
 * Test CreateImport method using different XML formats.
 * @throws XMLStreamException
 */
@Test
public void testCreateImport() throws XMLStreamException {
    Properties properties = new Properties();
    OMElement element = AXIOMUtil.stringToOM(XML1);
    try {
        SynapseImportFactory.createImport(element, properties);
        Assert.fail("execution successful where exception is expected");
    } catch (Exception ex) {
        Assert.assertEquals("asserting exception class", SynapseException.class, ex.getClass());
        Assert.assertEquals("asserting exception message", "Synapse Import Target Library name is not specified", ex.getMessage());
    }
    element = AXIOMUtil.stringToOM(XML2);
    try {
        SynapseImportFactory.createImport(element, properties);
        Assert.fail("execution successful where exception is expected");
    } catch (Exception ex) {
        Assert.assertEquals("asserting exception class", SynapseException.class, ex.getClass());
        Assert.assertEquals("asserting exception message", "Synapse Import Target Library package is not specified", ex.getMessage());
    }
    element = AXIOMUtil.stringToOM(XML3);
    SynapseImport synapseImport = SynapseImportFactory.createImport(element, properties);
    Assert.assertFalse("status should be false when status data not provided", synapseImport.isStatus());
    element = AXIOMUtil.stringToOM(XML4);
    synapseImport = SynapseImportFactory.createImport(element, properties);
    Assert.assertTrue("status should be enabled as specified in XML", synapseImport.isStatus());
}
Also used : SynapseImport(org.apache.synapse.libraries.imports.SynapseImport) SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement) Properties(java.util.Properties) XMLStreamException(javax.xml.stream.XMLStreamException) SynapseException(org.apache.synapse.SynapseException) Test(org.junit.Test)

Aggregations

SynapseImport (org.apache.synapse.libraries.imports.SynapseImport)16 OMElement (org.apache.axiom.om.OMElement)6 Library (org.apache.synapse.libraries.model.Library)5 Test (org.junit.Test)5 IOException (java.io.IOException)3 QName (javax.xml.namespace.QName)3 OMAttribute (org.apache.axiom.om.OMAttribute)3 DeploymentException (org.apache.axis2.deployment.DeploymentException)3 SynapseException (org.apache.synapse.SynapseException)3 File (java.io.File)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Properties (java.util.Properties)1 OMFactory (org.apache.axiom.om.OMFactory)1 Startup (org.apache.synapse.Startup)1 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)1 Entry (org.apache.synapse.config.Entry)1