Search in sources :

Example 1 with InvokeMediator

use of org.apache.synapse.mediators.template.InvokeMediator in project wso2-synapse by wso2.

the class MediatorFactoryFinder method getDynamicInvokeMediator.

public InvokeMediator getDynamicInvokeMediator(OMElement connectorElem, String libraryName) {
    InvokeMediator invokeMediator = new InvokeMediator();
    if (connectorElem.getLocalName() != null && libraryName != null && !libraryName.equals("")) {
        invokeMediator.setTargetTemplate(libraryName + "." + connectorElem.getLocalName());
    }
    // load configuration based references for the given connector
    OMAttribute config_key = connectorElem.getAttribute(new QName(XMLConfigConstants.CONFIG_REF));
    if (config_key != 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.CONFIG_REF, connectorElem);
        // setKey
        invokeMediator.setKey(generatedKey);
    }
    buildParamteres(connectorElem, invokeMediator);
    invokeMediator.setPackageName(libraryName);
    invokeMediator.setDynamicMediator(true);
    return invokeMediator;
}
Also used : QName(javax.xml.namespace.QName) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) Value(org.apache.synapse.mediators.Value) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 2 with InvokeMediator

use of org.apache.synapse.mediators.template.InvokeMediator in project wso2-synapse by wso2.

the class MediatorFactoryFinder method main.

public static void main(String[] args) throws Exception {
    String connectorStr = "<sfdc.getContact xmlns=\"http://ws.apache.org/ns/synapse\">\n" + "\t\t <parameter name=\"param1\" value=\"val1\"/>\n" + "\t\t <parameter name=\"param2\" value=\"val2\"/>\n" + "\t</sfdc.getContact>";
    OMElement inConnectorElem = AXIOMUtil.stringToOM(connectorStr);
    String libName = "synapse.lang.eip";
    InvokeMediator invokeMediator = MediatorFactoryFinder.getInstance().getDynamicInvokeMediator(inConnectorElem, libName);
    invokeMediator.getTargetTemplate();
}
Also used : InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) OMElement(org.apache.axiom.om.OMElement)

Example 3 with InvokeMediator

use of org.apache.synapse.mediators.template.InvokeMediator in project wso2-synapse by wso2.

the class MediatorTreeTraverseUtil method getMediatorReference.

/**
 * Returns mediator referece associated with position while traversing the mediator tree.
 *
 * @param synCfg      synapse configuration reference
 * @param seqMediator sequence mediator which traverse happens
 * @param position    array of tree nodes specifying position integer with respect to it's parent node
 *                    starting from the root parent.
 * @return Mediator reference
 */
