Search in sources :

Example 1 with SequenceMediatorSerializer

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

the class ThrottleMediatorSerializer method serializeSpecificMediator.

public OMElement serializeSpecificMediator(Mediator m) {
    if (!(m instanceof ThrottleMediator)) {
        handleException("Invalid Mediator has passed to serializer");
    }
    ThrottleMediator throttleMediator = (ThrottleMediator) m;
    OMElement throttle = fac.createOMElement("throttle", synNS);
    OMElement policy = fac.createOMElement("policy", synNS);
    String key = throttleMediator.getPolicyKey();
    if (key != null) {
        policy.addAttribute(fac.createOMAttribute("key", nullNS, key));
        throttle.addChild(policy);
    } else {
        OMNode inlinePolicy = throttleMediator.getInLinePolicy();
        if (inlinePolicy != null) {
            policy.addChild(inlinePolicy);
            throttle.addChild(policy);
        }
    }
    saveTracingState(throttle, throttleMediator);
    String id = throttleMediator.getId();
    if (id != null) {
        throttle.addAttribute(fac.createOMAttribute("id", nullNS, id));
    }
    String onReject = throttleMediator.getOnRejectSeqKey();
    if (onReject != null) {
        throttle.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONREJECT, nullNS, onReject));
    } else {
        Mediator mediator = throttleMediator.getOnRejectMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (mediator != null && mediator instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) mediator);
            element.setLocalName(XMLConfigConstants.ONREJECT);
            throttle.addChild(element);
        }
    }
    String onAccept = throttleMediator.getOnAcceptSeqKey();
    if (onAccept != null) {
        throttle.addAttribute(fac.createOMAttribute(XMLConfigConstants.ONACCEPT, nullNS, onAccept));
    } else {
        Mediator mediator = throttleMediator.getOnAcceptMediator();
        SequenceMediatorSerializer serializer = new SequenceMediatorSerializer();
        if (mediator != null && mediator instanceof SequenceMediator) {
            OMElement element = serializer.serializeAnonymousSequence(null, (SequenceMediator) mediator);
            element.setLocalName(XMLConfigConstants.ONACCEPT);
            throttle.addChild(element);
        }
    }
    return throttle;
}
Also used : OMNode(org.apache.axiom.om.OMNode) OMElement(org.apache.axiom.om.OMElement) Mediator(org.apache.synapse.Mediator) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator) SequenceMediatorSerializer(org.apache.synapse.config.xml.SequenceMediatorSerializer) SequenceMediator(org.apache.synapse.mediators.base.SequenceMediator)

Example 2 with SequenceMediatorSerializer

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

the class ResourceSerializer method serializeResource.

public static OMElement serializeResource(Resource resource) {
    OMElement resourceElt = fac.createOMElement("resource", SynapseConstants.SYNAPSE_OMNAMESPACE);
    String[] methods = resource.getMethods();
    if (methods.length > 0) {
        String value = "";
        for (String method : methods) {
            value += method + " ";
        }
        resourceElt.addAttribute("methods", value.trim(), null);
    }
    if (resource.getContentType() != null) {
        resourceElt.addAttribute("content-type", resource.getContentType(), null);
    }
    if (resource.getUserAgent() != null) {
        resourceElt.addAttribute("user-agent", resource.getUserAgent(), null);
    }
    if (resource.getProtocol() == RESTConstants.PROTOCOL_HTTP_ONLY) {
        resourceElt.addAttribute("protocol", "http", null);
    } else if (resource.getProtocol() == RESTConstants.PROTOCOL_HTTPS_ONLY) {
        resourceElt.addAttribute("protocol", "https", null);
    }
    DispatcherHelper helper = resource.getDispatcherHelper();
    if (helper != null) {
        if (helper instanceof URLMappingHelper) {
            resourceElt.addAttribute("url-mapping", helper.getString(), null);
        } else if (helper instanceof URITemplateHelper) {
            resourceElt.addAttribute("uri-template", helper.getString(), null);
        }
    }
    SequenceMediatorSerializer seqSerializer = new SequenceMediatorSerializer();
    if (resource.getInSequenceKey() != null) {
        resourceElt.addAttribute("inSequence", resource.getInSequenceKey(), null);
    } else if (resource.getInSequence() != null) {
        OMElement inSeqElement = seqSerializer.serializeAnonymousSequence(null, resource.getInSequence());
        inSeqElement.setLocalName("inSequence");
        resourceElt.addChild(inSeqElement);
    }
    if (resource.getOutSequenceKey() != null) {
        resourceElt.addAttribute("outSequence", resource.getOutSequenceKey(), null);
    } else if (resource.getOutSequence() != null) {
        OMElement outSeqElement = seqSerializer.serializeAnonymousSequence(null, resource.getOutSequence());
        outSeqElement.setLocalName("outSequence");
        resourceElt.addChild(outSeqElement);
    }
    if (resource.getFaultSequenceKey() != null) {
        resourceElt.addAttribute("faultSequence", resource.getFaultSequenceKey(), null);
    } else if (resource.getFaultSequence() != null) {
        OMElement faultSeqElement = seqSerializer.serializeAnonymousSequence(null, resource.getFaultSequence());
        faultSeqElement.setLocalName("faultSequence");
        resourceElt.addChild(faultSeqElement);
    }
    return resourceElt;
}
Also used : URITemplateHelper(org.apache.synapse.rest.dispatch.URITemplateHelper) DispatcherHelper(org.apache.synapse.rest.dispatch.DispatcherHelper) URLMappingHelper(org.apache.synapse.rest.dispatch.URLMappingHelper) OMElement(org.apache.axiom.om.OMElement) SequenceMediatorSerializer(org.apache.synapse.config.xml.SequenceMediatorSerializer)

Aggregations

OMElement (org.apache.axiom.om.OMElement)2 SequenceMediatorSerializer (org.apache.synapse.config.xml.SequenceMediatorSerializer)2 OMNode (org.apache.axiom.om.OMNode)1 Mediator (org.apache.synapse.Mediator)1 SequenceMediator (org.apache.synapse.mediators.base.SequenceMediator)1 DispatcherHelper (org.apache.synapse.rest.dispatch.DispatcherHelper)1 URITemplateHelper (org.apache.synapse.rest.dispatch.URITemplateHelper)1 URLMappingHelper (org.apache.synapse.rest.dispatch.URLMappingHelper)1