Search in sources :

Example 11 with Template

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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) Template(org.apache.synapse.endpoints.Template) Test(org.junit.Test)

Example 12 with Template

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;
}
Also used : QName(javax.xml.namespace.QName) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) Template(org.apache.synapse.endpoints.Template)

Example 13 with 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);
    }
}
Also used : TemplateSerializer(org.apache.synapse.config.xml.endpoints.TemplateSerializer) Template(org.apache.synapse.endpoints.Template)

Example 14 with Template

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;
}
Also used : Entry(org.apache.synapse.config.Entry) TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) Endpoint(org.apache.synapse.endpoints.Endpoint) AbstractEndpoint(org.apache.synapse.endpoints.AbstractEndpoint) InboundEndpoint(org.apache.synapse.inbound.InboundEndpoint) OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) Template(org.apache.synapse.endpoints.Template)

Example 15 with Template

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);
        }
    }
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseArtifactDeploymentException(org.apache.synapse.deployers.SynapseArtifactDeploymentException) Template(org.apache.synapse.endpoints.Template)

Aggregations

Template (org.apache.synapse.endpoints.Template)15 OMElement (org.apache.axiom.om.OMElement)9 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)9 QName (javax.xml.namespace.QName)5 SynapseException (org.apache.synapse.SynapseException)5 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 Entry (org.apache.synapse.config.Entry)3 TemplateSerializer (org.apache.synapse.config.xml.endpoints.TemplateSerializer)3 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)3 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)3 File (java.io.File)2 Iterator (java.util.Iterator)2 Mediator (org.apache.synapse.Mediator)2 TemplateFactory (org.apache.synapse.config.xml.endpoints.TemplateFactory)2 ProxyService (org.apache.synapse.core.axis2.ProxyService)2 AbstractEndpoint (org.apache.synapse.endpoints.AbstractEndpoint)2 Endpoint (org.apache.synapse.endpoints.Endpoint)2 SynapseEventSource (org.apache.synapse.eventing.SynapseEventSource)2 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1