use of org.wso2.carbon.rest.api.APIException in project carbon-mediation by wso2.
the class RestApiAdmin method disableStatistics.
public String disableStatistics(String apiName) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
API api = synapseConfiguration.getAPI(apiName);
if (api != null) {
if (api.getAspectConfiguration() == null) {
AspectConfiguration config = new AspectConfiguration(apiName);
config.disableStatistics();
api.configure(config);
} else {
api.getAspectConfiguration().disableStatistics();
}
/**
* Persist the api service if it is not deployed via an artifact container
*/
if (api.getArtifactContainerName() == null) {
persistApi(api);
}
return apiName;
} else {
handleException(log, "No defined API with name " + apiName + " found to disable statistics in the Synapse configuration", null);
}
} catch (Exception fault) {
handleException(log, "Couldn't disable statistics of the API " + apiName + " : " + fault.getMessage(), fault);
} finally {
lock.unlock();
}
return null;
}
use of org.wso2.carbon.rest.api.APIException in project carbon-mediation by wso2.
the class RestApiAdmin method handleException.
private void handleException(Log log, String message, Exception e) throws APIException {
if (e == null) {
APIException apiException = new APIException(message);
log.error(message, apiException);
throw apiException;
} else {
message = message + " :: " + e.getMessage();
log.error(message, e);
throw new APIException(message, e);
}
}
use of org.wso2.carbon.rest.api.APIException in project carbon-mediation by wso2.
the class RestApiAdmin method getSwaggerDocument.
/**
* Return the registry resource for the provided location
*
* @param apiName
* @param tenantId
* @return
* @throws APIException
*/
public String getSwaggerDocument(String apiName, int tenantId) throws APIException {
API api = getSynapseAPIByName(apiName);
if (api == null) {
throw new APIException("API with name \"" + apiName + "\" does not exists.");
}
String resourcePath = getSwaggerResourcePath(api);
String swaggerJsonString = null;
if (resourcePath.startsWith(CONFIG_REG_PREFIX) || resourcePath.startsWith(GOV_REG_PREFIX)) {
try {
swaggerJsonString = getResourceFromRegistry(resourcePath, tenantId);
} catch (RegistryException e) {
handleException(log, "Could not get swagger document", e);
}
} else {
// Read from URI
try {
swaggerJsonString = readFromURI(resourcePath);
} catch (IOException e) {
log.error("Error occurred while reading swagger definition from: " + resourcePath, e);
}
}
// Generate if not available
if (swaggerJsonString == null) {
if (log.isDebugEnabled()) {
log.debug("Generate swagger definition for the API : " + apiName);
}
swaggerJsonString = generateSwaggerFromSynapseAPI(api);
}
return swaggerJsonString;
}
use of org.wso2.carbon.rest.api.APIException in project carbon-mediation by wso2.
the class RestApiAdmin method deleteApi.
public boolean deleteApi(String apiName) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
assertNameNotEmpty(apiName);
apiName = apiName.trim();
SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
API api = synapseConfiguration.getAPI(apiName);
if (api.getArtifactContainerName() == null) {
if (log.isDebugEnabled()) {
log.debug("Deleting API : " + apiName + " from the configuration");
}
api.destroy();
synapseConfiguration.removeAPI(apiName);
if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode")) && saveRuntimeArtifacts) {
MediationPersistenceManager pm = getMediationPersistenceManager();
String fileName = api.getFileName();
pm.deleteItem(apiName, fileName, ServiceBusConstants.ITEM_TYPE_REST_API);
}
if (log.isDebugEnabled()) {
log.debug("Api : " + apiName + " removed from the configuration");
}
}
} finally {
lock.unlock();
}
return true;
}
use of org.wso2.carbon.rest.api.APIException in project carbon-mediation by wso2.
the class RestApiAdmin method enableStatistics.
public String enableStatistics(String apiName) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
API api = synapseConfiguration.getAPI(apiName);
if (api != null) {
if (api.getAspectConfiguration() == null) {
AspectConfiguration config = new AspectConfiguration(apiName);
config.enableStatistics();
api.configure(config);
} else {
api.getAspectConfiguration().enableStatistics();
}
/**
* Persist the api service if it is not deployed via an artifact container
*/
if (api.getArtifactContainerName() == null) {
persistApi(api);
}
return apiName;
} else {
handleException(log, "No defined API with name " + apiName + " found to enable statistics in the Synapse configuration", null);
}
} catch (Exception fault) {
handleException(log, "Couldn't enable statistics of the API " + apiName + " : " + fault.getMessage(), fault);
} finally {
lock.unlock();
}
return null;
}
Aggregations