Search in sources :

Example 1 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class APIDeployer method updateSynapseArtifact.

@Override
public String updateSynapseArtifact(OMElement artifactConfig, String fileName, String existingArtifactName, Properties properties) {
    API api = APIFactory.createAPI(artifactConfig, properties);
    if (api != null) {
        api.setLogSetterValue();
    }
    if (log.isDebugEnabled()) {
        log.debug("API update from file : " + fileName + " has started");
    }
    try {
        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);
    }
    return null;
}
Also used : API(org.apache.synapse.rest.API) DeploymentException(org.apache.axis2.deployment.DeploymentException) File(java.io.File)

Example 2 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class APIDeployer method restoreSynapseArtifact.

@Override
public void restoreSynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Restoring the API with name : " + artifactName + " : Started");
    }
    try {
        API api = getSynapseConfiguration().getAPI(artifactName);
        if (api != null) {
            api.setLogSetterValue();
        }
        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");
        } else {
            handleSynapseArtifactDeploymentError("Couldn't restore the API named '" + artifactName + "', filename cannot be found");
        }
    } catch (Exception e) {
        handleSynapseArtifactDeploymentError("Restoring of the API named '" + artifactName + "' has failed", e);
    }
}
Also used : API(org.apache.synapse.rest.API) OMElement(org.apache.axiom.om.OMElement) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 3 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class APIDeployer method undeploySynapseArtifact.

@Override
public void undeploySynapseArtifact(String artifactName) {
    if (log.isDebugEnabled()) {
        log.debug("Undeployment of the API named : " + artifactName + " : Started");
    }
    try {
        API api = getSynapseConfiguration().getAPI(artifactName);
        if (api != null) {
            api.setLogSetterValue();
            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("Undeployment of API named : " + artifactName + " : Failed", e);
    }
}
Also used : API(org.apache.synapse.rest.API) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Example 4 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class APISerializationTest method testAPISerialization3.

public void testAPISerialization3() throws Exception {
    String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" 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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) API(org.apache.synapse.rest.API)

Example 5 with API

use of org.apache.synapse.rest.API in project wso2-synapse by wso2.

the class APISerializationTest method testAPISerialization1.

public void testAPISerialization1() throws Exception {
    String xml = "<api name=\"test\" context=\"/dictionary\" transports=\"https\" 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());
}
Also used : OMElement(org.apache.axiom.om.OMElement) API(org.apache.synapse.rest.API)

Aggregations

API (org.apache.synapse.rest.API)26 OMElement (org.apache.axiom.om.OMElement)10 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 PriorityExecutor (org.apache.synapse.commons.executors.PriorityExecutor)3 Endpoint (org.apache.synapse.endpoints.Endpoint)3 TemplateMediator (org.apache.synapse.mediators.template.TemplateMediator)3 MessageProcessor (org.apache.synapse.message.processor.MessageProcessor)3 MessageStore (org.apache.synapse.message.store.MessageStore)3 Resource (org.apache.synapse.rest.Resource)3 File (java.io.File)2 Iterator (java.util.Iterator)2 ManagedLifecycle (org.apache.synapse.ManagedLifecycle)2 Mediator (org.apache.synapse.Mediator)2 APIMediationFlowPoint (org.apache.synapse.debug.constructs.APIMediationFlowPoint)2 SynapseMediationFlowPoint (org.apache.synapse.debug.constructs.SynapseMediationFlowPoint)2 SynapseSequenceType (org.apache.synapse.debug.constructs.SynapseSequenceType)2 AbstractMediator (org.apache.synapse.mediators.AbstractMediator)2