public static Mediator getMediatorReference(SynapseConfiguration synCfg, Mediator seqMediator, int[] position) {
    Mediator current_mediator = null;
    for (int counter = 0; counter < position.length; counter++) {
        if (counter == 0) {
            int mediatorCount = ((AbstractListMediator) seqMediator).getList().size();
            int correctedPosition = getCorrectedPossition((AbstractListMediator) seqMediator, position[counter]);
            if (mediatorCount > correctedPosition) {
                current_mediator = ((AbstractListMediator) seqMediator).getChild(correctedPosition);
            } else {
                log.warn("Mediator position requested is larger than last index : " + position[counter]);
            }
        }
        if (current_mediator != null && counter != 0) {
            if (current_mediator instanceof InvokeMediator) {
                current_mediator = synCfg.getSequenceTemplate(((InvokeMediator) current_mediator).getTargetTemplate());
            } else if (current_mediator instanceof FilterMediator) {
                if (position[counter] == 0) {
                    if (((FilterMediator) current_mediator).getElseMediator() != null) {
                        current_mediator = ((FilterMediator) current_mediator).getElseMediator();
                    } else if (((FilterMediator) current_mediator).getElseKey() != null) {
                        current_mediator = synCfg.getSequence(((FilterMediator) current_mediator).getElseKey());
                    }
                    continue;
                } else if (position[counter] == 1) {
                    if (((FilterMediator) current_mediator).getThenKey() != null) {
                        current_mediator = synCfg.getSequence(((FilterMediator) current_mediator).getThenKey());
                    } else {
                        counter = counter + 1;
                        if (counter < position.length) {
                            int mediatorCount = ((AbstractListMediator) current_mediator).getList().size();
                            int correctedPosition = getCorrectedPossition((AbstractListMediator) current_mediator, position[counter]);
                            if (mediatorCount > correctedPosition) {
                                current_mediator = ((AbstractListMediator) current_mediator).getChild(correctedPosition);
                            } else {
                                log.warn("Mediator position requested is larger than last index : " + position[counter]);
                            }
                        }
                    }
                    continue;
                }
            } else if (current_mediator instanceof SwitchMediator) {
                if (position[counter] == 0) {
                    SwitchCase switchCase = ((SwitchMediator) current_mediator).getDefaultCase();
                    if (switchCase != null) {
                        current_mediator = switchCase.getCaseMediator();
                    } else {
                        current_mediator = null;
                    }
                } else {
                    SwitchCase switchCase = ((SwitchMediator) current_mediator).getCases().get(position[counter] - 1);
                    if (switchCase != null) {
                        current_mediator = switchCase.getCaseMediator();
                    } else {
                        current_mediator = null;
                    }
                }
                continue;
            } else if (current_mediator instanceof AggregateMediator) {
                if (((AggregateMediator) current_mediator).getOnCompleteSequence() != null) {
                    current_mediator = ((AggregateMediator) current_mediator).getOnCompleteSequence();
                } else if (((AggregateMediator) current_mediator).getOnCompleteSequenceRef() != null) {
                    current_mediator = synCfg.getSequence(((AggregateMediator) current_mediator).getOnCompleteSequenceRef());
                }
            } else if (current_mediator instanceof ForEachMediator) {
                if (((ForEachMediator) current_mediator).getSequence() != null) {
                    current_mediator = ((ForEachMediator) current_mediator).getSequence();
                } else if (((ForEachMediator) current_mediator).getSequenceRef() != null) {
                    current_mediator = synCfg.getSequence(((ForEachMediator) current_mediator).getSequenceRef());
                }
            } else if (current_mediator instanceof IterateMediator) {
                if (((IterateMediator) current_mediator).getTarget().getSequence() != null) {
                    current_mediator = ((IterateMediator) current_mediator).getTarget().getSequence();
                } else if (((IterateMediator) current_mediator).getTarget().getSequenceRef() != null) {
                    current_mediator = synCfg.getSequence(((IterateMediator) current_mediator).getTarget().getSequenceRef());
                }
            } else if (current_mediator instanceof CloneMediator) {
                if (((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequence() != null) {
                    current_mediator = ((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequence();
                } else if (((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequenceRef() != null) {
                    current_mediator = synCfg.getSequence(((CloneMediator) current_mediator).getTargets().get(position[counter]).getSequenceRef());
                }
                continue;
            } else if (current_mediator.getType().equals("ThrottleMediator")) {
                current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, position[counter]);
                continue;
            } else if (current_mediator.getType().equals("EntitlementMediator")) {
                current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, position[counter]);
                continue;
            } else if (current_mediator.getType().equals("CacheMediator")) {
                current_mediator = ((EnclosedInlinedSequence) current_mediator).getInlineSequence(synCfg, 0);
            }
            if (current_mediator != null && (current_mediator instanceof AbstractListMediator)) {
                int mediatorCount = ((AbstractListMediator) current_mediator).getList().size();
                int correctedPosition = getCorrectedPossition((AbstractListMediator) current_mediator, position[counter]);
                if (mediatorCount > correctedPosition) {
                    current_mediator = ((AbstractListMediator) current_mediator).getChild(correctedPosition);
                } else {
                    log.warn("Mediator position requested is larger than last index : " + position[counter]);
                }
            } else {
                current_mediator = null;
                break;
            }
        }
    }
    return current_mediator;
}
Also used : AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator) SwitchCase(org.apache.synapse.config.xml.SwitchCase) AggregateMediator(org.apache.synapse.mediators.eip.aggregator.AggregateMediator) ForEachMediator(org.apache.synapse.mediators.builtin.ForEachMediator) EnclosedInlinedSequence(org.apache.synapse.debug.constructs.EnclosedInlinedSequence) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) SwitchMediator(org.apache.synapse.mediators.filters.SwitchMediator) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) ForEachMediator(org.apache.synapse.mediators.builtin.ForEachMediator) IterateMediator(org.apache.synapse.mediators.eip.splitter.IterateMediator) CommentMediator(org.apache.synapse.mediators.builtin.CommentMediator) FilterMediator(org.apache.synapse.mediators.filters.FilterMediator) CloneMediator(org.apache.synapse.mediators.eip.splitter.CloneMediator) Mediator(org.apache.synapse.Mediator) AggregateMediator(org.apache.synapse.mediators.eip.aggregator.AggregateMediator) AbstractListMediator(org.apache.synapse.mediators.AbstractListMediator) SwitchMediator(org.apache.synapse.mediators.filters.SwitchMediator) IterateMediator(org.apache.synapse.mediators.eip.splitter.IterateMediator) CloneMediator(org.apache.synapse.mediators.eip.splitter.CloneMediator)

Example 4 with InvokeMediator

use of org.apache.synapse.mediators.template.InvokeMediator in project wso2-synapse by wso2.

the class InvokeMediatorFactory method createSpecificMediator.

@Override
protected Mediator createSpecificMediator(OMElement elem, Properties properties) {
    invoker = new InvokeMediator();
    processAuditStatus(invoker, elem);
    OMAttribute targetTemplateAttr = elem.getAttribute(ATT_TARGET);
    if (targetTemplateAttr != null) {
        invoker.setTargetTemplate(targetTemplateAttr.getAttributeValue());
        buildParameters(elem);
    } else {
        String msg = "EIP Invoke mediator should have a target template specified.";
        log.error(msg);
        throw new SynapseException(msg);
    }
    return invoker;
}
Also used : SynapseException(org.apache.synapse.SynapseException) InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) OMAttribute(org.apache.axiom.om.OMAttribute)

