use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SynapseAnalyticsDataProvider method getApi.
@Override
public API getApi() throws DataNotFoundException {
String apiContext = (String) messageContext.getProperty(RESTConstants.REST_API_CONTEXT);
String apiVersion = (String) messageContext.getProperty(RESTConstants.SYNAPSE_REST_API_VERSION);
String tenantDomain = MultitenantUtils.getTenantDomainFromRequestURL(apiContext);
if (tenantDomain == null) {
tenantDomain = MultitenantConstants.SUPER_TENANT_DOMAIN_NAME;
}
SubscriptionDataStore store = SubscriptionDataHolder.getInstance().getTenantSubscriptionStore(tenantDomain);
org.wso2.carbon.apimgt.keymgt.model.entity.API apiObj = store.getApiByContextAndVersion(apiContext, apiVersion);
API api = new API();
if (apiObj == null) {
try {
apiObj = new SubscriptionDataLoaderImpl().getApi(apiContext, apiVersion);
} catch (DataLoadingException e) {
log.error("Error occurred when getting api.", e);
throw new DataNotFoundException("Error occurred when getting API information", e);
}
}
if (apiObj != null) {
api.setApiId(apiObj.getUuid());
api.setApiType(apiObj.getApiType());
api.setApiName(apiObj.getApiName());
api.setApiVersion(apiObj.getApiVersion());
api.setApiCreator(apiObj.getApiProvider());
api.setApiCreatorTenantDomain(MultitenantUtils.getTenantDomain(api.getApiCreator()));
}
return api;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method loadAllScopes.
@Override
public List<Scope> loadAllScopes(String tenantDomain) throws DataLoadingException {
String scopesEp = APIConstants.SubscriptionValidationResources.SCOPES;
List<Scope> scopes = new ArrayList<>();
String responseString;
try {
responseString = invokeService(scopesEp, tenantDomain);
} catch (IOException e) {
String msg = "Error while executing the HTTP client " + scopesEp;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
scopes = new Gson().fromJson(responseString, ScopesList.class).getList();
}
return scopes;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method loadAllAppPolicies.
@Override
public List<ApplicationPolicy> loadAllAppPolicies(String tenantDomain) throws DataLoadingException {
String applicationsEP = APIConstants.SubscriptionValidationResources.APPLICATION_POLICIES;
List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
String responseString = null;
try {
responseString = invokeService(applicationsEP, tenantDomain);
} catch (IOException e) {
String msg = "Error while executing the http client " + applicationsEP;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
applicationPolicies = (new Gson().fromJson(responseString, ApplicationPolicyList.class)).getList();
}
return applicationPolicies;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method getApi.
@Override
public API getApi(String context, String version) throws DataLoadingException {
Set<String> gatewayLabels = gatewayArtifactSynchronizerProperties.getGatewayLabels();
if (gatewayLabels != null && gatewayLabels.size() > 0) {
for (String gatewayLabel : gatewayLabels) {
String apisEP = APIConstants.SubscriptionValidationResources.APIS + "?context=" + context + "&version=" + version + "&gatewayLabel=" + getEncodedLabel(gatewayLabel);
API api = null;
String responseString;
try {
responseString = invokeService(apisEP, null);
} catch (IOException e) {
String msg = "Error while executing the http client " + apisEP;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
APIList list = new Gson().fromJson(responseString, APIList.class);
if (list.getList() != null && !list.getList().isEmpty()) {
api = list.getList().get(0);
}
}
return api;
}
}
return null;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method getKeyMapping.
@Override
public ApplicationKeyMapping getKeyMapping(String consumerKey, String keymanager, String tenantDomain) throws DataLoadingException {
ApplicationKeyMapping application = null;
String responseString;
String endPoint = null;
try {
keymanager = URLEncoder.encode(keymanager, APIConstants.DigestAuthConstants.CHARSET);
keymanager = keymanager.replace("\\+", "%20");
endPoint = APIConstants.SubscriptionValidationResources.APPLICATION_KEY_MAPPINGS + "?consumerKey=" + consumerKey + "&keymanager=" + keymanager;
responseString = invokeService(endPoint, tenantDomain);
} catch (IOException e) {
String msg = "Error while executing the http client " + endPoint;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
ApplicationKeyMappingList list = new Gson().fromJson(responseString, ApplicationKeyMappingList.class);
if (list.getList() != null && !list.getList().isEmpty()) {
application = list.getList().get(0);
}
}
return application;
}
Aggregations