Search in sources :

Example 66 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getSkipRolesByRegex.

/**
 * return skipRolesByRegex config
 */
public static String getSkipRolesByRegex() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String skipRolesByRegex = config.getFirstProperty(APIConstants.SKIP_ROLES_BY_REGEX);
    return skipRolesByRegex;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 67 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method isAllowDisplayMultipleVersions.

public static boolean isAllowDisplayMultipleVersions() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String displayMultiVersions = config.getFirstProperty(APIConstants.API_STORE_DISPLAY_MULTIPLE_VERSIONS);
    if (displayMultiVersions == null) {
        log.warn("The configurations related to show multiple versions of API in APIStore " + "are missing in api-manager.xml.");
        return false;
    }
    return Boolean.parseBoolean(displayMultiVersions);
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 68 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getInternalApiKeyAlias.

public static String getInternalApiKeyAlias() {
    APIManagerConfiguration config = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String alias = config.getFirstProperty(APIConstants.API_PUBLISHER_INTERNAL_API_KEY_ALIAS);
    if (alias == null) {
        log.warn("The configurations related to Api Key alias in API Publisher " + "are missing in api-manager.xml. Hence returning the default value.");
        return APIConstants.GATEWAY_PUBLIC_CERTIFICATE_ALIAS;
    }
    return alias;
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Example 69 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method getHttpClient.

/**
 * Return a http client instance
 *
 * @param port      - server port
 * @param protocol- service endpoint protocol http/https
 * @return
 */
public static HttpClient getHttpClient(int port, String protocol) {
    APIManagerConfiguration configuration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String maxTotal = configuration.getFirstProperty(APIConstants.HTTP_CLIENT_MAX_TOTAL);
    String defaultMaxPerRoute = configuration.getFirstProperty(APIConstants.HTTP_CLIENT_DEFAULT_MAX_PER_ROUTE);
    String proxyEnabled = configuration.getFirstProperty(APIConstants.PROXY_ENABLE);
    String proxyHost = configuration.getFirstProperty(APIConstants.PROXY_HOST);
    String proxyPort = configuration.getFirstProperty(APIConstants.PROXY_PORT);
    String proxyUsername = configuration.getFirstProperty(APIConstants.PROXY_USERNAME);
    String proxyPassword = configuration.getFirstProperty(APIConstants.PROXY_PASSWORD);
    String nonProxyHosts = configuration.getFirstProperty(APIConstants.NON_PROXY_HOSTS);
    String proxyProtocol = configuration.getFirstProperty(APIConstants.PROXY_PROTOCOL);
    if (proxyProtocol != null) {
        protocol = proxyProtocol;
    }
    PoolingHttpClientConnectionManager pool = null;
    try {
        pool = getPoolingHttpClientConnectionManager(protocol);
    } catch (APIManagementException e) {
        log.error("Error while getting http client connection manager", e);
    }
    pool.setMaxTotal(Integer.parseInt(maxTotal));
    pool.setDefaultMaxPerRoute(Integer.parseInt(defaultMaxPerRoute));
    RequestConfig params = RequestConfig.custom().build();
    HttpClientBuilder clientBuilder = HttpClients.custom().setConnectionManager(pool).setDefaultRequestConfig(params);
    if (Boolean.parseBoolean(proxyEnabled)) {
        HttpHost host = new HttpHost(proxyHost, Integer.parseInt(proxyPort), protocol);
        DefaultProxyRoutePlanner routePlanner;
        if (!StringUtils.isBlank(nonProxyHosts)) {
            routePlanner = new ExtendedProxyRoutePlanner(host, configuration);
        } else {
            routePlanner = new DefaultProxyRoutePlanner(host);
        }
        clientBuilder = clientBuilder.setRoutePlanner(routePlanner);
        if (!StringUtils.isBlank(proxyUsername) && !StringUtils.isBlank(proxyPassword)) {
            CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
            credentialsProvider.setCredentials(new AuthScope(proxyHost, Integer.parseInt(proxyPort)), new UsernamePasswordCredentials(proxyUsername, proxyPassword));
            clientBuilder = clientBuilder.setDefaultCredentialsProvider(credentialsProvider);
        }
    }
    return clientBuilder.build();
}
Also used : RequestConfig(org.apache.http.client.config.RequestConfig) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration) ExtendedProxyRoutePlanner(org.wso2.carbon.apimgt.impl.proxy.ExtendedProxyRoutePlanner) DefaultProxyRoutePlanner(org.apache.http.impl.conn.DefaultProxyRoutePlanner) HttpClientBuilder(org.apache.http.impl.client.HttpClientBuilder) CredentialsProvider(org.apache.http.client.CredentialsProvider) BasicCredentialsProvider(org.apache.http.impl.client.BasicCredentialsProvider) PoolingHttpClientConnectionManager(org.apache.http.impl.conn.PoolingHttpClientConnectionManager) UsernamePasswordCredentials(org.apache.http.auth.UsernamePasswordCredentials) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) HttpHost(org.apache.http.HttpHost) AuthScope(org.apache.http.auth.AuthScope)

Example 70 with APIManagerConfiguration

use of org.wso2.carbon.apimgt.impl.APIManagerConfiguration in project carbon-apimgt by wso2.

the class APIUtil method isSupportedFileType.

/**
 * Check whether the file type is supported.
 * @param filename name
 * @return true if supported
 */
public static boolean isSupportedFileType(String filename) {
    if (log.isDebugEnabled()) {
        log.debug("File name " + filename);
    }
    if (StringUtils.isEmpty(filename)) {
        return false;
    }
    String fileType = FilenameUtils.getExtension(filename);
    List<String> list = null;
    APIManagerConfiguration apiManagerConfiguration = ServiceReferenceHolder.getInstance().getAPIManagerConfigurationService().getAPIManagerConfiguration();
    String supportedTypes = apiManagerConfiguration.getFirstProperty(APIConstants.API_PUBLISHER_SUPPORTED_DOC_TYPES);
    if (!StringUtils.isEmpty(supportedTypes)) {
        String[] definedTypesArr = supportedTypes.trim().split("\\s*,\\s*");
        list = Arrays.asList(definedTypesArr);
    } else {
        String[] defaultType = { "pdf", "txt", "doc", "docx", "xls", "xlsx", "odt", "ods", "json", "yaml", "md" };
        list = Arrays.asList(defaultType);
    }
    return list.contains(fileType.toLowerCase());
}
Also used : APIManagerConfiguration(org.wso2.carbon.apimgt.impl.APIManagerConfiguration)

Aggregations

APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)122 Test (org.junit.Test)76 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)67 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)51 HashMap (java.util.HashMap)39 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)36 RealmService (org.wso2.carbon.user.core.service.RealmService)33 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)31 ArrayList (java.util.ArrayList)26 API (org.wso2.carbon.apimgt.api.model.API)25 Before (org.junit.Before)24 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)24 UserRegistry (org.wso2.carbon.registry.core.session.UserRegistry)24 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)23 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)23 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)22 MessageContext (org.apache.synapse.MessageContext)20 Axis2MessageContext (org.apache.synapse.core.axis2.Axis2MessageContext)20 Cache (javax.cache.Cache)19 Map (java.util.Map)18