Search in sources :

Example 61 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class SequenceMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    SequenceMediator seqMediator = new SequenceMediator();
    OMAttribute n = elem.getAttribute(ATT_NAME);
    OMAttribute e = elem.getAttribute(ATT_ONERROR);
    if (n != null) {
        seqMediator.setName(n.getAttributeValue());
        if (e != null) {
            seqMediator.setErrorHandler(e.getAttributeValue());
        }
        processAuditStatus(seqMediator, elem);
        addChildren(elem, seqMediator, properties);
    } else {
        n = elem.getAttribute(ATT_KEY);
        if (n != null) {
            // 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, elem);
            // setKey
            seqMediator.setKey(generatedKey);
            if (e != null) {
                String msg = "A sequence mediator with a reference to another " + "sequence can not have 'ErrorHandler'";
                log.error(msg);
                throw new SynapseException(msg);
            }
        } else {
            String msg = "A sequence mediator should be a named sequence or a reference " + "to another sequence (i.e. a name attribute or key attribute is required)";
            log.error(msg);
            throw new SynapseException(msg);
        }
    }
    return seqMediator;
}
Also used : SynapseException(org.apache.synapse.SynapseException) Value(org.apache.synapse.mediators.Value) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 62 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class ListenerContextBuilder method createParser.

private Parser createParser(final OMElement definitions) throws AxisFault {
    OMElement conditionsElem = definitions.getFirstChildWithName(new QName(EvaluatorConstants.CONDITIONS));
    if (conditionsElem == null) {
        handleException("Conditions configuration is mandatory for priority based routing");
    }
    assert conditionsElem != null;
    OMAttribute defPriorityAttr = conditionsElem.getAttribute(new QName(EvaluatorConstants.DEFAULT_PRIORITY));
    Parser parser;
    if (defPriorityAttr != null) {
        parser = new Parser(Integer.parseInt(defPriorityAttr.getAttributeValue()));
    } else {
        parser = new Parser();
    }
    try {
        parser.init(conditionsElem);
    } catch (EvaluatorException e) {
        handleException("Invalid " + EvaluatorConstants.CONDITIONS + " configuration for priority based mediation", e);
    }
    return parser;
}
Also used : EvaluatorException(org.apache.synapse.commons.evaluators.EvaluatorException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute) Parser(org.apache.synapse.commons.evaluators.Parser)

