Search in sources :

Example 6 with Source

use of org.apache.synapse.mediators.elementary.Source in project wso2-synapse by wso2.

the class CallMediatorSerializer method serializeSource.

private OMElement serializeSource(CallMediator mediator) {
    Source source = mediator.getSourceForOutboundPayload();
    String sourceContentType = mediator.getSourceMessageType();
    OMElement sourceEle = fac.createOMElement("source", synNS);
    sourceEle.addAttribute(fac.createOMAttribute("type", nullNS, intTypeToString(source.getSourceType())));
    if (sourceContentType != null) {
        sourceEle.addAttribute(fac.createOMAttribute("contentType", nullNS, sourceContentType));
    }
    if (source.getSourceType() == EnrichMediator.PROPERTY) {
        sourceEle.setText(source.getProperty());
    } else if (source.getSourceType() == EnrichMediator.CUSTOM) {
        sourceEle.setText(source.getXpath().toString());
    } else if (source.getSourceType() == EnrichMediator.INLINE) {
        if (source.getInlineOMNode() instanceof OMElement) {
            sourceEle.addChild(((OMElement) source.getInlineOMNode()).cloneOMElement());
        } else if (source.getInlineOMNode() instanceof OMText) {
            sourceEle.setText(((OMText) source.getInlineOMNode()).getText());
        }
    }
    return sourceEle;
}
Also used : OMText(org.apache.axiom.om.OMText) OMElement(org.apache.axiom.om.OMElement) Source(org.apache.synapse.mediators.elementary.Source)

Example 7 with Source

use of org.apache.synapse.mediators.elementary.Source in project wso2-synapse by wso2.

the class CallMediatorFactory method createSpecificMediator.

public Mediator createSpecificMediator(OMElement elem, Properties properties) {
    CallMediator callMediator = new CallMediator();
    // after successfully creating the mediator
    // set its common attributes such as tracing etc
    processAuditStatus(callMediator, elem);
    OMElement sourceEle = elem.getFirstChildWithName(SOURCE_Q);
    if (sourceEle != null) {
        Source source = new Source();
        populateSource(callMediator, source, sourceEle);
        callMediator.setSourceForOutboundPayload(source);
    }
    OMElement targetEle = elem.getFirstChildWithName(TARGET_Q);
    if (targetEle != null) {
        Target target = new Target();
        populateTarget(callMediator, target, targetEle);
        callMediator.setTargetForInboundPayload(target);
    }
    OMElement epElement = elem.getFirstChildWithName(ENDPOINT_Q);
    if (epElement != null) {
        // create the endpoint and set it in the call mediator
        Endpoint endpoint = EndpointFactory.getEndpointFromElement(epElement, true, properties);
        if (endpoint != null) {
            callMediator.setEndpoint(endpoint);
        }
    }
    OMAttribute blockingAtt = elem.getAttribute(BLOCKING_Q);
    if (blockingAtt != null) {
        callMediator.setBlocking(Boolean.parseBoolean(blockingAtt.getAttributeValue()));
        if (callMediator.isBlocking()) {
            OMAttribute initAxis2ClientOptions = elem.getAttribute(ATT_INIT_AXIS2_CLIENT_OPTIONS);
            OMAttribute axis2xmlAttr = elem.getAttribute(ATT_AXIS2XML);
            OMAttribute repoAttr = elem.getAttribute(ATT_REPOSITORY);
            if (initAxis2ClientOptions != null) {
                callMediator.setInitClientOptions(Boolean.parseBoolean(initAxis2ClientOptions.getAttributeValue()));
            }
            if (axis2xmlAttr != null && axis2xmlAttr.getAttributeValue() != null) {
                File axis2xml = new File(axis2xmlAttr.getAttributeValue());
                if (axis2xml.exists() && axis2xml.isFile()) {
                    callMediator.setAxis2xml(axis2xmlAttr.getAttributeValue());
                } else {
                    handleException("Invalid axis2.xml path: " + axis2xmlAttr.getAttributeValue());
                }
            }
            if (repoAttr != null && repoAttr.getAttributeValue() != null) {
                File repo = new File(repoAttr.getAttributeValue());
                if (repo.exists() && repo.isDirectory()) {
                    callMediator.setClientRepository(repoAttr.getAttributeValue());
                } else {
                    handleException("Invalid repository path: " + repoAttr.getAttributeValue());
                }
            }
        }
    }
    addAllCommentChildrenToList(elem, callMediator.getCommentsList());
    return callMediator;
}
Also used : Target(org.apache.synapse.mediators.elementary.Target) Endpoint(org.apache.synapse.endpoints.Endpoint) OMElement(org.apache.axiom.om.OMElement) CallMediator(org.apache.synapse.mediators.builtin.CallMediator) OMAttribute(org.apache.axiom.om.OMAttribute) File(java.io.File) Source(org.apache.synapse.mediators.elementary.Source)

Example 8 with Source

use of org.apache.synapse.mediators.elementary.Source in project wso2-synapse by wso2.

the class CallMediatorEnrichUtil method createSourceWithBody.

public static Source createSourceWithBody() {
    Source source = new Source();
    source.setClone(false);
    source.setSourceType(CallMediatorEnrichUtil.convertTypeToInt("body"));
    return source;
}
Also used : Source(org.apache.synapse.mediators.elementary.Source)

Aggregations

Source (org.apache.synapse.mediators.elementary.Source)8 Target (org.apache.synapse.mediators.elementary.Target)5 OMElement (org.apache.axiom.om.OMElement)3 Map (java.util.Map)2 OMText (org.apache.axiom.om.OMText)2 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 JsonParser (com.google.gson.JsonParser)1 JsonPrimitive (com.google.gson.JsonPrimitive)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 File (java.io.File)1 HashMap (java.util.HashMap)1 OMAttribute (org.apache.axiom.om.OMAttribute)1 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)1 Endpoint (org.apache.synapse.endpoints.Endpoint)1 CallMediator (org.apache.synapse.mediators.builtin.CallMediator)1 EnrichMediator (org.apache.synapse.mediators.elementary.EnrichMediator)1