Example 5 with InvokeMediator

use of org.apache.synapse.mediators.template.InvokeMediator in project wso2-synapse by wso2.

the class InvokeMediatorSerializer method serializeSpecificMediator.

@Override
protected OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof InvokeMediator)) {
        handleException("Unsupported mediator passed in for serialization : " + m.getType());
    }
    InvokeMediator mediator = (InvokeMediator) m;
    OMElement invokeElem = null;
    if (mediator.isDynamicMediator()) {
        String packageName = (mediator.getPackageName() != null && !mediator.getPackageName().isEmpty()) ? mediator.getPackageName() : "";
        invokeElem = fac.createOMElement(mediator.getTargetTemplate().substring(packageName.length() + 1, mediator.getTargetTemplate().length()), synNS);
        if (mediator.getKey() != null) {
            // Serialize Value using ValueSerializer
            ValueSerializer keySerializer = new ValueSerializer();
            keySerializer.serializeValue(mediator.getKey(), XMLConfigConstants.CONFIG_REF, invokeElem);
        }
    } else {
        invokeElem = fac.createOMElement(INVOKE_N, synNS);
    }
    if (mediator.getTargetTemplate() != null) {
        if (!mediator.isDynamicMediator()) {
            invokeElem.addAttribute(fac.createOMAttribute("target", nullNS, mediator.getTargetTemplate()));
        }
        serializeParams(invokeElem, mediator);
        saveTracingState(invokeElem, mediator);
    }
    return invokeElem;
}
Also used : InvokeMediator(org.apache.synapse.mediators.template.InvokeMediator) OMElement(org.apache.axiom.om.OMElement)

Aggregations

InvokeMediator (org.apache.synapse.mediators.template.InvokeMediator)6 OMAttribute (org.apache.axiom.om.OMAttribute)2 OMElement (org.apache.axiom.om.OMElement)2 QName (javax.xml.namespace.QName)1 Mediator (org.apache.synapse.Mediator)1 SynapseException (org.apache.synapse.SynapseException)1 SwitchCase (org.apache.synapse.config.xml.SwitchCase)1 EnclosedInlinedSequence (org.apache.synapse.debug.constructs.EnclosedInlinedSequence)1 AbstractListMediator (org.apache.synapse.mediators.AbstractListMediator)1 Value (org.apache.synapse.mediators.Value)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 CommentMediator (org.apache.synapse.mediators.builtin.CommentMediator)1 ForEachMediator (org.apache.synapse.mediators.builtin.ForEachMediator)1 AggregateMediator (org.apache.synapse.mediators.eip.aggregator.AggregateMediator)1 CloneMediator (org.apache.synapse.mediators.eip.splitter.CloneMediator)1 IterateMediator (org.apache.synapse.mediators.eip.splitter.IterateMediator)1 FilterMediator (org.apache.synapse.mediators.filters.FilterMediator)1 SwitchMediator (org.apache.synapse.mediators.filters.SwitchMediator)1