Package org.apache.synapse.rest

Examples of org.apache.synapse.rest.API


    public API getAPI(String name) {
        return apiTable.get(name);
    }

    public void removeAPI(String name) {
        API api = apiTable.get(name);
        if (api != null) {
            apiTable.remove(name);
        } else {
            handleException("No API exists by the name: " + name);
        }
View Full Code Here


        OMAttribute contextAtt = apiElt.getAttribute(new QName("context"));
        if (contextAtt == null || "".equals(contextAtt.getAttributeValue())) {
            handleException("Attribute 'context' is required for an API definition");
        }

        API api = new API(nameAtt.getAttributeValue(), contextAtt.getAttributeValue());

        OMAttribute hostAtt = apiElt.getAttribute(new QName("hostname"));
        if (hostAtt != null && !"".equals(hostAtt.getAttributeValue())) {
            api.setHost(hostAtt.getAttributeValue());
        }

        OMAttribute portAtt = apiElt.getAttribute(new QName("port"));
        if (portAtt != null && !"".equals(portAtt.getAttributeValue())) {
            api.setPort(Integer.parseInt(portAtt.getAttributeValue()));
        }

        Iterator resources = apiElt.getChildrenWithName(new QName(
                XMLConfigConstants.SYNAPSE_NAMESPACE, "resource"));
        boolean noResources = true;
        while (resources.hasNext()) {
            OMElement resourceElt = (OMElement) resources.next();
            api.addResource(ResourceFactory.createResource(resourceElt));
            noResources = false;
        }

        if (noResources) {
            handleException("An API must contain at least one resource definition");
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("API deployment from file : " + fileName + " : Started");
        }

        try {
            API api = APIFactory.createAPI(artifactConfig);
            if (api != null) {
                api.setFileName((new File(fileName)).getName());
                if (log.isDebugEnabled()) {
                    log.debug("API named '" + api.getName()
                            + "' has been built from the file " + fileName);
                }
                api.init(getSynapseEnvironment());
                if (log.isDebugEnabled()) {
                    log.debug("Initialized the API: " + api.getName());
                }
                getSynapseConfiguration().addAPI(api.getName(), api);
                if (log.isDebugEnabled()) {
                    log.debug("API deployment from file : " + fileName + " : Completed");
                }
                log.info("API named '" + api.getName() +
                        "' has been deployed from file : " + fileName);
                return api.getName();
            } else {
                handleSynapseArtifactDeploymentError("API deployment Failed. The artifact " +
                        "described in the file " + fileName + " is not a valid API");
            }
        } catch (Exception e) {
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("API update from file : " + fileName + " has started");
        }

        try {
            API api = APIFactory.createAPI(artifactConfig);
            if (api == null) {
                handleSynapseArtifactDeploymentError("API update failed. The artifact " +
                        "defined in the file: " + fileName + " is not a valid API.");
                return null;
            }
            api.setFileName(new File(fileName).getName());

            if (log.isDebugEnabled()) {
                log.debug("API: " + api.getName() + " has been built from the file: " + fileName);
            }

            api.init(getSynapseEnvironment());
            API existingAPI = getSynapseConfiguration().getAPI(existingArtifactName);
            if (existingArtifactName.equals(api.getName())) {
                getSynapseConfiguration().updateAPI(existingArtifactName, api);
            } else {
                // The user has changed the name of the API
                // We should add the updated API as a new API and remove the old one
                getSynapseConfiguration().addAPI(api.getName(), api);
                getSynapseConfiguration().removeAPI(existingArtifactName);
                log.info("API: " + existingArtifactName + " has been undeployed");
            }

            log.info("API: " + api.getName() + " has been updated from the file: " + fileName);

            waitForCompletion();
            existingAPI.destroy();
            return api.getName();

        } catch (DeploymentException e) {
            handleSynapseArtifactDeploymentError("Error while updating the API from the " +
                    "file: " + fileName);
View Full Code Here

            log.debug("Undeployment of the API named : "
                    + artifactName + " : Started");
        }

        try {
            API api = getSynapseConfiguration().getAPI(artifactName);
            if (api != null) {
                getSynapseConfiguration().removeAPI(artifactName);
                if (log.isDebugEnabled()) {
                    log.debug("Undeployment of the API named : "
                            + artifactName + " : Completed");
                }
                log.info("API named '" + api.getName() + "' has been undeployed");
            } else if (log.isDebugEnabled()) {
                log.debug("API " + artifactName + " has already been undeployed");
            }
        } catch (Exception e) {
            handleSynapseArtifactDeploymentError(
View Full Code Here

        if (log.isDebugEnabled()) {
            log.debug("Restoring the API with name : " + artifactName + " : Started");
        }

        try {
            API api = getSynapseConfiguration().getAPI(artifactName);
            OMElement apiElement = APISerializer.serializeAPI(api);
            if (api.getFileName() != null) {
                String fileName = getServerConfigurationInformation().getSynapseXMLLocation()
                        + File.separator + MultiXMLConfigurationBuilder.REST_API_DIR
                        + File.separator + api.getFileName();
                writeToFile(apiElement, fileName);
                if (log.isDebugEnabled()) {
                    log.debug("Restoring the API with name : " + artifactName + " : Completed");
                }
                log.info("API named '" + artifactName + "' has been restored");
View Full Code Here

            defineEndpointTemplate(config, elem, properties);
        }
    }

    public static void defineAPI(SynapseConfiguration config, OMElement elem) {
        API api = APIFactory.createAPI(elem);
        config.addAPI(api.getName(), api);
    }
View Full Code Here

    public void testAPISerialization1() throws Exception {
        String xml = "<api name=\"test\" context=\"/dictionary\" xmlns=\"http://ws.apache.org/ns/synapse\">" +
                "<resource url-mapping=\"/admin/view\" inSequence=\"in\" outSequence=\"out\"/></api>";
        OMElement om = AXIOMUtil.stringToOM(xml);
        API api = APIFactory.createAPI(om);
        OMElement out = APISerializer.serializeAPI(api);
        assertXMLEqual(xml, out.toString());
    }
View Full Code Here

    public void testAPISerialization2() throws Exception {
        String xml = "<api name=\"test\" context=\"/dictionary\" hostname=\"apache.org\" port=\"8243\"" +
                " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view\" " +
                "inSequence=\"in\" outSequence=\"out\"/></api>";
        OMElement om = AXIOMUtil.stringToOM(xml);
        API api = APIFactory.createAPI(om);
        OMElement out = APISerializer.serializeAPI(api);
        assertXMLEqual(xml, out.toString());
    }
View Full Code Here

    public void testAPISerialization3() throws Exception {
        String xml = "<api name=\"test\" context=\"/dictionary\" hostname=\"apache.org\" port=\"8243\"" +
                " xmlns=\"http://ws.apache.org/ns/synapse\"><resource url-mapping=\"/admin/view\" " +
                "inSequence=\"in\"><outSequence><log/><send/></outSequence></resource></api>";
        OMElement om = AXIOMUtil.stringToOM(xml);
        API api = APIFactory.createAPI(om);
        OMElement out = APISerializer.serializeAPI(api);
        assertXMLEqual(xml, out.toString());
    }
View Full Code Here

TOP

Related Classes of org.apache.synapse.rest.API

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.