Search in sources :

Example 1 with DataLoadingException

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;
}
Also used : SubscriptionDataLoaderImpl(org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl) DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) DataNotFoundException(org.wso2.carbon.apimgt.common.analytics.exceptions.DataNotFoundException) API(org.wso2.carbon.apimgt.common.analytics.publishers.dto.API) SubscriptionDataStore(org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)

Example 2 with DataLoadingException

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;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) Scope(org.wso2.carbon.apimgt.keymgt.model.entity.Scope) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 3 with DataLoadingException

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;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) ApplicationPolicyList(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicyList) ApplicationPolicy(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy) ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) IOException(java.io.IOException)

Example 4 with DataLoadingException

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;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) APIList(org.wso2.carbon.apimgt.keymgt.model.entity.APIList) Gson(com.google.gson.Gson) API(org.wso2.carbon.apimgt.keymgt.model.entity.API) IOException(java.io.IOException)

Example 5 with DataLoadingException

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;
}
Also used : DataLoadingException(org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException) Gson(com.google.gson.Gson) IOException(java.io.IOException) ApplicationKeyMappingList(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingList) ApplicationKeyMapping(org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)

Aggregations

DataLoadingException (org.wso2.carbon.apimgt.keymgt.model.exception.DataLoadingException)26 IOException (java.io.IOException)16 Gson (com.google.gson.Gson)15 ArrayList (java.util.ArrayList)10 ApiPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApiPolicy)5 API (org.wso2.carbon.apimgt.keymgt.model.entity.API)4 ApplicationPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicy)4 SubscriptionPolicy (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionPolicy)4 SubscriptionDataLoaderImpl (org.wso2.carbon.apimgt.keymgt.model.impl.SubscriptionDataLoaderImpl)4 Application (org.wso2.carbon.apimgt.keymgt.model.entity.Application)3 ApplicationKeyMapping (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMapping)3 Subscription (org.wso2.carbon.apimgt.keymgt.model.entity.Subscription)3 API (org.wso2.carbon.apimgt.common.analytics.publishers.dto.API)2 SubscriptionDataStore (org.wso2.carbon.apimgt.keymgt.model.SubscriptionDataStore)2 APIList (org.wso2.carbon.apimgt.keymgt.model.entity.APIList)2 APIPolicyList (org.wso2.carbon.apimgt.keymgt.model.entity.APIPolicyList)2 ApplicationKeyMappingList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationKeyMappingList)2 ApplicationList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationList)2 ApplicationPolicyList (org.wso2.carbon.apimgt.keymgt.model.entity.ApplicationPolicyList)2 SubscriptionList (org.wso2.carbon.apimgt.keymgt.model.entity.SubscriptionList)2