Search in sources :

Example 1 with SequenceMediatorFactory

use of org.apache.synapse.config.xml.SequenceMediatorFactory in project wso2-synapse by wso2.

the class ResourceFactory method configureSequences.

private static void configureSequences(Resource resource, OMElement resourceElt, Properties properties) {
    OMAttribute inSequenceKeyAtt = resourceElt.getAttribute(new QName("inSequence"));
    OMElement inSequenceElt = resourceElt.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "inSequence"));
    if (inSequenceKeyAtt != null && !"".equals(inSequenceKeyAtt.getAttributeValue())) {
        resource.setInSequenceKey(inSequenceKeyAtt.getAttributeValue());
    } else if (inSequenceElt != null) {
        SequenceMediatorFactory fac = new SequenceMediatorFactory();
        SequenceMediator sequence = fac.createAnonymousSequence(inSequenceElt, properties);
        sequence.setSequenceType(SequenceType.API_INSEQ);
        resource.setInSequence(sequence);
    }
    OMAttribute outSequenceKeyAtt = resourceElt.getAttribute(new QName("outSequence"));
    OMElement outSequenceElt = resourceElt.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "outSequence"));
    if (outSequenceKeyAtt != null && !"".equals(outSequenceKeyAtt.getAttributeValue())) {
        resource.setOutSequenceKey(outSequenceKeyAtt.getAttributeValue());
    } else if (outSequenceElt != null) {
        SequenceMediatorFactory fac = new SequenceMediatorFactory();
        SequenceMediator sequence = fac.createAnonymousSequence(outSequenceElt, properties);
        sequence.setSequenceType(SequenceType.API_OUTSEQ);
        resource.setOutSequence(sequence);
    }
    OMAttribute faultSequenceKeyAtt = resourceElt.getAttribute(new QName("faultSequence"));
    OMElement faultSequenceElt = resourceElt.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "faultSequence"));
    if (faultSequenceKeyAtt != null && !"".equals(faultSequenceKeyAtt.getAttributeValue())) {
        resource.setFaultSequenceKey(faultSequenceKeyAtt.getAttributeValue());
    } else if (faultSequenceElt != null) {
        SequenceMediatorFactory fac = new SequenceMediatorFactory();
        SequenceMediator sequence = fac.createAnonymousSequence(faultSequenceElt, properties);
        sequence.setSequenceType(SequenceType.API_FAULTSEQ);
        resource.setFaultSequence(sequence);
    }
}
Also used : SequenceMediatorFactory(org.apache.synapse.config.xml.SequenceMediatorFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with SequenceMediatorFactory

use of org.apache.synapse.config.xml.SequenceMediatorFactory in project wso2-synapse by wso2.

the class ThrottleMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    ThrottleMediator throttleMediator = new ThrottleMediator();
    OMElement policy = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "policy"));
    if (policy != null) {
        OMAttribute key = policy.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, "key"));
        if (key != null) {
            String keyValue = key.getAttributeValue();
            if (keyValue != null && !"".equals(keyValue)) {
                throttleMediator.setPolicyKey(keyValue);
            } else {
                handleException("key attribute should have a value ");
            }
        } else {
            OMElement inLine = policy.getFirstElement();
            if (inLine != null) {
                throttleMediator.setInLinePolicy(inLine);
            }
        }
    }
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(throttleMediator, elem);
    String id = elem.getAttributeValue(new QName(XMLConfigConstants.NULL_NAMESPACE, "id"));
    if (id != null && !"".equals(id)) {
        throttleMediator.setId(id.trim());
    } else {
        handleException("Idy attribute must have defined ");
    }
    SequenceMediatorFactory mediatorFactory = new SequenceMediatorFactory();
    OMAttribute onReject = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.ONREJECT));
    if (onReject != null) {
        String onRejectValue = onReject.getAttributeValue();
        if (onRejectValue != null) {
            throttleMediator.setOnRejectSeqKey(onRejectValue.trim());
        }
    } else {
        OMElement onRejectMediatorElement = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ONREJECT));
        if (onRejectMediatorElement != null) {
            throttleMediator.setOnRejectMediator(mediatorFactory.createAnonymousSequence(onRejectMediatorElement, properties));
        }
    }
    OMAttribute onAccept = elem.getAttribute(new QName(XMLConfigConstants.NULL_NAMESPACE, XMLConfigConstants.ONACCEPT));
    if (onAccept != null) {
        String onAcceptValue = onAccept.getAttributeValue();
        if (onAcceptValue != null) {
            throttleMediator.setOnAcceptSeqKey(onAcceptValue);
        }
    } else {
        OMElement onAcceptMediatorElement = elem.getFirstChildWithName(new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, XMLConfigConstants.ONACCEPT));
        if (onAcceptMediatorElement != null) {
            throttleMediator.setOnAcceptMediator(mediatorFactory.createAnonymousSequence(onAcceptMediatorElement, properties));
        }
    }
    return throttleMediator;
}
Also used : SequenceMediatorFactory(org.apache.synapse.config.xml.SequenceMediatorFactory) QName(javax.xml.namespace.QName) OMElement(org.apache.axiom.om.OMElement) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 3 with SequenceMediatorFactory

use of org.apache.synapse.config.xml.SequenceMediatorFactory in project wso2-synapse by wso2.

the class ProxyServiceMessageReceiverTest method testReceive.

/**
 * Test message receipt by ProxyServiceMessageReceiver.
 *
 * @throws Exception on a message receipt issue
 */
@Test
public void testReceive() throws Exception {
    // create ProxyServiceMessageReceiver instance
    ProxyServiceMessageReceiver proxyServiceMessageReceiver = new ProxyServiceMessageReceiver();
    ProxyService proxyService = new ProxyService("TestProxy");
    // create an inSequence and set
    OMElement sequenceAsOM = AXIOMUtil.stringToOM("<inSequence xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "         <property name=\"TEST\" scope=\"axis2\" type=\"STRING\" value=\"WSO2\"/>\n" + "      </inSequence>");
    proxyService.setTargetInLineInSequence(new SequenceMediatorFactory().createAnonymousSequence(sequenceAsOM, null));
    proxyServiceMessageReceiver.setProxy(proxyService);
    MessageContext messageContext = createMessageContext();
    Axis2SynapseEnvironment synapseEnvironment = getMockedSynapseEnvironment();
    // set required values
    MessageContextCreatorForAxis2.setSynConfig(new SynapseConfiguration());
    MessageContextCreatorForAxis2.setSynEnv(synapseEnvironment);
    messageContext.setEnvironment(synapseEnvironment);
    // invoke
    proxyServiceMessageReceiver.receive(((Axis2MessageContext) messageContext).getAxis2MessageContext());
    String propertySet = (String) ((Axis2MessageContext) messageContext).getAxis2MessageContext().getProperty("TEST");
    Assert.assertEquals("property is not set after delegating to proxy", "WSO2", propertySet);
}
Also used : SequenceMediatorFactory(org.apache.synapse.config.xml.SequenceMediatorFactory) OMElement(org.apache.axiom.om.OMElement) MessageContext(org.apache.synapse.MessageContext) SynapseConfiguration(org.apache.synapse.config.SynapseConfiguration) Test(org.junit.Test)

Aggregations

OMElement (org.apache.axiom.om.OMElement)3 SequenceMediatorFactory (org.apache.synapse.config.xml.SequenceMediatorFactory)3 QName (javax.xml.namespace.QName)2 OMAttribute (org.apache.axiom.om.OMAttribute)2 MessageContext (org.apache.synapse.MessageContext)1 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 Test (org.junit.Test)1