use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method loadAllSubscriptionPolicies.
@Override
public List<SubscriptionPolicy> loadAllSubscriptionPolicies(String tenantDomain) throws DataLoadingException {
String subscriptionPoliciesEP = APIConstants.SubscriptionValidationResources.SUBSCRIPTION_POLICIES;
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
String responseString = null;
try {
responseString = invokeService(subscriptionPoliciesEP, tenantDomain);
} catch (IOException e) {
String msg = "Error while executing the http client " + subscriptionPoliciesEP;
log.error(msg, e);
throw new DataLoadingException(msg, e);
}
if (responseString != null && !responseString.isEmpty()) {
subscriptionPolicies = (new Gson().fromJson(responseString, SubscriptionPolicyList.class)).getList();
}
return subscriptionPolicies;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method getApplicationById.
@Override
public Application getApplicationById(int appId) throws DataLoadingException {
String endPoint = APIConstants.SubscriptionValidationResources.APPLICATIONS + "?appId=" + appId;
Application application = null;
String responseString;
try {
responseString = invokeService(endPoint, null);
} 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()) {
ApplicationList list = new Gson().fromJson(responseString, ApplicationList.class);
if (list.getList() != null && !list.getList().isEmpty()) {
application = list.getList().get(0);
}
}
return application;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataLoaderImpl method getSubscriptionPolicy.
@Override
public SubscriptionPolicy getSubscriptionPolicy(String policyName, String tenantDomain) throws DataLoadingException {
String endPoint = APIConstants.SubscriptionValidationResources.SUBSCRIPTION_POLICIES + "?policyName=" + policyName;
SubscriptionPolicy subscriptionPolicy = new SubscriptionPolicy();
if (log.isDebugEnabled()) {
log.debug("getSubscriptionPolicy for " + policyName + " for tenant " + tenantDomain);
}
String responseString;
try {
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()) {
SubscriptionPolicyList list = new Gson().fromJson(responseString, SubscriptionPolicyList.class);
if (list.getList() != null && !list.getList().isEmpty()) {
subscriptionPolicy = list.getList().get(0);
}
}
return subscriptionPolicy;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method getSubscriptionById.
@Override
public Subscription getSubscriptionById(int appId, int apiId) {
String subscriptionCacheKey = SubscriptionDataStoreUtil.getSubscriptionCacheKey(appId, apiId);
String synchronizeKey = "SubscriptionDataStoreImpl-Subscription-" + subscriptionCacheKey;
Subscription subscription = subscriptionMap.get(subscriptionCacheKey);
if (subscription == null) {
synchronized (synchronizeKey.intern()) {
subscription = subscriptionMap.get(subscriptionCacheKey);
if (subscription != null) {
return subscription;
}
try {
subscription = new SubscriptionDataLoaderImpl().getSubscriptionById(Integer.toString(apiId), Integer.toString(appId));
} catch (DataLoadingException e) {
log.error("Error while Retrieving Subscription Data From Internal API", e);
}
if (subscription != null && !StringUtils.isEmpty(subscription.getSubscriptionId())) {
// load to the memory
log.debug("Loading Subscription to the in-memory datastore.");
subscriptionMap.put(subscription.getCacheKey(), subscription);
}
}
}
if (log.isDebugEnabled()) {
log.debug("Retrieving API Subscription with Application " + appId + " and APIId : " + apiId);
if (subscription != null) {
log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + subscription.toString());
} else {
log.debug("Retrieved API Subscription with Application " + appId + " and APIId : " + apiId + " is " + "empty.");
}
}
return subscription;
}
use of org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException in project carbon-apimgt by wso2.
the class SubscriptionDataStoreImpl method getKeyMappingByKeyAndKeyManager.
@Override
public ApplicationKeyMapping getKeyMappingByKeyAndKeyManager(String key, String keyManager) {
ApplicationKeyMappingCacheKey applicationKeyMappingCacheKey = new ApplicationKeyMappingCacheKey(key, keyManager);
String synchronizeKey = "SubscriptionDataStoreImpl-KeyMapping-" + applicationKeyMappingCacheKey;
ApplicationKeyMapping applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
if (applicationKeyMapping == null) {
synchronized (synchronizeKey.intern()) {
applicationKeyMapping = applicationKeyMappingMap.get(applicationKeyMappingCacheKey);
if (applicationKeyMapping != null) {
return applicationKeyMapping;
}
try {
applicationKeyMapping = new SubscriptionDataLoaderImpl().getKeyMapping(key, keyManager, tenantDomain);
} catch (DataLoadingException e) {
log.error("Error while Loading KeyMapping Information from Internal API.", e);
}
if (applicationKeyMapping != null && !StringUtils.isEmpty(applicationKeyMapping.getConsumerKey())) {
// load to the memory
log.debug("Loading Keymapping to the in-memory datastore.");
addOrUpdateApplicationKeyMapping(applicationKeyMapping);
}
}
}
if (log.isDebugEnabled()) {
log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager);
if (applicationKeyMapping != null) {
log.debug("Retrieved Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is " + applicationKeyMapping.toString());
} else {
log.debug("Retrieving Application information with Consumer Key : " + key + " and keymanager : " + keyManager + " is empty");
}
}
return applicationKeyMapping;
}
Aggregations