use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializer method serializeConfiguration.
/**
* Order of entries is irrelevant, however its nice to have some order.
*
* @param synCfg configuration to be serialized
* @return serialized element of the configuration
*/
public OMElement serializeConfiguration(SynapseConfiguration synCfg) {
OMElement definitions = fac.createOMElement("definitions", synNS);
// first add the description
if (synCfg.getDescription() != null) {
OMElement descElem = fac.createOMElement("description", synNS);
descElem.setText(synCfg.getDescription());
definitions.addChild(descElem);
}
// then process a remote registry if present
if (synCfg.getRegistry() != null) {
RegistrySerializer.serializeRegistry(definitions, synCfg.getRegistry());
}
// then process a remote registry if present
if (synCfg.getTaskManager() != null) {
TaskManagerSerializer.serializetaskManager(definitions, synCfg.getTaskManager());
}
serializeImports(definitions, synCfg.getSynapseImports().values());
// add proxy services
Iterator itr = synCfg.getProxyServices().iterator();
while (itr.hasNext()) {
ProxyService service = (ProxyService) itr.next();
ProxyServiceSerializer.serializeProxy(definitions, service);
}
// Add Event sources
for (SynapseEventSource eventSource : synCfg.getEventSources()) {
EventSourceSerializer.serializeEventSource(definitions, eventSource);
}
Map<String, Entry> entries = new HashMap<String, Entry>();
Map<String, Endpoint> endpoints = new HashMap<String, Endpoint>();
Map<String, SequenceMediator> sequences = new HashMap<String, SequenceMediator>();
Map<String, TemplateMediator> templates = new HashMap<String, TemplateMediator>();
Map<String, Template> endpointTemplates = new HashMap<String, Template>();
itr = synCfg.getLocalRegistry().keySet().iterator();
while (itr.hasNext()) {
Object key = itr.next();
if (SynapseConstants.SERVER_IP.equals(key) || SynapseConstants.SERVER_HOST.equals(key)) {
continue;
}
Object o = synCfg.getLocalRegistry().get(key);
if (o instanceof TemplateMediator) {
templates.put(key.toString(), (TemplateMediator) o);
} else if (o instanceof SequenceMediator) {
sequences.put(key.toString(), (SequenceMediator) o);
} else if (o instanceof Endpoint) {
endpoints.put(key.toString(), (Endpoint) o);
} else if (o instanceof Template) {
endpointTemplates.put(key.toString(), (Template) o);
} else if (o instanceof Entry) {
entries.put(key.toString(), (Entry) o);
} else {
handleException("Unknown object : " + o.getClass() + " for serialization into Synapse configuration");
}
}
// process entries
serializeEntries(definitions, entries);
// process endpoints
serializeEndpoints(definitions, endpoints);
// process sequences
serializeSequences(definitions, sequences);
// process templates
serializeMediatorTemplates(definitions, templates);
// serialize the endpoint templates
serializeEndpointTemplates(definitions, endpointTemplates);
// handle startups
serializeStartups(definitions, synCfg.getStartups());
// Executors
serializeExecutors(definitions, synCfg.getPriorityExecutors());
// Message stores
serializeMessageStores(definitions, synCfg.getMessageStores());
// Message Processors
serializeMessageProcessors(definitions, synCfg.getMessageProcessors());
serializeAPIs(definitions, synCfg.getAPIs());
// XML comments
serializeComments(definitions, synCfg.getCommentedTextList());
if (synCfg.getInboundEndpoints() != null && synCfg.getInboundEndpoints().size() > 0) {
Collection<InboundEndpoint> inboundEndpoints = synCfg.getInboundEndpoints();
for (InboundEndpoint inboundEndpoint : inboundEndpoints) {
InboundEndpointSerializer.serializeInboundEndpoint(definitions, inboundEndpoint);
}
}
return definitions;
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class SynapseConfiguration method getEndpointTemplates.
/**
* Returns the map of defined synapse endpoint templates in the configuration excluding the
* fetched sequences from remote registry.
*
* @return Map of Templates defined in the local configuration
*/
public Map<String, Template> getEndpointTemplates() {
Map<String, Template> definedTemplates = new HashMap<String, Template>();
synchronized (this) {
for (Object o : localRegistry.values()) {
if (o instanceof Template) {
Template template = (Template) o;
definedTemplates.put(template.getName(), template);
}
}
}
return definedTemplates;
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class SynapseConfiguration method getEndpointTemplate.
public Template getEndpointTemplate(String key) {
Object o = getEntry(key);
if (o instanceof Template) {
return (Template) 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(this));
}
if (entry.getType() == Entry.REMOTE_ENTRY) {
if (registry != null) {
o = registry.getResource(entry, getProperties());
if (o != null && o instanceof Template) {
localRegistry.put(key, entry);
return (Template) o;
} else if (o instanceof OMNode) {
Template m = new TemplateFactory().createEndpointTemplate((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 Template) {
entry.setValue(object);
return (Template) object;
}
}
}
// load from available libraries
Template templateFromLib = LibDeployerUtils.getLibArtifact(synapseLibraries, key, Template.class);
if (templateFromLib != null) {
return templateFromLib;
}
return null;
}
use of org.apache.synapse.endpoints.Template 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;
Map<String, Template> templates = getSynapseConfiguration().getEndpointTemplates();
if (templates.containsKey(artifactName)) {
st = getSynapseConfiguration().getEndpointTemplate(artifactName);
} else {
// therefore, it must be a sequence template
if (log.isDebugEnabled()) {
log.debug("Undeploying template is not of endpoint type. Undeployer will now check " + "for sequence template for the key: " + artifactName);
}
}
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.endpoints.Template 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, getSynapseConfiguration());
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;
}
Aggregations