Search in sources :

Example 26 with SecretResolver

use of org.wso2.securevault.SecretResolver in project wso2-synapse by wso2.

the class ThrottleUtil method loadThrottlePropertiesFromConfigurations.

/**
 * This method used to set throttle properties loaded from throttle.properties file in configuration folder
 *
 * @return properties of throttle properties
 */
public static ThrottleProperties loadThrottlePropertiesFromConfigurations() {
    ThrottleProperties throttleProperties = new ThrottleProperties();
    Properties properties = new Properties();
    String throttlePropertiesFileLocation;
    if (System.getProperty(CONF_LOCATION) != null) {
        throttlePropertiesFileLocation = System.getProperty(CONF_LOCATION) + File.separator + "throttle.properties";
        try {
            properties.load(new FileInputStream(throttlePropertiesFileLocation));
            SecretResolver secretResolver = SecretResolverFactory.create(properties);
            Set<String> keys = properties.stringPropertyNames();
            for (String key : keys) {
                if (ThrottleConstants.THROTTLE_CONTEXT_CLEANUP_TASK_FREQUENCY.equals(key)) {
                    String throttleFrequency = properties.getProperty(key);
                    if (!StringUtils.isEmpty(throttleFrequency)) {
                        throttleProperties.setThrottleFrequency(throttleFrequency);
                    }
                }
                if (ThrottleConstants.THROTTLE_CONTEXT_DISTRIBUTED_CLEANUP_TASK_FREQUENCY.equals(key)) {
                    String throttleContextDistributedCleanupTaskFrequency = properties.getProperty(key);
                    if (throttleContextDistributedCleanupTaskFrequency != null && !throttleContextDistributedCleanupTaskFrequency.equals("")) {
                        throttleProperties.setThrottleContextDistributedCleanupTaskFrequency(throttleContextDistributedCleanupTaskFrequency);
                    }
                }
                if (ThrottleConstants.THROTTLE_CONTEXT_DISTRIBUTED_EXPIRED_INSTANCE_TIME.equals(key)) {
                    String throttleContextDistributedExpiredInstanceTime = properties.getProperty(key);
                    if (throttleContextDistributedExpiredInstanceTime != null && !throttleContextDistributedExpiredInstanceTime.equals("")) {
                        throttleProperties.setThrottleContextDistributedExpiredInstanceTime(throttleContextDistributedExpiredInstanceTime);
                    }
                }
                if (ThrottleConstants.THROTTLE_DISTRIBUTED_CLEANUP_POOL_SIZE.equals(key)) {
                    String throttleDistributedCleanupPoolSize = properties.getProperty(key);
                    if (throttleDistributedCleanupPoolSize != null && throttleDistributedCleanupPoolSize != "") {
                        throttleProperties.setThrottleDistributedCleanupPoolSize(throttleDistributedCleanupPoolSize);
                    }
                }
                if (ThrottleConstants.THROTTLE_DISTRIBUTED_CLEANUP_AMOUNT.equals(key)) {
                    String throttleDistributedCleanupAmount = properties.getProperty(key);
                    if (throttleDistributedCleanupAmount != null && throttleDistributedCleanupAmount != "") {
                        throttleProperties.setThrottleDistributedCleanupAmount(throttleDistributedCleanupAmount);
                    }
                }
                if (ThrottleConstants.THROTTLE_DISTRIBUTED_CLEANUP_TASK_ENABLE.equals(key)) {
                    String throttleDistributedCleanupTaskEnable = properties.getProperty(key);
                    if (throttleDistributedCleanupTaskEnable != null && throttleDistributedCleanupTaskEnable != "") {
                        throttleProperties.setThrottleDistributedCleanupTaskEnable(throttleDistributedCleanupTaskEnable);
                    }
                }
                if (ThrottleConstants.MAX_NON_ASSOCIATED_COUNTER_CLEANUP_AMOUNT.equals(key)) {
                    String maxNonAssociatedCounterCleanupAmount = properties.getProperty(key);
                    if (maxNonAssociatedCounterCleanupAmount != null && maxNonAssociatedCounterCleanupAmount != "") {
                        throttleProperties.setMaxNonAssociatedCounterCleanupAmount(maxNonAssociatedCounterCleanupAmount);
                    }
                }
                if (ThrottleConstants.THROTTLING_POOL_SIZE.equals(key)) {
                    String throttlingPoolSize = properties.getProperty(key);
                    if (throttlingPoolSize != null && throttlingPoolSize != "") {
                        throttleProperties.setThrottlingPoolSize(throttlingPoolSize);
                    }
                }
                if (ThrottleConstants.THROTTLING_REPLICATION_FREQUENCY.equals(key)) {
                    String throttlingReplicationFrequency = properties.getProperty(key);
                    if (throttlingReplicationFrequency != null && throttlingReplicationFrequency != "") {
                        throttleProperties.setThrottlingReplicationFrequency(throttlingReplicationFrequency);
                    }
                }
                if (ThrottleConstants.THROTTLING_KEYS_TO_REPLICATE.equals(key)) {
                    String throttlingKeysToReplicate = properties.getProperty(key);
                    if (throttlingKeysToReplicate != null && throttlingKeysToReplicate != "") {
                        throttleProperties.setThrottlingKeysToReplicates(throttlingKeysToReplicate);
                    }
                }
                if (ThrottleConstants.WINDOW_REPLICATOR_POOL_SIZE.equals(key)) {
                    String windowReplicatorPoolSize = properties.getProperty(key);
                    if (windowReplicatorPoolSize != null && windowReplicatorPoolSize != "") {
                        throttleProperties.setWindowReplicatorPoolSize(windowReplicatorPoolSize);
                    }
                }
                if (ThrottleConstants.WINDOW_REPLICATOR_FREQUENCY.equals(key)) {
                    String windowReplicatorFrequency = properties.getProperty(key);
                    if (windowReplicatorFrequency != null && windowReplicatorFrequency != "") {
                        throttleProperties.setWindowReplicatorFrequency(windowReplicatorFrequency);
                    }
                }
                if (ThrottleConstants.DISTRIBUTED_COUNTER_TYPE.equals(key)) {
                    String distributedCounterType = properties.getProperty(key);
                    if (distributedCounterType != null && !distributedCounterType.equals("")) {
                        throttleProperties.setDistributedCounterType(distributedCounterType);
                    }
                }
                if (key.contains(ThrottleConstants.DISTRIBUTED_COUNTER_CONFIGURATIONS)) {
                    String distributedConfiguration = properties.getProperty(key);
                    String configuration = key.split(ThrottleConstants.DISTRIBUTED_COUNTER_CONFIGURATIONS)[1];
                    if (StringUtils.isNotEmpty(distributedConfiguration)) {
                        throttleProperties.getDistributedCounterConfigurations().put(configuration, getResolvedValue(secretResolver, distributedConfiguration));
                    }
                }
            }
        } catch (IOException e) {
            log.debug("Setting the Default Throttle Properties");
        }
    } else {
        log.debug("Setting the Default Throttle Properties");
    }
    return throttleProperties;
}
Also used : SecretResolver(org.wso2.securevault.SecretResolver) IOException(java.io.IOException) Properties(java.util.Properties) FileInputStream(java.io.FileInputStream)

Aggregations

SecretResolver (org.wso2.securevault.SecretResolver)17 OMElement (org.apache.axiom.om.OMElement)15 QName (javax.xml.namespace.QName)13 Iterator (java.util.Iterator)7 StAXOMBuilder (org.apache.axiom.om.impl.builder.StAXOMBuilder)7 Parameter (org.apache.axis2.description.Parameter)7 Properties (java.util.Properties)6 AxisFault (org.apache.axis2.AxisFault)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 FileInputStream (java.io.FileInputStream)4 InputStream (java.io.InputStream)4 LinkedHashMap (java.util.LinkedHashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 XmlException (org.apache.xmlbeans.XmlException)3 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)3 GatewayArtifactSynchronizerProperties (org.wso2.carbon.apimgt.impl.dto.GatewayArtifactSynchronizerProperties)3 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)3 WorkflowProperties (org.wso2.carbon.apimgt.impl.dto.WorkflowProperties)3 FileNotFoundException (java.io.FileNotFoundException)2