Search in sources :

Example 56 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class ScriptMediatorFactory method getIncludeKeysMap.

private Map<Value, Object> getIncludeKeysMap(OMElement elem) {
    // get <include /> scripts
    // map key = registry entry key, value = script source
    // at this time map values are null, later loaded
    // from void ScriptMediator.prepareExternalScript(MessageContext synCtx)
    // TreeMap used to keep given scripts order if needed
    Map<Value, Object> includeKeysMap = new LinkedHashMap<Value, Object>();
    Iterator itr = elem.getChildrenWithName(INCLUDE_Q);
    while (itr.hasNext()) {
        OMElement includeElem = (OMElement) itr.next();
        OMAttribute key = includeElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
        // ValueFactory for creating dynamic or static Value
        ValueFactory keyFac = new ValueFactory();
        // create dynamic or static key based on OMElement
        Value generatedKey = keyFac.createValue(XMLConfigConstants.KEY, includeElem);
        if (key == null) {
            throw new SynapseException("Cannot use 'include' element without 'key'" + " attribute for a script mediator");
        }
        includeKeysMap.put(generatedKey, null);
    }
    return includeKeysMap;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) Value(org.apache.synapse.mediators.Value) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) ValueFactory(org.apache.synapse.config.xml.ValueFactory) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 57 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class SynapseXMLConfigurationFactory method getConfiguration.

public SynapseConfiguration getConfiguration(OMElement definitions, Properties properties) {
    if (!definitions.getQName().equals(XMLConfigConstants.DEFINITIONS_ELT)) {
        throw new SynapseException("Wrong QName for this configuration factory " + definitions.getQName());
    }
    SynapseConfiguration config = SynapseConfigUtils.newConfiguration();
    config.setDefaultQName(definitions.getQName());
    Iterator itr = definitions.getChildren();
    while (itr.hasNext()) {
        Object o = itr.next();
        if (o instanceof OMElement) {
            OMElement elt = (OMElement) o;
            if (XMLConfigConstants.SEQUENCE_ELT.equals(elt.getQName())) {
                String key = elt.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
                // this could be a sequence def or a referred sequence
                if (key != null) {
                    handleException("Referred sequences are not allowed at the top level");
                } else {
                    defineSequence(config, elt, properties);
                }
            } else if (XMLConfigConstants.TEMPLATE_ELT.equals(elt.getQName())) {
                defineTemplate(config, elt, properties);
            } else if (XMLConfigConstants.IMPORT_ELT.equals(elt.getQName())) {
                defineImport(config, elt, properties);
            } else if (XMLConfigConstants.ENDPOINT_ELT.equals(elt.getQName())) {
                defineEndpoint(config, elt, properties);
            } else if (XMLConfigConstants.ENTRY_ELT.equals(elt.getQName())) {
                defineEntry(config, elt, properties);
            } else if (XMLConfigConstants.PROXY_ELT.equals(elt.getQName())) {
                defineProxy(config, elt, properties);
            } else if (XMLConfigConstants.REGISTRY_ELT.equals(elt.getQName())) {
                defineRegistry(config, elt, properties);
            } else if (XMLConfigConstants.EVENT_SOURCE_ELT.equals(elt.getQName())) {
                defineEventSource(config, elt, properties);
            } else if (XMLConfigConstants.EXECUTOR_ELT.equals(elt.getQName())) {
                defineExecutor(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_STORE_ELT.equals(elt.getQName())) {
                defineMessageStore(config, elt, properties);
            } else if (XMLConfigConstants.TASK_MANAGER_ELT.equals(elt.getQName())) {
                defineTaskManager(config, elt, properties);
            } else if (XMLConfigConstants.MESSAGE_PROCESSOR_ELT.equals(elt.getQName())) {
                defineMessageProcessor(config, elt, properties);
            } else if (StartupFinder.getInstance().isStartup(elt.getQName())) {
                defineStartup(config, elt, properties);
            } else if (XMLConfigConstants.API_ELT.equals(elt.getQName())) {
                defineAPI(config, elt, properties);
            } else if (XMLConfigConstants.DESCRIPTION_ELT.equals(elt.getQName())) {
                config.setDescription(elt.getText());
            } else if (XMLConfigConstants.INBOUND_ENDPOINT_ELT.equals(elt.getQName())) {
                defineInboundEndpoint(config, elt, properties);
            } else {
                handleException("Invalid configuration element at the top level, one of \'sequence\', " + "\'endpoint\', \'proxy\', \'eventSource\', \'localEntry\', \'priorityExecutor\'" + ", \'registry\' or \'inboundEndpoint\' is expected");
            }
        } else if (o instanceof OMComment) {
            OMComment commentNode = (OMComment) o;
            defineComments(config, commentNode);
        }
    }
    return config;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMComment(org.apache.axiom.om.OMComment) Iterator(java.util.Iterator) OMElement(org.apache.axiom.om.OMElement) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration)

Example 58 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class MediatorFactoryFinder method loadMediatorFactories.

private static void loadMediatorFactories() {
    for (Class c : mediatorFactories) {
        try {
            MediatorFactory fac = (MediatorFactory) c.newInstance();
            factoryMap.put(fac.getTagQName(), c);
        } catch (Exception e) {
            throw new SynapseException("Error instantiating " + c.getName(), e);
        }
    }
    // now iterate through the available pluggable mediator factories
    registerExtensions();
    initialized = true;
}
Also used : SynapseException(org.apache.synapse.SynapseException) EventPublisherMediatorFactory(org.apache.synapse.config.xml.eventing.EventPublisherMediatorFactory) SynapseException(org.apache.synapse.SynapseException) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 59 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class MediatorPropertySerializer method serializeMediatorProperty.

/**
 * Serialize the property to the given paren element. There will be a element created with
 * given name inside the parent element.
 *
 * @param parent element to which property elements should be added
 * @param mp a property to be serialized
 * @param childElementName <code>QName</code> of the element to be created
 */
public static void serializeMediatorProperty(OMElement parent, MediatorProperty mp, QName childElementName) {
    OMElement prop = fac.createOMElement(childElementName, parent);
    if (mp.getName() != null) {
        prop.addAttribute(fac.createOMAttribute("name", nullNS, mp.getName()));
    } else {
        String msg = "Mediator property name missing";
        log.error(msg);
        throw new SynapseException(msg);
    }
    if (mp.getValue() != null) {
        prop.addAttribute(fac.createOMAttribute("value", nullNS, mp.getValue()));
    } else if (mp.getExpression() != null) {
        SynapsePathSerializer.serializePath(mp.getExpression(), prop, "expression");
    } else {
        String msg = "Mediator property must have a literal value or be an expression";
        log.error(msg);
        throw new SynapseException(msg);
    }
    if (mp.getScope() != null && !XMLConfigConstants.SCOPE_DEFAULT.equals(mp.getScope())) {
        prop.addAttribute(fac.createOMAttribute("scope", nullNS, mp.getScope()));
    }
}
Also used : SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement)

