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