use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method enableTracing.
public String enableTracing(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.enableTracing();
// Need to enable statistics for tracing
config.enableStatistics();
api.configure(config);
} else {
api.getAspectConfiguration().enableTracing();
// Need to enable statistics for tracing
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 tracing in the Synapse configuration", null);
}
} catch (Exception fault) {
handleException(log, "Couldn't enable tracing of the API " + apiName + " : " + fault.getMessage(), fault);
} finally {
lock.unlock();
}
return null;
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method disableTracing.
public String disableTracing(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.disableTracing();
api.configure(config);
} else {
api.getAspectConfiguration().disableTracing();
}
/**
* 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 tracing in the Synapse configuration", null);
}
} catch (Exception fault) {
handleException(log, "Couldn't disable tracing of the API " + apiName + " : " + fault.getMessage(), fault);
} finally {
lock.unlock();
}
return null;
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method updateApiFromString.
public boolean updateApiFromString(String apiName, String apiData) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
assertNameNotEmpty(apiName);
OMElement apiElement = AXIOMUtil.stringToOM(apiData);
// Set API name to old value since we do not allow editing the API name.
OMAttribute nameAttribute = apiElement.getAttribute(new QName("name"));
if (nameAttribute == null || nameAttribute.getAttributeValue().trim().isEmpty()) {
apiElement.addAttribute("name", apiName, null);
}
// Need to attach synapse configuration to properties to identify synapse imports (Connectors)
// From Synapse level.
Properties properties = new Properties();
properties.put(SYNAPSE_CONFIGURATION, getSynapseConfiguration());
API api = APIFactory.createAPI(apiElement, properties);
SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
API oldAPI = synapseConfiguration.getAPI(apiName);
if (oldAPI != null) {
oldAPI.destroy();
api.setFileName(oldAPI.getFileName());
}
synapseConfiguration.removeAPI(apiName);
synapseConfiguration.addAPI(api.getName(), api);
api.init(getSynapseEnvironment());
if (oldAPI.getArtifactContainerName() != null) {
api.setArtifactContainerName(oldAPI.getArtifactContainerName());
api.setIsEdited(true);
getApiByName(api.getName()).setIsEdited(true);
} else {
if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode")) && saveRuntimeArtifacts) {
MediationPersistenceManager pm = getMediationPersistenceManager();
String fileName = api.getFileName();
pm.deleteItem(apiName, fileName, ServiceBusConstants.ITEM_TYPE_REST_API);
pm.saveItem(apiName, ServiceBusConstants.ITEM_TYPE_REST_API);
}
}
return true;
} catch (XMLStreamException e) {
handleException(log, "Could not parse String to OMElement", e);
return false;
} finally {
lock.unlock();
}
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method updateApi.
public boolean updateApi(String apiName, APIData apiData) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
assertNameNotEmpty(apiName);
API oldAPI = null;
// Need to attach synapse configuration to properties to identify synapse imports (Connectors)
// From Synapse level.
Properties properties = new Properties();
properties.put(SYNAPSE_CONFIGURATION, getSynapseConfiguration());
API api = APIFactory.createAPI(RestApiAdminUtils.retrieveAPIOMElement(apiData), properties);
SynapseConfiguration synapseConfiguration = getSynapseConfiguration();
oldAPI = synapseConfiguration.getAPI(apiName);
if (oldAPI != null) {
oldAPI.destroy();
api.setFileName(oldAPI.getFileName());
}
synapseConfiguration.updateAPI(apiName, api);
api.init(getSynapseEnvironment());
if (oldAPI.getArtifactContainerName() != null) {
api.setIsEdited(true);
api.setArtifactContainerName(oldAPI.getArtifactContainerName());
apiData.setIsEdited(true);
} else {
if (!Boolean.parseBoolean(System.getProperty("NonRegistryMode")) && saveRuntimeArtifacts) {
MediationPersistenceManager pm = getMediationPersistenceManager();
String fileName = api.getFileName();
pm.deleteItem(apiName, fileName, ServiceBusConstants.ITEM_TYPE_REST_API);
pm.saveItem(apiName, ServiceBusConstants.ITEM_TYPE_REST_API);
}
}
return true;
} finally {
lock.unlock();
}
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method generateUpdatedAPIFromSwaggerByFormat.
/**
* Function to generate updated existing API by referring to swagger definition.
*
* @param swaggerJsonString swagger definition.
* @param isJSON input in YAML / JSON format.
* @param existingApi existing synapse API.
* @return generated synapse API.
* @throws APIException error occurred while retrieving host details.
*/
public String generateUpdatedAPIFromSwaggerByFormat(String swaggerJsonString, boolean isJSON, API existingApi) throws APIException {
if (swaggerJsonString == null || swaggerJsonString.isEmpty()) {
handleException(log, "Provided swagger definition is empty, hence unable to generate API", null);
}
if (existingApi == null) {
handleException(log, "Provided existing API name is empty, hence unable to generate API", null);
}
if (!isJSON) {
try {
swaggerJsonString = GenericApiObjectDefinition.convertYamlToJson(swaggerJsonString);
} catch (JsonProcessingException e) {
handleException(log, "Error occurred while converting the provided YAML to JSON", null);
}
}
JsonParser jsonParser = new JsonParser();
JsonElement swaggerJson = jsonParser.parse(swaggerJsonString);
if (swaggerJson.isJsonObject()) {
APIGenerator apiGenerator = new APIGenerator(swaggerJson.getAsJsonObject());
try {
API api = apiGenerator.generateUpdatedSynapseAPI(existingApi);
return APISerializer.serializeAPI(api).toString();
} catch (APIGenException e) {
handleException(log, "Error occurred while generating API", e);
}
} else {
handleException(log, "Error in swagger definition format: should be a json object", null);
}
// Definitely will not reach here
return "";
}
Aggregations