use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class APIServiceComponent method createdConfigurationContext.
public void createdConfigurationContext(ConfigurationContext configContext) {
AxisConfiguration axisConfig = configContext.getAxisConfiguration();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (axisConfig != null) {
SynapseEnvironmentService synEnvService = ConfigHolder.getInstance().getSynapseEnvironmentService(tenantId);
if (synEnvService != null) {
try {
registerDeployer(axisConfig, synEnvService.getSynapseEnvironment());
} catch (APIException e) {
log.error("Error while initializing API admin", e);
}
}
}
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdminService method deleteApi.
/**
* Deletes an API that carries the name that is passed in.
*
* @param apiName Name of the API to be deleted
* @return Status of the execution of deleting the given API
* @throws APIException Is thrown if an anomaly is encountered while deleting the given API
*/
public boolean deleteApi(String apiName) throws APIException {
final Lock lock = getLock();
try {
lock.lock();
assertNameNotEmpty(log, apiName);
apiName = apiName.trim();
SynapseConfiguration synapseConfiguration = RestApiAdminUtils.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"))) {
MediationPersistenceManager pm = RestApiAdminUtils.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.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method generateUpdatedAPIFromSwagger.
/**
* Function to generate updated existing API by referring to swagger definition (from JSON representation)
*
* @param swaggerJsonString swagger definition
* @param existingApiName name of the existing API
* @return generated synapse API
* @throws APIException
*/
public String generateUpdatedAPIFromSwagger(String swaggerJsonString, String existingApiName) throws APIException {
if (swaggerJsonString == null || swaggerJsonString.isEmpty()) {
handleException(log, "Provided swagger definition is empty, hence unable to generate API", null);
}
if (existingApiName == null || existingApiName.isEmpty()) {
handleException(log, "Provided existing API name is empty, hence unable to generate API", null);
}
JsonParser jsonParser = new JsonParser();
JsonElement swaggerJson = jsonParser.parse(swaggerJsonString);
if (swaggerJson.isJsonObject()) {
APIGenerator apiGenerator = new APIGenerator(swaggerJson.getAsJsonObject());
try {
API api = apiGenerator.generateUpdatedSynapseAPI(getSynapseAPIByName(existingApiName));
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 "";
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method getApiForTenant.
/**
* Set the tenant domain when a publisher tries to retrieve API his API in MT mode. When
* publisher gets
* the API, we login the gateway as supretenant. But we need to get the
* API,which is in the particular tenant domain.
*
* @param apiName
* @param tenantDomain
* @return
* @throws APIException
*/
public APIData getApiForTenant(String apiName, String tenantDomain) throws APIException {
try {
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
APIData data = getApiByName(apiName);
return data;
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}
use of org.wso2.carbon.identity.mgt.endpoint.util.client.ApiException in project carbon-mediation by wso2.
the class RestApiAdmin method addSwaggerDocument.
/**
* Replace the swagger document in the registry with the given swagger json string
*
* @param apiName
* @param swaggerJsonString
* @param tenantId
* @throws APIException
*/
public void addSwaggerDocument(String apiName, String swaggerJsonString, int tenantId) throws APIException {
String resourcePath = SwaggerConstants.DEFAULT_SWAGGER_REGISTRY_PATH + apiName + SwaggerConstants.SWAGGER_JSON_FILE_PATH;
RegistryService registryService = RegistryServiceHolder.getInstance().getRegistryService();
try {
Registry registry = registryService.getConfigSystemRegistry(tenantId);
org.wso2.carbon.registry.core.Resource resource;
if (swaggerJsonString != null) {
resource = registry.newResource();
resource.setContent(swaggerJsonString);
resource.setMediaType(APPLICATION_JSON_TYPE);
registry.put(resourcePath, resource);
}
} catch (RegistryException e) {
handleException(log, "Could not add swagger document", e);
}
}
Aggregations