use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class Axis2MessageContext method getSequenceTemplate.
public Mediator getSequenceTemplate(String key) {
Object o = localEntries.get(key);
if (o != null && o instanceof Mediator) {
return (Mediator) o;
} else {
Mediator m = getConfiguration().getSequenceTemplate(key);
if (m instanceof TemplateMediator) {
TemplateMediator templateMediator = (TemplateMediator) m;
synchronized (m) {
if (!templateMediator.isInitialized()) {
templateMediator.init(synEnv);
}
}
}
localEntries.put(key, m);
return m;
}
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class TemplateDeployer method deploySynapseArtifact.
@Override
public String deploySynapseArtifact(OMElement artifactConfig, String fileName, Properties properties) {
if (log.isDebugEnabled()) {
log.debug("Template Deployment from file : " + fileName + " : Started");
}
try {
OMElement element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
if (element != null) {
org.apache.synapse.config.xml.endpoints.TemplateFactory templateFactory = new org.apache.synapse.config.xml.endpoints.TemplateFactory();
Template tm = templateFactory.createEndpointTemplate(artifactConfig, properties);
tm.setFileName(new File(fileName).getName());
/**
* Set the artifact container name of the Template
*/
tm.setArtifactContainerName(customLogContent);
if (log.isDebugEnabled()) {
log.debug("Endpoint Template named '" + tm.getName() + "' has been built from the file " + fileName);
}
getSynapseConfiguration().addEndpointTemplate(tm.getName(), tm);
if (log.isDebugEnabled()) {
log.debug("Template Deployment from file : " + fileName + " : Completed");
}
log.info("Endpoint Template named '" + tm.getName() + "' has been deployed from file : " + fileName);
return tm.getName();
} else {
element = artifactConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "sequence"));
if (element != null) {
Mediator mediator = MediatorFactoryFinder.getInstance().getMediator(artifactConfig, properties);
if (mediator instanceof TemplateMediator) {
TemplateMediator tm = (TemplateMediator) mediator;
/**
* Set the artifact container name of the Template
*/
tm.setArtifactContainerName(customLogContent);
tm.setFileName((new File(fileName)).getName());
if (log.isDebugEnabled()) {
log.debug("Sequence Template named '" + tm.getName() + "' has been built from the file " + fileName);
}
tm.init(getSynapseEnvironment());
if (log.isDebugEnabled()) {
log.debug("Initialized the Template : " + tm.getName());
}
getSynapseConfiguration().addSequenceTemplate(tm.getName(), tm);
if (log.isDebugEnabled()) {
log.debug("Template Deployment from file : " + fileName + " : Completed");
}
log.info("Template named '" + tm.getName() + "' has been deployed from file : " + fileName);
return tm.getName();
}
}
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Template Deployment from the file : " + fileName + " : Failed.", e);
}
return null;
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class TemplateDeployer method undeploySynapseArtifact.
@Override
public void undeploySynapseArtifact(String artifactName) {
if (log.isDebugEnabled()) {
log.debug("Template Undeployment of the Template named : " + artifactName + " : Started");
}
try {
Template st = null;
try {
st = getSynapseConfiguration().getEndpointTemplate(artifactName);
} catch (SynapseException e) {
// catch n log that and continue this process for undeployment of a sequence template
if (e.getMessage().indexOf("Cannot locate an either local or remote entry for key") != -1) {
if (log.isDebugEnabled()) {
log.debug("Undeploying template is not of endpoint type. Undeployer will now check " + "for sequence template for the key: " + artifactName);
}
} else {
// different error hence stop undeployment/report failure
throw e;
}
}
if (st != null) {
getSynapseConfiguration().removeEndpointTemplate(artifactName);
if (log.isDebugEnabled()) {
log.debug("Destroying the Template named : " + artifactName);
}
if (log.isDebugEnabled()) {
log.debug("Template Undeployment of the template named : " + artifactName + " : Completed");
}
log.info("Template named '" + st.getName() + "' has been undeployed");
} else {
TemplateMediator tm = getSynapseConfiguration().getSequenceTemplate(artifactName);
if (tm != null) {
getSynapseConfiguration().removeSequenceTemplate(artifactName);
if (log.isDebugEnabled()) {
log.debug("Destroying the Template named : " + artifactName);
}
tm.destroy();
if (log.isDebugEnabled()) {
log.debug("Template Undeployment of the template named : " + artifactName + " : Completed");
}
log.info("Template named '" + tm.getName() + "' has been undeployed");
} else {
log.debug("Template task " + artifactName + " has already been undeployed");
}
}
} catch (Exception e) {
handleSynapseArtifactDeploymentError("Template Undeployement of template named : " + artifactName + " : Failed", e);
}
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class SynapseConfiguration method init.
/**
* This method will be called in the startup of Synapse or in an initiation
* and will initialize all the managed parts of the Synapse Configuration
*
* @param se SynapseEnvironment specifying the env to be initialized
*/
public synchronized void init(SynapseEnvironment se) {
SynapseConfiguration previouseConfiguration = null;
if (log.isDebugEnabled()) {
log.debug("Initializing the Synapse Configuration using the SynapseEnvironment");
}
// initialize registry
if (registry != null && registry instanceof ManagedLifecycle) {
((ManagedLifecycle) registry).init(se);
}
// we initialize xpath extensions here since synapse environment is available
initXpathExtensions(se);
initCarbonTenantConfigurator(se);
// initialize endpoints
for (Endpoint endpoint : getDefinedEndpoints().values()) {
try {
endpoint.init(se);
} catch (Exception e) {
log.error(" Error in initializing endpoint [" + endpoint.getName() + "] " + e.getMessage());
}
}
// initialize sequence templates
for (TemplateMediator seqTemplate : getSequenceTemplates().values()) {
try {
seqTemplate.init(se);
} catch (Exception e) {
log.error(" Error in initializing Sequence Template [" + seqTemplate.getName() + "] " + e.getMessage());
}
}
String tenantDomain = getTenantDomain(se);
if (tenantDomain != null) {
previouseConfiguration = SynapseConfigUtils.getSynapseConfiguration(tenantDomain);
SynapseConfigUtils.addSynapseConfiguration(tenantDomain, this);
}
if (previouseConfiguration != null) {
destroyExistingInbounds(previouseConfiguration);
}
for (InboundEndpoint endpoint : getInboundEndpoints()) {
try {
endpoint.init(se);
} catch (Exception e) {
inboundEndpointMap.remove(endpoint.getName());
log.error(" Error in initializing inbound endpoint [" + endpoint.getName() + "] " + e.getMessage());
}
}
// initialize managed mediators
for (ManagedLifecycle seq : getDefinedSequences().values()) {
if (seq != null) {
try {
seq.init(se);
} catch (Exception e) {
log.error(" Error in initializing Sequence " + e.getMessage());
}
}
}
// initialize all the proxy services
for (ProxyService proxy : getProxyServices()) {
try {
if (proxy.getTargetInLineEndpoint() != null) {
proxy.getTargetInLineEndpoint().init(se);
}
if (proxy.getTargetInLineInSequence() != null) {
proxy.getTargetInLineInSequence().init(se);
}
if (proxy.getTargetInLineOutSequence() != null) {
proxy.getTargetInLineOutSequence().init(se);
}
if (proxy.getTargetInLineFaultSequence() != null) {
proxy.getTargetInLineFaultSequence().init(se);
}
} catch (Exception e) {
log.error(" Error in initializing Proxy Service [ " + proxy.getName() + "] " + e.getMessage());
}
}
// initialize the startups
for (ManagedLifecycle stp : getStartups()) {
if (stp != null) {
try {
stp.init(se);
} catch (Exception e) {
log.error(" Error in initializing Stratups " + e.getMessage());
}
}
}
// initialize sequence executors
for (PriorityExecutor executor : getPriorityExecutors().values()) {
try {
executor.init();
} catch (Exception e) {
log.error(" Error in initializing Executor [ " + executor.getName() + "] " + e.getMessage());
}
}
// initialize message stores
for (MessageStore messageStore : messageStores.values()) {
try {
messageStore.init(se);
} catch (Exception e) {
log.error(" Error in initializing Message Store [ " + messageStore.getName() + "] " + e.getMessage());
}
}
// initialize message processors
for (MessageProcessor messageProcessor : messageProcessors.values()) {
try {
messageProcessor.init(se);
} catch (Exception e) {
log.error(" Error in initializing Message Processor [ " + messageProcessor.getName() + "] " + e.getMessage());
}
}
for (API api : apiTable.values()) {
try {
api.init(se);
} catch (Exception e) {
log.error(" Error in initializing API [ " + api.getName() + "] " + e.getMessage());
}
}
initImportedLibraries(se);
}
use of org.apache.synapse.mediators.template.TemplateMediator in project wso2-synapse by wso2.
the class SynapseConfiguration method getSequenceTemplate.
/**
* Return the template specified with the given key
*
* @param key the key being referenced for the template
* @return the template referenced by the key from local/remote registry
*/
public TemplateMediator getSequenceTemplate(String key) {
Object o = getEntry(key);
if (o instanceof TemplateMediator) {
return (TemplateMediator) o;
}
Entry entry = null;
if (o == null) {
entry = new Entry(key);
entry.setType(Entry.REMOTE_ENTRY);
} else {
Object object = localRegistry.get(key);
if (object instanceof Entry) {
entry = (Entry) object;
}
}
assertEntryNull(entry, key);
// noinspection ConstantConditions
if (entry.getMapper() == null) {
entry.setMapper(new XMLToTemplateMapper());
}
if (entry.getType() == Entry.REMOTE_ENTRY) {
if (registry != null) {
o = registry.getResource(entry, getProperties());
if (o != null && o instanceof TemplateMediator) {
localRegistry.put(key, entry);
return (TemplateMediator) o;
} else if (o instanceof OMNode) {
TemplateMediator m = (TemplateMediator) new TemplateMediatorFactory().createMediator((OMElement) o, properties);
if (m != null) {
entry.setValue(m);
return m;
}
}
}
} else {
Object value = entry.getValue();
if (value instanceof OMNode) {
Object object = entry.getMapper().getObjectFromOMNode((OMNode) value, getProperties());
if (object instanceof TemplateMediator) {
entry.setValue(object);
return (TemplateMediator) object;
}
}
}
// load from available libraries
TemplateMediator templateFromLib = LibDeployerUtils.getLibArtifact(synapseLibraries, key, TemplateMediator.class);
if (templateFromLib != null) {
return templateFromLib;
}
return null;
}
Aggregations