use of org.apache.synapse.rest.dispatch.DispatcherHelper in project wso2-synapse by wso2.
the class API method addResource.
public void addResource(Resource resource) {
DispatcherHelper dispatcherHelper = resource.getDispatcherHelper();
if (dispatcherHelper != null) {
String mapping = dispatcherHelper.getString();
for (Resource r : resources.values()) {
DispatcherHelper helper = r.getDispatcherHelper();
if (helper != null && helper.getString().equals(mapping) && resourceMatches(resource, r)) {
handleException("Two resources cannot have the same path mapping and methods");
}
}
} else {
for (Resource r : resources.values()) {
DispatcherHelper helper = r.getDispatcherHelper();
if (helper == null) {
handleException("Only one resource can be designated as default");
}
}
}
resources.put(resource.getName(), resource);
}
use of org.apache.synapse.rest.dispatch.DispatcherHelper 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