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);
}
}
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;
}
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;
}
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());
}
}
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());
}
Aggregations