Example 60 with SynapseException

use of org.apache.synapse.SynapseException in project wso2-synapse by wso2.

the class TemplateMediatorFactory method createSpecificMediator.

protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    TemplateMediator templateTemplateMediator = new TemplateMediator();
    OMAttribute nameAttr = elem.getAttribute(ATT_NAME);
    if (nameAttr != null) {
        templateTemplateMediator.setName(nameAttr.getAttributeValue());
        processAuditStatus(templateTemplateMediator, elem);
        initParameters(elem, templateTemplateMediator);
        OMElement templateBodyElem = elem.getFirstChildWithName(TEMPLATE_BODY_Q);
        addChildren(templateBodyElem, templateTemplateMediator, properties);
    } else {
        String msg = "A EIP template should be a named mediator .";
        log.error(msg);
        throw new SynapseException(msg);
    }
    return templateTemplateMediator;
}
Also used : TemplateMediator(org.apache.synapse.mediators.template.TemplateMediator) SynapseException(org.apache.synapse.SynapseException) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

SynapseException (org.apache.synapse.SynapseException)136 OMElement (org.apache.axiom.om.OMElement)31 OMAttribute (org.apache.axiom.om.OMAttribute)23 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)16 QName (javax.xml.namespace.QName)15 Iterator (java.util.Iterator)14 JaxenException (org.jaxen.JaxenException)14 XMLStreamException (javax.xml.stream.XMLStreamException)13 AxisFault (org.apache.axis2.AxisFault)13 Map (java.util.Map)12 Endpoint (org.apache.synapse.endpoints.Endpoint)12 ArrayList (java.util.ArrayList)11 HashMap (java.util.HashMap)10 IOException (java.io.IOException)8 MalformedURLException (java.net.MalformedURLException)8 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)8 OMNode (org.apache.axiom.om.OMNode)7 Mediator (org.apache.synapse.Mediator)7 MediatorProperty (org.apache.synapse.mediators.MediatorProperty)7