use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class XMLToTemplateMapperTest method testGetObjectFromOMNodeEndpoint.
/**
* Test getObjectFromOMNode by parsing a XML with endpoint tag.
*
* @throws XMLStreamException
*/
@Test
public void testGetObjectFromOMNodeEndpoint() throws XMLStreamException {
String input = "<template xmlns=\"http://ws.apache.org/ns/synapse\" name=\"HelloWordLogger\">\n" + "<endpoint>\n" + " <address uri=\"http://localhost:9000/services/SimpleStockQuoteService\"/>\n" + " </endpoint>" + "</template>";
OMElement element = AXIOMUtil.stringToOM(input);
Template template = (Template) mapper.getObjectFromOMNode(element, properties);
Assert.assertEquals("name should be parsed into the template", NAME, template.getName());
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class TemplateFactory method createEndpointTemplate.
public Template createEndpointTemplate(OMElement element, Properties properties) {
Template template = new Template();
OMAttribute nameAttribute = element.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
if (nameAttribute != null) {
template.setName(nameAttribute.getAttributeValue());
} else {
handleException("Error loading the configuration from endpointTemplate, '" + "name' attribute missing");
}
Iterator paramItr = element.getChildrenWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "parameter"));
while (paramItr.hasNext()) {
OMElement paramElement = (OMElement) paramItr.next();
OMAttribute paramName = paramElement.getAttribute(new QName("name"));
if (paramName == null) {
handleException("parameter name should be present");
}
assert paramName != null;
template.addParameter(paramName.getAttributeValue().trim());
}
if (!template.getParameters().contains("name")) {
template.addParameter("name");
}
if (!template.getParameters().contains("uri")) {
template.addParameter("uri");
}
OMElement endpointElement = element.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "endpoint"));
if (endpointElement == null) {
handleException("endpoint element is required in an endpoint template");
}
template.setElement(endpointElement);
CommentListUtil.populateComments(element, template.getCommentsList());
return template;
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class SynapseXMLConfigurationSerializer method serializeEndpointTemplates.
private static void serializeEndpointTemplates(OMElement definitions, Map<String, Template> templateMap) {
for (Template template : templateMap.values()) {
TemplateSerializer serializer = new TemplateSerializer();
serializer.serializeEndpointTemplate(template, definitions);
}
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class MultiXMLConfigurationSerializer method serializeLocalEntry.
public OMElement serializeLocalEntry(Object o, SynapseConfiguration synapseConfig, OMElement parent) throws Exception {
if (o instanceof TemplateMediator) {
return serializeTemplate((TemplateMediator) o, synapseConfig, parent);
} else if (o instanceof SequenceMediator) {
return serializeSequence((SequenceMediator) o, synapseConfig, parent);
} else if (o instanceof Template) {
return serializeTemplate((Template) o, synapseConfig, parent);
} else if (o instanceof Endpoint) {
return serializeEndpoint((Endpoint) o, synapseConfig, parent);
} else if (o instanceof Entry) {
Entry entry = (Entry) o;
if ((SynapseConstants.SERVER_HOST.equals(entry.getKey()) || SynapseConstants.SERVER_IP.equals(entry.getKey())) || entry.getType() == Entry.REMOTE_ENTRY) {
return null;
}
File entriesDir = createDirectory(currentDirectory, MultiXMLConfigurationBuilder.LOCAL_ENTRY_DIR);
OMElement entryElem = EntrySerializer.serializeEntry(entry, null);
String fileName = entry.getFileName();
if (fileName != null) {
if (currentDirectory == rootDirectory) {
handleDeployment(entriesDir, fileName, entry.getKey(), synapseConfig.getArtifactDeploymentStore());
}
File entryFile = new File(entriesDir, fileName);
writeToFile(entryElem, entryFile);
} else if (parent != null) {
parent.addChild(entryElem);
}
return entryElem;
}
return null;
}
use of org.apache.synapse.endpoints.Template in project wso2-synapse by wso2.
the class LibraryArtifact method loadComponentsInto.
public void loadComponentsInto(SynapseLibrary library) {
for (String artifactName : subArtifacts.keySet()) {
LibraryArtifact artifact = subArtifacts.get(artifactName);
if (artifact.isLeafArtifact()) {
delegateClassLoading(artifact, library);
// this is where actual artifact is constructed to it's ture form
Object template = artifact.file.build();
if (artifact.file instanceof TemplateArtifactFile) {
if (template instanceof TemplateMediator) {
TemplateMediator templateMediator = (TemplateMediator) template;
// make template dynamic as it is not directly available to synapse environment
templateMediator.setDynamic(true);
String templateName = templateMediator.getName();
library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
} else if (template instanceof Template) {
String templateName = ((Template) template).getName();
library.addComponent(getQualifiedName(library.getPackage(), templateName, library.getQName().getLocalPart()), template);
} else if (template != null) {
library.addComponent(getQualifiedName(library.getPackage(), artifact.getName(), library.getQName().getLocalPart()), template);
} else {
throw new SynapseArtifactDeploymentException("Cannot load components into " + "Synapse Library. Component " + "cannot be built for " + artifactName);
}
}
} else {
artifact.loadComponentsInto(library);
}
}
}
Aggregations