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