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;
}
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;
}
Aggregations