Search in sources :

Example 1 with API

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

the class SynapseConfiguration method updateAPI.

public synchronized void updateAPI(String name, API api) {
    if (!apiTable.containsKey(name)) {
        handleException("No API exists by the name: " + name);
    } else {
        for (API existingAPI : apiTable.values()) {
            if (!api.getName().equals(existingAPI.getName()) && api.getVersion().equals(existingAPI.getVersion()) && existingAPI.getContext().equals(api.getContext())) {
                handleException("URL context: " + api.getContext() + " is already registered" + " with the API: " + existingAPI.getName());
            }
        }
        apiTable.put(name, api);
        removeBindsToMappings(name);
        addBindsToMappings(name, api);
        reconstructAPITable();
        for (SynapseObserver o : observers) {
            o.apiUpdated(api);
        }
    }
}
Also used : API(org.apache.synapse.api.API)

Example 2 with API

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

the class SynapseConfiguration method removeAPI.

public synchronized void removeAPI(String name) {
    API api = apiTable.get(name);
    if (api != null) {
        apiTable.remove(name);
        removeBindsToMappings(name);
        for (SynapseObserver o : observers) {
            o.apiRemoved(api);
        }
    } else {
        handleException("No API exists by the name: " + name);
    }
}
Also used : API(org.apache.synapse.api.API)

Example 3 with API

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

the class SynapseConfiguration method addAPI.

public synchronized void addAPI(String name, API api, boolean reOrder) {
    if (!apiTable.containsKey(name)) {
        for (API existingAPI : apiTable.values()) {
            if (api.getVersion().equals(existingAPI.getVersion()) && existingAPI.getContext().equals(api.getContext())) {
                handleException("URL context: " + api.getContext() + " is already registered" + " with the API: " + existingAPI.getName());
            }
        }
        apiTable.put(name, api);
        addBindsToMappings(name, api);
        if (reOrder) {
            reconstructAPITable();
        }
        for (SynapseObserver o : observers) {
            o.apiAdded(api);
        }
    } else {
        handleException("Duplicate resource definition by the name: " + name);
    }
}
Also used : API(org.apache.synapse.api.API)

Example 4 with API

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

the class APIDeployer method updateSynapseArtifact.

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

Example 5 with API

use of org.apache.synapse.api.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);
            // Remove swagger of the API
            getSynapseConfiguration().removeSwaggerFromTheAPI(artifactName);
            if (log.isDebugEnabled()) {
                log.debug("Undeployment of the API named : " + artifactName + " : Completed");
            }
            String unDeployTime = String.valueOf(System.currentTimeMillis());
            executeSynapseHandlerOnArtifactUnDeployment(api.getName(), SynapseConstants.FAIL_SAFE_MODE_API, unDeployTime);
            log.info("API named '" + api.getName() + "' has been undeployed");
            api.destroy();
        } 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.api.API) DeploymentException(org.apache.axis2.deployment.DeploymentException)

Aggregations

API (org.apache.synapse.api.API)64 MessageContext (org.apache.synapse.MessageContext)33 SynapseConfiguration (org.apache.synapse.config.SynapseConfiguration)33 Resource (org.apache.synapse.api.Resource)23 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)14 OMElement (org.apache.axiom.om.OMElement)10 URLMappingHelper (org.apache.synapse.api.dispatch.URLMappingHelper)7 Test (org.junit.Test)6 URITemplateHelper (org.apache.synapse.api.dispatch.URITemplateHelper)5 Cache (javax.cache.Cache)4 DeploymentException (org.apache.axis2.deployment.DeploymentException)4 SynapseException (org.apache.synapse.SynapseException)4 ContextVersionStrategy (org.apache.synapse.api.version.ContextVersionStrategy)4 ProxyService (org.apache.synapse.core.axis2.ProxyService)4 InboundEndpoint (org.apache.synapse.inbound.InboundEndpoint)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 CacheProvider (org.wso2.carbon.apimgt.impl.caching.CacheProvider)4 ArrayList (java.util.ArrayList)3