Example 63 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class EventPublisherMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    EventPublisherMediator eventPublisherMediator = new EventPublisherMediator();
    processAuditStatus(eventPublisherMediator, elem);
    OMAttribute attEventSource = elem.getAttribute(PROP_NAME);
    if (attEventSource != null) {
        eventPublisherMediator.setEventSourceName(attEventSource.getAttributeValue());
    } else {
        handleException("The 'eventSourceName' attribute is required for the EventPublisher mediator");
    }
    return eventPublisherMediator;
}
Also used : EventPublisherMediator(org.apache.synapse.mediators.eventing.EventPublisherMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 64 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class EventSourceFactory method createEventSource.

@SuppressWarnings({ "UnusedDeclaration" })
public static SynapseEventSource createEventSource(OMElement elem, Properties properties) {
    SynapseEventSource eventSource = null;
    OMAttribute name = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "name"));
    if (name == null) {
        handleException("The 'name' attribute is required for a event source de");
    } else {
        eventSource = new SynapseEventSource(name.getAttributeValue());
    }
    OMElement subscriptionManagerElem = elem.getFirstChildWithName(SUBSCRIPTION_MANAGER_QNAME);
    if (eventSource != null && subscriptionManagerElem != null) {
        OMAttribute clazz = subscriptionManagerElem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "class"));
        if (clazz != null) {
            String className = clazz.getAttributeValue();
            try {
                Class subscriptionManagerClass = Class.forName(className);
                SubscriptionManager manager = (SubscriptionManager) subscriptionManagerClass.newInstance();
                Iterator itr = subscriptionManagerElem.getChildrenWithName(PROPERTIES_QNAME);
                while (itr.hasNext()) {
                    OMElement propElem = (OMElement) itr.next();
                    String propName = propElem.getAttribute(new QName("name")).getAttributeValue();
                    String propValue = propElem.getAttribute(new QName("value")).getAttributeValue();
                    if (propName != null && !"".equals(propName.trim()) && propValue != null && !"".equals(propValue.trim())) {
                        propName = propName.trim();
                        propValue = propValue.trim();
                        PasswordManager passwordManager = PasswordManager.getInstance();
                        String key = eventSource.getName() + "." + propName;
                        if (passwordManager.isInitialized() && passwordManager.isTokenProtected(key)) {
                            eventSource.putConfigurationProperty(propName, propValue);
                            propValue = passwordManager.resolve(propValue);
                        }
                        manager.addProperty(propName, propValue);
                    }
                }
                eventSource.setSubscriptionManager(manager);
                eventSource.getSubscriptionManager().init();
            } catch (ClassNotFoundException e) {
                handleException("SubscriptionManager class not found", e);
            } catch (IllegalAccessException e) {
                handleException("Unable to access the SubscriptionManager object", e);
            } catch (InstantiationException e) {
                handleException("Unable to instantiate the SubscriptionManager object", e);
            }
        } else {
            handleException("SynapseSubscription manager class is a required attribute");
        }
    } else {
        handleException("SynapseSubscription Manager has not been specified for the event source");
    }
    try {
        createStaticSubscriptions(elem, eventSource);
    } catch (EventException e) {
        handleException("Static subscription creation failure", e);
    }
    return eventSource;
}
Also used : SynapseEventSource(org.apache.synapse.eventing.SynapseEventSource) EventException(org.wso2.eventing.exceptions.EventException) QName(javax.xml.namespace.QName) PasswordManager(org.wso2.securevault.PasswordManager) OMElement(org.apache.axiom.om.OMElement) SubscriptionManager(org.wso2.eventing.SubscriptionManager) Iterator(java.util.Iterator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 65 with OMAttribute

use of org.apache.axiom.om.OMAttribute in project wso2-synapse by wso2.

the class RecipientListEndpointFactory method createEndpoint.

@Override
protected Endpoint createEndpoint(OMElement epConfig, boolean anonymousEndpoint, Properties properties) {
    OMElement recipientListElement = epConfig.getFirstChildWithName(new QName(SynapseConstants.SYNAPSE_NAMESPACE, "recipientlist"));
    if (recipientListElement != null) {
        // create endpoint
        RecipientListEndpoint recipientListEndpoint = new RecipientListEndpoint();
        // set endpoint name
        OMAttribute name = epConfig.getAttribute(new QName(org.apache.synapse.config.xml.XMLConfigConstants.NULL_NAMESPACE, "name"));
        if (name != null) {
            recipientListEndpoint.setName(name.getAttributeValue());
        }
        // set endpoints or members
        if (recipientListElement.getFirstChildWithName(XMLConfigConstants.ENDPOINT_ELT) != null) {
            if (recipientListElement.getChildrenWithName((MEMBER)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Endpoint> endpoints = getEndpoints(recipientListElement, recipientListEndpoint, properties);
            recipientListEndpoint.setChildren(endpoints);
        } else if (recipientListElement.getFirstChildWithName(MEMBER) != null) {
            if (recipientListElement.getChildrenWithName((XMLConfigConstants.ENDPOINT_ELT)).hasNext()) {
                String msg = "Invalid Synapse configuration. " + "recipientListElement element cannot have both member & endpoint " + "child elements";
                log.error(msg);
                throw new SynapseException(msg);
            }
            List<Member> members = getMembers(recipientListElement);
            recipientListEndpoint.setMembers(members);
        } else if (recipientListElement.getFirstChildWithName(DYNAMIC_SET) != null) {
            OMElement dynamicSetElement = recipientListElement.getFirstChildWithName(DYNAMIC_SET);
            Value dynamicEndpointSet = new ValueFactory().createValue("value", dynamicSetElement);
            String maxStr = dynamicSetElement.getAttributeValue(new QName("max-cache"));
            int maxCache = -1;
            try {
                maxCache = Integer.parseInt(maxStr);
            } catch (NumberFormatException e) {
            }
            recipientListEndpoint = new RecipientListEndpoint(maxCache < 0 ? RecipientListEndpoint.DEFAULT_MAX_POOL : maxCache);
            if (name != null) {
                recipientListEndpoint.setName(name.getAttributeValue());
            }
            recipientListEndpoint.setDynamicEnpointSet(dynamicEndpointSet);
        }
        if (recipientListEndpoint.getChildren() == null && recipientListEndpoint.getMembers() == null && recipientListEndpoint.getDynamicEnpointSet() == null) {
            String msg = "Invalid Synapse configuration.\n" + "A RecipientListEndpoint must have child/member elements, but the RecipientListEndpoint " + "'" + recipientListEndpoint.getName() + "' does not have any child/member/dynamic endpoint elements.";
            log.error(msg);
            throw new SynapseException(msg);
        }
        // process the parameters
        processProperties(recipientListEndpoint, epConfig);
        return recipientListEndpoint;
    }
    return null;
}
Also used : SynapseException(org.apache.synapse.SynapseException) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) ValueFactory(org.apache.synapse.config.xml.ValueFactory) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Endpoint(org.apache.synapse.endpoints.Endpoint) RecipientListEndpoint(org.apache.synapse.endpoints.RecipientListEndpoint) Value(org.apache.synapse.mediators.Value) ArrayList(java.util.ArrayList) List(java.util.List) OMAttribute(org.apache.axiom.om.OMAttribute)

Aggregations

OMAttribute (org.apache.axiom.om.OMAttribute)187 OMElement (org.apache.axiom.om.OMElement)116 QName (javax.xml.namespace.QName)82 Iterator (java.util.Iterator)41 OMFactory (org.apache.axiom.om.OMFactory)31 OMNamespace (org.apache.axiom.om.OMNamespace)28 SynapseException (org.apache.synapse.SynapseException)28 JaxenException (org.jaxen.JaxenException)28 OMNode (org.apache.axiom.om.OMNode)13 Value (org.apache.synapse.mediators.Value)12 SynapseXPath (org.apache.synapse.util.xpath.SynapseXPath)11 ArrayList (java.util.ArrayList)8 Endpoint (org.apache.synapse.endpoints.Endpoint)7 IOException (java.io.IOException)6 List (java.util.List)6 OMText (org.apache.axiom.om.OMText)6 SOAPEnvelope (org.apache.axiom.soap.SOAPEnvelope)6 StringReader (java.io.StringReader)5 SOAPHeaderBlock (org.apache.axiom.soap.SOAPHeaderBlock)5 EndpointDefinition (org.apache.synapse.endpoints.EndpointDefinition)5