From 6dd62f36aa2cd5ca3d356cda03d21dc9da44ea7b Mon Sep 17 00:00:00 2001 From: Kannan Kirishikesan Date: Mon, 19 Jun 2023 12:30:47 +0530 Subject: [PATCH 1/2] Gets user credentials for redis when other configs are missing --- .../carbon/apimgt/impl/APIManagerConfiguration.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java index e3f4cdd1e8a6..2fa9135c12c5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java +++ b/components/apimgt/org.wso2.carbon.apimgt.impl/src/main/java/org/wso2/carbon/apimgt/impl/APIManagerConfiguration.java @@ -386,12 +386,19 @@ private void readChildElements(OMElement serverConfig, redisConfig.setRedisEnabled(true); redisConfig.setHost(redisHost.getText()); redisConfig.setPort(Integer.parseInt(redisPort.getText())); - if (redisUser != null && redisPassword != null && redisDatabaseId != null - && redisConnectionTimeout != null && redisIsSslEnabled != null) { + if (redisUser != null) { redisConfig.setUser(redisUser.getText()); + } + if (redisPassword != null) { redisConfig.setPassword(MiscellaneousUtil.resolve(redisPassword, secretResolver).toCharArray()); + } + if (redisDatabaseId != null) { redisConfig.setDatabaseId(Integer.parseInt(redisDatabaseId.getText())); + } + if (redisConnectionTimeout != null) { redisConfig.setConnectionTimeout(Integer.parseInt(redisConnectionTimeout.getText())); + } + if (redisIsSslEnabled != null) { redisConfig.setSslEnabled(Boolean.parseBoolean(redisIsSslEnabled.getText())); } if (propertiesElement !=null){ From 0af54cc2793d57b6e4cd8d80355a562c7d12ee1b Mon Sep 17 00:00:00 2001 From: Kannan Kirishikesan Date: Mon, 19 Jun 2023 12:31:46 +0530 Subject: [PATCH 2/2] Fix errors when using throttling with Redis --- .../apimgt/gateway/RedisBaseDistributedCountManager.java | 4 ++-- .../apimgt/gateway/internal/APIHandlerServiceComponent.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/RedisBaseDistributedCountManager.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/RedisBaseDistributedCountManager.java index a727e9065216..010e909860d5 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/RedisBaseDistributedCountManager.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/RedisBaseDistributedCountManager.java @@ -145,7 +145,7 @@ public long asyncGetAndAddCounter(String key, long value) { Response incrementedValue = transaction.incrBy(key, value); transaction.exec(); - if (currentValue != null) { + if (currentValue != null && currentValue.get() != null) { current = Long.parseLong(currentValue.get()); } if (log.isDebugEnabled()) { @@ -177,7 +177,7 @@ public long asyncGetAndAlterCounter(String key, long value) { Response incrementedValue = transaction.incrBy(key, value); transaction.exec(); - if (currentValue != null) { + if (currentValue != null && currentValue.get() != null) { current = Long.parseLong(currentValue.get()); } if (log.isDebugEnabled()) { diff --git a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/internal/APIHandlerServiceComponent.java b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/internal/APIHandlerServiceComponent.java index 4700304cab14..0190b06fe70e 100644 --- a/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/internal/APIHandlerServiceComponent.java +++ b/components/apimgt/org.wso2.carbon.apimgt.gateway/src/main/java/org/wso2/carbon/apimgt/gateway/internal/APIHandlerServiceComponent.java @@ -126,11 +126,11 @@ protected void activate(ComponentContext context) { RedisConfig redisConfig = ServiceReferenceHolder.getInstance().getAPIManagerConfiguration().getRedisConfig(); if (redisConfig.isRedisEnabled()) { + ServiceReferenceHolder.getInstance().setRedisPool(getJedisPool(redisConfig)); RedisBaseDistributedCountManager redisBaseDistributedCountManager = new RedisBaseDistributedCountManager(ServiceReferenceHolder.getInstance().getRedisPool()); context.getBundleContext().registerService(DistributedCounterManager.class, redisBaseDistributedCountManager, null); - ServiceReferenceHolder.getInstance().setRedisPool(getJedisPool(redisConfig)); } // Create caches for the super tenant