Search in sources :

Example 1 with DispatcherHelper

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);
}
Also used : DispatcherHelper(org.apache.synapse.rest.dispatch.DispatcherHelper)

Example 2 with DispatcherHelper

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

DispatcherHelper (org.apache.synapse.rest.dispatch.DispatcherHelper)2 OMElement (org.apache.axiom.om.OMElement)1 SequenceMediatorSerializer (org.apache.synapse.config.xml.SequenceMediatorSerializer)1 URITemplateHelper (org.apache.synapse.rest.dispatch.URITemplateHelper)1 URLMappingHelper (org.apache.synapse.rest.dispatch.URLMappingHelper)1