This is an automated email from the ASF dual-hosted git repository.
xiaoyu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 8726106 [type: refactor] optimize dubbo plugin. (#2333)
8726106 is described below
commit 8726106d7b5361b2cccda4d319cceea5e3b6ed21
Author: Qicz <[email protected]>
AuthorDate: Thu Nov 11 15:28:19 2021 +0800
[type: refactor] optimize dubbo plugin. (#2333)
* [type: refactor] optimize dubbo plugin.
* add code comment.
* refactor
---
.../http/combination/CryptorRequestPluginTest.java | 16 +-
.../decorator/CryptorResponseDecorator.java | 8 +-
.../handler/CryptorRequestPluginDataHandler.java | 7 +-
.../handler/CryptorResponsePluginDataHandler.java | 7 +-
.../CryptorRuleHandler.java} | 6 +-
.../cryptor/request/CryptorRequestPlugin.java | 6 +-
.../cryptor/response/CryptorResponsePlugin.java | 4 +-
.../cryptor/strategy/CryptorStrategyFactory.java | 4 +-
.../shenyu/plugin/cryptor/utils/JsonUtil.java | 7 +-
.../plugin/alibaba/dubbo/AlibabaDubboPlugin.java | 55 ++----
...nfigCache.java => AlibabaDubboConfigCache.java} | 127 +++-----------
.../AlibabaAbstractDubboPluginDataHandler.java | 34 ++++
.../handler/AlibabaDubboPluginDataHandler.java | 121 --------------
.../dubbo/proxy/AlibabaDubboGrayLoadBalance.java | 7 +-
.../dubbo/proxy/AlibabaDubboProxyService.java | 8 +-
.../subscriber/AlibabaDubboMetaDataSubscriber.java | 10 +-
...eTest.java => AlibabaDubboConfigCacheTest.java} | 53 +++---
.../dubbo/handler/AlibabaDubboPluginDataTest.java | 4 +-
.../dubbo/proxy/AlibabaDubboProxyServiceTest.java | 12 +-
.../ApacheDubboMetaDataSubscriberTest.java | 8 +-
.../plugin/apache/dubbo/ApacheDubboPlugin.java | 55 ++----
...onfigCache.java => ApacheDubboConfigCache.java} | 127 +++-----------
.../ApacheAbstractDubboPluginDataHandler.java | 34 ++++
.../dubbo/proxy/ApacheDubboGrayLoadBalance.java | 6 +-
.../dubbo/proxy/ApacheDubboProxyService.java | 8 +-
.../subscriber/ApacheDubboMetaDataSubscriber.java | 10 +-
...heTest.java => ApacheDubboConfigCacheTest.java} | 46 ++---
... ApacheAbstractDubboPluginDataHandlerTest.java} | 8 +-
.../dubbo/proxy/ApacheDubboProxyServiceTest.java | 10 +-
.../ApacheDubboMetaDataSubscriberTest.java | 8 +-
.../shenyu-plugin-dubbo-common/pom.xml | 5 +
.../plugin/dubbo/common/AbstractDubboPlugin.java | 80 +++++++++
.../dubbo/common/cache/DubboConfigCache.java | 36 ++++
.../plugin/dubbo/common/cache/DubboParam.java | 185 +++++++++++++++++++++
.../handler/AbstractDubboPluginDataHandler.java} | 16 +-
.../dubbo/AlibabaDubboPluginConfiguration.java | 4 +-
.../dubbo/AlibabaDubboPluginConfigurationTest.java | 4 +-
.../dubbo/ApacheDubboPluginConfiguration.java | 4 +-
.../dubbo/ApacheDubboPluginConfigurationTest.java | 4 +-
39 files changed, 601 insertions(+), 553 deletions(-)
diff --git
a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorRequestPluginTest.java
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorRequestPluginTest.java
index 1b0a12a..abca81d 100644
---
a/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorRequestPluginTest.java
+++
b/shenyu-integrated-test/shenyu-integrated-test-http/src/test/java/org/apache/shenyu/integrated/test/http/combination/CryptorRequestPluginTest.java
@@ -26,7 +26,7 @@ import org.apache.shenyu.common.utils.JsonUtils;
import org.apache.shenyu.integratedtest.common.AbstractPluginDataInit;
import org.apache.shenyu.integratedtest.common.dto.UserDTO;
import org.apache.shenyu.integratedtest.common.helper.HttpHelper;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import org.apache.shenyu.plugin.cryptor.strategy.RsaStrategy;
import org.apache.shenyu.web.controller.LocalPluginController.RuleLocalData;
import org.junit.After;
@@ -112,14 +112,14 @@ public class CryptorRequestPluginTest extends
AbstractPluginDataInit {
private RuleLocalData buildRuleLocalData(final String fieldNames, final
String way) {
final RuleLocalData ruleLocalData = new RuleLocalData();
- CryptorRuleHandle cryptorRuleHandle = new CryptorRuleHandle();
- cryptorRuleHandle.setDecryptKey(RSA_PRIVATE_KEY);
- cryptorRuleHandle.setEncryptKey(RSA_PUBLIC_KEY);
- cryptorRuleHandle.setStrategyName("rsa");
- cryptorRuleHandle.setFieldNames(fieldNames);
- cryptorRuleHandle.setWay(way);
+ CryptorRuleHandler cryptorRuleHandler = new CryptorRuleHandler();
+ cryptorRuleHandler.setDecryptKey(RSA_PRIVATE_KEY);
+ cryptorRuleHandler.setEncryptKey(RSA_PUBLIC_KEY);
+ cryptorRuleHandler.setStrategyName("rsa");
+ cryptorRuleHandler.setFieldNames(fieldNames);
+ cryptorRuleHandler.setWay(way);
- ruleLocalData.setRuleHandler(JsonUtils.toJson(cryptorRuleHandle));
+ ruleLocalData.setRuleHandler(JsonUtils.toJson(cryptorRuleHandler));
ConditionData conditionData = new ConditionData();
conditionData.setParamType(ParamTypeEnum.URI.getName());
conditionData.setOperator(OperatorEnum.EQ.getAlias());
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/decorator/CryptorResponseDecorator.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/decorator/CryptorResponseDecorator.java
index 41c018c..46de37e 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/decorator/CryptorResponseDecorator.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/decorator/CryptorResponseDecorator.java
@@ -21,7 +21,7 @@ import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.plugin.base.support.BodyInserterContext;
import org.apache.shenyu.plugin.base.support.CachedBodyOutputMessage;
import org.apache.shenyu.plugin.base.utils.ResponseUtils;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import org.apache.shenyu.plugin.cryptor.strategy.CryptorStrategyFactory;
import org.apache.shenyu.plugin.cryptor.utils.CryptorUtil;
import org.apache.shenyu.plugin.cryptor.utils.JsonUtil;
@@ -46,10 +46,10 @@ public class CryptorResponseDecorator extends
ServerHttpResponseDecorator {
private final ServerWebExchange exchange;
- private final CryptorRuleHandle ruleHandle;
+ private final CryptorRuleHandler ruleHandle;
public CryptorResponseDecorator(final ServerWebExchange exchange,
- final CryptorRuleHandle ruleHandle) {
+ final CryptorRuleHandler ruleHandle) {
super(exchange.getResponse());
this.exchange = exchange;
this.ruleHandle = ruleHandle;
@@ -73,7 +73,7 @@ public class CryptorResponseDecorator extends
ServerHttpResponseDecorator {
}
@SuppressWarnings("rawtypes")
- private Mono strategyMatch(final String originalBody, final
CryptorRuleHandle ruleHandle, final ServerWebExchange exchange) {
+ private Mono strategyMatch(final String originalBody, final
CryptorRuleHandler ruleHandle, final ServerWebExchange exchange) {
String parseBody = JsonUtil.parser(originalBody,
ruleHandle.getFieldNames());
if (Objects.isNull(parseBody)) {
return Mono.just(originalBody);
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRequestPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRequestPluginDataHandler.java
index c5d2c19..641b30d 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRequestPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRequestPluginDataHandler.java
@@ -18,7 +18,6 @@
package org.apache.shenyu.plugin.cryptor.handler;
import org.apache.shenyu.common.dto.RuleData;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
@@ -34,13 +33,13 @@ import java.util.function.Supplier;
*/
public class CryptorRequestPluginDataHandler implements PluginDataHandler {
- public static final Supplier<CommonHandleCache<String, CryptorRuleHandle>>
CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
+ public static final Supplier<CommonHandleCache<String,
CryptorRuleHandler>> CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
@Override
public void handlerRule(final RuleData ruleData) {
Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
- CryptorRuleHandle cryptorRuleHandle =
GsonUtils.getInstance().fromJson(s, CryptorRuleHandle.class);
-
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
cryptorRuleHandle);
+ CryptorRuleHandler cryptorRuleHandler =
GsonUtils.getInstance().fromJson(s, CryptorRuleHandler.class);
+
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
cryptorRuleHandler);
});
}
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorResponsePluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorResponsePluginDataHandler.java
index f962435..7a753da 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorResponsePluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorResponsePluginDataHandler.java
@@ -19,7 +19,6 @@ package org.apache.shenyu.plugin.cryptor.handler;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
@@ -34,13 +33,13 @@ import java.util.function.Supplier;
*/
public class CryptorResponsePluginDataHandler implements PluginDataHandler {
- public static final Supplier<CommonHandleCache<String, CryptorRuleHandle>>
CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
+ public static final Supplier<CommonHandleCache<String,
CryptorRuleHandler>> CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
@Override
public void handlerRule(final RuleData ruleData) {
Optional.ofNullable(ruleData.getHandle()).ifPresent(s -> {
- CryptorRuleHandle cryptorRuleHandle =
GsonUtils.getInstance().fromJson(s, CryptorRuleHandle.class);
-
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
cryptorRuleHandle);
+ CryptorRuleHandler cryptorRuleHandler =
GsonUtils.getInstance().fromJson(s, CryptorRuleHandler.class);
+
CACHED_HANDLE.get().cachedHandle(CacheKeyUtils.INST.getKey(ruleData),
cryptorRuleHandler);
});
}
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/dto/CryptorRuleHandle.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRuleHandler.java
similarity index 95%
rename from
shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/dto/CryptorRuleHandle.java
rename to
shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRuleHandler.java
index d3fc66b..c64feb9 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/dto/CryptorRuleHandle.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/handler/CryptorRuleHandler.java
@@ -15,12 +15,12 @@
* limitations under the License.
*/
-package org.apache.shenyu.plugin.cryptor.dto;
+package org.apache.shenyu.plugin.cryptor.handler;
/**
* Cryptor response rule handle.
*/
-public class CryptorRuleHandle {
+public class CryptorRuleHandler {
private String strategyName;
@@ -114,7 +114,7 @@ public class CryptorRuleHandle {
@Override
public String toString() {
- return "CryptorResponseRuleHandle{"
+ return "CryptorRuleHandler{"
+ "strategyName='" + strategyName + '\''
+ ", decryptKey='" + decryptKey + '\''
+ ", encryptKey='" + encryptKey + '\''
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/request/CryptorRequestPlugin.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/request/CryptorRequestPlugin.java
index cf82419..4e51ff5 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/request/CryptorRequestPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/request/CryptorRequestPlugin.java
@@ -30,7 +30,7 @@ import
org.apache.shenyu.plugin.base.support.CachedBodyOutputMessage;
import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
import org.apache.shenyu.plugin.base.utils.ResponseUtils;
import org.apache.shenyu.plugin.cryptor.decorator.CryptorRequestDecorator;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import
org.apache.shenyu.plugin.cryptor.handler.CryptorRequestPluginDataHandler;
import org.apache.shenyu.plugin.cryptor.strategy.CryptorStrategyFactory;
import org.apache.shenyu.plugin.cryptor.utils.CryptorUtil;
@@ -63,7 +63,7 @@ public class CryptorRequestPlugin extends
AbstractShenyuPlugin {
@Override
@SuppressWarnings("unchecked")
protected Mono<Void> doExecute(final ServerWebExchange exchange, final
ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
- CryptorRuleHandle ruleHandle =
CryptorRequestPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
+ CryptorRuleHandler ruleHandle =
CryptorRequestPluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
if (Objects.isNull(ruleHandle)) {
LOG.error("Cryptor request rule configuration is null :{}",
rule.getId());
return chain.execute(exchange);
@@ -100,7 +100,7 @@ public class CryptorRequestPlugin extends
AbstractShenyuPlugin {
}
@SuppressWarnings("rawtypes")
- private Mono strategyMatch(final CryptorRuleHandle ruleHandle, final
String originalBody, final ServerWebExchange exchange) {
+ private Mono strategyMatch(final CryptorRuleHandler ruleHandle, final
String originalBody, final ServerWebExchange exchange) {
String parseBody = JsonUtil.parser(originalBody,
ruleHandle.getFieldNames());
if (Objects.isNull(parseBody)) {
Object error =
ShenyuResultWrap.error(ShenyuResultEnum.CRYPTOR_REQUEST_ERROR_CONFIGURATION.getCode(),
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/response/CryptorResponsePlugin.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/response/CryptorResponsePlugin.java
index 9c3e515..9223216 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/response/CryptorResponsePlugin.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/response/CryptorResponsePlugin.java
@@ -27,7 +27,7 @@ import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
import org.apache.shenyu.plugin.base.AbstractShenyuPlugin;
import org.apache.shenyu.plugin.base.utils.CacheKeyUtils;
import org.apache.shenyu.plugin.cryptor.decorator.CryptorResponseDecorator;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import
org.apache.shenyu.plugin.cryptor.handler.CryptorResponsePluginDataHandler;
import org.apache.shenyu.plugin.cryptor.utils.JsonUtil;
import org.slf4j.Logger;
@@ -46,7 +46,7 @@ public class CryptorResponsePlugin extends
AbstractShenyuPlugin {
@Override
protected Mono<Void> doExecute(final ServerWebExchange exchange, final
ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
- CryptorRuleHandle ruleHandle =
CryptorResponsePluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
+ CryptorRuleHandler ruleHandle =
CryptorResponsePluginDataHandler.CACHED_HANDLE.get().obtainHandle(CacheKeyUtils.INST.getKey(rule));
if (Objects.isNull(ruleHandle)) {
LOG.error("Cryptor response rule configuration is null :{}",
rule.getId());
return chain.execute(exchange);
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/strategy/CryptorStrategyFactory.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/strategy/CryptorStrategyFactory.java
index a47ccd1..83c6b5b 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/strategy/CryptorStrategyFactory.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/strategy/CryptorStrategyFactory.java
@@ -17,7 +17,7 @@
package org.apache.shenyu.plugin.cryptor.strategy;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import org.apache.shenyu.spi.ExtensionLoader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -50,7 +50,7 @@ public class CryptorStrategyFactory {
* @param data requestBody
* @return Return the parsed data if the match is successful, otherwise
return null.
*/
- public static String match(final CryptorRuleHandle ruleHandle, final
String data) {
+ public static String match(final CryptorRuleHandler ruleHandle, final
String data) {
switch (ruleHandle.getWay()) {
case DECRYPT:
return decrypt(ruleHandle.getStrategyName(),
ruleHandle.getDecryptKey(), data);
diff --git
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/utils/JsonUtil.java
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/utils/JsonUtil.java
index 3225788..2da2644 100644
---
a/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/utils/JsonUtil.java
+++
b/shenyu-plugin/shenyu-plugin-cryptor/src/main/java/org/apache/shenyu/plugin/cryptor/utils/JsonUtil.java
@@ -20,9 +20,10 @@ package org.apache.shenyu.plugin.cryptor.utils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
+import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.utils.GsonUtils;
-import org.apache.shenyu.plugin.cryptor.dto.CryptorRuleHandle;
+import org.apache.shenyu.plugin.cryptor.handler.CryptorRuleHandler;
import java.util.List;
import java.util.Map;
@@ -65,7 +66,7 @@ public class JsonUtil {
* @param ruleHandle ruleHandle
* @return is null
*/
- public static boolean checkParam(final CryptorRuleHandle ruleHandle) {
+ public static boolean checkParam(final CryptorRuleHandler ruleHandle) {
String json = GsonUtils.getGson().toJson(ruleHandle);
Map<String, String> map = GsonUtils.getInstance().toObjectMap(json,
String.class);
for (Map.Entry<String, String> entry : map.entrySet()) {
@@ -97,7 +98,7 @@ public class JsonUtil {
final AtomicInteger initDeep,
final String value,
final List<String> deepKey) {
- if (deepKey.size() == 0) {
+ if (CollectionUtils.isEmpty(deepKey)) {
return jsonElement;
}
if (jsonElement.isJsonPrimitive()) {
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/AlibabaDubboPlugin.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/AlibabaDubboPlugin.java
index 799cd43..d5a6aae 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/AlibabaDubboPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/AlibabaDubboPlugin.java
@@ -21,7 +21,6 @@ import com.alibaba.dubbo.remoting.exchange.ResponseCallback;
import com.alibaba.dubbo.remoting.exchange.ResponseFuture;
import com.alibaba.dubbo.rpc.Result;
import com.alibaba.dubbo.rpc.RpcContext;
-import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.dto.RuleData;
@@ -29,14 +28,9 @@ import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.common.enums.ResultEnum;
import org.apache.shenyu.plugin.alibaba.dubbo.proxy.AlibabaDubboProxyService;
import org.apache.shenyu.plugin.api.ShenyuPluginChain;
-import org.apache.shenyu.plugin.api.context.ShenyuContext;
-import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
-import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
import org.apache.shenyu.plugin.dubbo.common.AbstractDubboPlugin;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@@ -60,28 +54,27 @@ public class AlibabaDubboPlugin extends AbstractDubboPlugin
{
this.alibabaDubboProxyService = alibabaDubboProxyService;
}
+ /**
+ * do dubbo invoker.
+ *
+ * @param exchange exchange the current server exchange {@linkplain
ServerWebExchange}
+ * @param chain chain the current chain {@linkplain ServerWebExchange}
+ * @param selector selector {@linkplain SelectorData}
+ * @param rule rule {@linkplain RuleData}
+ * @param metaData the medata
+ * @param param the param
+ * @return {@code Mono<Void>} to indicate when request handling is complete
+ */
@Override
- protected Mono<Void> doExecute(final ServerWebExchange exchange, final
ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
- String param = exchange.getAttribute(Constants.PARAM_TRANSFORM);
- ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
- assert shenyuContext != null;
- MetaData metaData = exchange.getAttribute(Constants.META_DATA);
- if (!checkMetaData(metaData)) {
- assert metaData != null;
- LOG.error(" path is :{}, meta data have error.... {}",
shenyuContext.getPath(), metaData);
-
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
- Object error =
ShenyuResultWrap.error(ShenyuResultEnum.META_DATA_ERROR.getCode(),
ShenyuResultEnum.META_DATA_ERROR.getMsg(), null);
- return WebFluxResultUtils.result(exchange, error);
- }
- if (StringUtils.isNoneBlank(metaData.getParameterTypes()) &&
StringUtils.isBlank(param)) {
-
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
- Object error =
ShenyuResultWrap.error(ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getCode(),
ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getMsg(), null);
- return WebFluxResultUtils.result(exchange, error);
- }
+ protected Mono<Void> doDubboInvoker(final ServerWebExchange exchange,
+ final ShenyuPluginChain chain,
+ final SelectorData selector,
+ final RuleData rule,
+ final MetaData metaData,
+ final String param) {
RpcContext.getContext().setAttachment(Constants.DUBBO_SELECTOR_ID,
selector.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_RULE_ID,
rule.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_REMOTE_ADDRESS,
Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress());
-
return Mono.create(monoSink -> {
ResponseFuture future =
alibabaDubboProxyService.genericInvoker(param, metaData);
future.setCallback(new ResponseCallback() {
@@ -109,18 +102,4 @@ public class AlibabaDubboPlugin extends
AbstractDubboPlugin {
return chain.execute(exchange);
});
}
-
- @Override
- protected Mono<Void> handleSelectorIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
- return WebFluxResultUtils.noSelectorResult(pluginName, exchange);
- }
-
- @Override
- protected Mono<Void> handleRuleIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
- return WebFluxResultUtils.noRuleResult(pluginName, exchange);
- }
-
- private boolean checkMetaData(final MetaData metaData) {
- return null != metaData &&
!StringUtils.isBlank(metaData.getMethodName()) &&
!StringUtils.isBlank(metaData.getServiceName());
- }
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCache.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
similarity index 70%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCache.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
index 3816a60..6e75c08 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCache.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCache.java
@@ -26,10 +26,11 @@ import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.exception.ShenyuException;
-import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboConfigCache;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,9 +45,9 @@ import java.util.concurrent.ExecutionException;
* The type Application config cache.
*/
@SuppressWarnings("all")
-public final class ApplicationConfigCache {
+public final class AlibabaDubboConfigCache extends DubboConfigCache {
- private static final Logger LOG =
LoggerFactory.getLogger(ApplicationConfigCache.class);
+ private static final Logger LOG =
LoggerFactory.getLogger(AlibabaDubboConfigCache.class);
private ApplicationConfig applicationConfig;
@@ -76,7 +77,7 @@ public final class ApplicationConfigCache {
}
});
- private ApplicationConfigCache() {
+ private AlibabaDubboConfigCache() {
}
/**
@@ -84,7 +85,7 @@ public final class ApplicationConfigCache {
*
* @return the instance
*/
- public static ApplicationConfigCache getInstance() {
+ public static AlibabaDubboConfigCache getInstance() {
return ApplicationConfigCacheInstance.INSTANCE;
}
@@ -94,7 +95,7 @@ public final class ApplicationConfigCache {
* @param dubboRegisterConfig the dubbo register config
*/
public void init(final DubboRegisterConfig dubboRegisterConfig) {
- if (applicationConfig == null) {
+ if (Objects.isNull(applicationConfig)) {
applicationConfig = new ApplicationConfig("shenyu_proxy");
}
if (needUpdateRegistryConfig(dubboRegisterConfig)) {
@@ -109,15 +110,12 @@ public final class ApplicationConfigCache {
}
private boolean needUpdateRegistryConfig(final DubboRegisterConfig
dubboRegisterConfig) {
- if (registryConfig == null) {
+ if (Objects.isNull(registryConfig)) {
return true;
}
- if (!Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())
+ return !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())
|| !Objects.equals(dubboRegisterConfig.getRegister(),
registryConfig.getAddress())
- || !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())) {
- return true;
- }
- return false;
+ || !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol());
}
/**
@@ -163,24 +161,24 @@ public final class ApplicationConfigCache {
reference.setParameters(parameters);
String rpcExt = metaData.getRpcExt();
- DubboParamExtInfo dubboParamExtInfo =
GsonUtils.getInstance().fromJson(rpcExt, DubboParamExtInfo.class);
- if (Objects.nonNull(dubboParamExtInfo)) {
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getVersion())) {
- reference.setVersion(dubboParamExtInfo.getVersion());
+ DubboParam dubboParam = this.parserToDubboParam(rpcExt);
+ if (Objects.nonNull(dubboParam)) {
+ if (StringUtils.isNoneBlank(dubboParam.getVersion())) {
+ reference.setVersion(dubboParam.getVersion());
}
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getGroup())) {
- reference.setGroup(dubboParamExtInfo.getGroup());
+ if (StringUtils.isNoneBlank(dubboParam.getGroup())) {
+ reference.setGroup(dubboParam.getGroup());
}
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getUrl())) {
- reference.setUrl(dubboParamExtInfo.getUrl());
+ if (StringUtils.isNoneBlank(dubboParam.getUrl())) {
+ reference.setUrl(dubboParam.getUrl());
}
-
Optional.ofNullable(dubboParamExtInfo.getTimeout()).ifPresent(reference::setTimeout);
-
Optional.ofNullable(dubboParamExtInfo.getRetries()).ifPresent(reference::setRetries);
-
Optional.ofNullable(dubboParamExtInfo.getSent()).ifPresent(reference::setSent);
+
Optional.ofNullable(dubboParam.getTimeout()).ifPresent(reference::setTimeout);
+
Optional.ofNullable(dubboParam.getRetries()).ifPresent(reference::setRetries);
+
Optional.ofNullable(dubboParam.getSent()).ifPresent(reference::setSent);
}
try {
Object obj = reference.get();
- if (obj != null) {
+ if (Objects.nonNull(obj)) {
LOG.info("init alibaba dubbo reference success there meteData
is :{}", metaData);
cache.put(metaData.getPath(), reference);
}
@@ -228,83 +226,6 @@ public final class ApplicationConfigCache {
/**
* The Instance.
*/
- static final ApplicationConfigCache INSTANCE = new
ApplicationConfigCache();
- }
-
- /**
- * The type Dubbo param ext info.
- */
- static class DubboParamExtInfo {
-
- private String group;
-
- private String version;
-
- private String loadbalance;
-
- private Integer retries;
-
- private Integer timeout;
-
- private String url;
-
- private Boolean sent;
-
- public String getGroup() {
- return group;
- }
-
- public void setGroup(final String group) {
- this.group = group;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(final String version) {
- this.version = version;
- }
-
- public String getLoadbalance() {
- return loadbalance;
- }
-
- public void setLoadbalance(final String loadbalance) {
- this.loadbalance = loadbalance;
- }
-
- public Integer getRetries() {
- return retries;
- }
-
- public void setRetries(final Integer retries) {
- this.retries = retries;
- }
-
- public Integer getTimeout() {
- return timeout;
- }
-
- public void setTimeout(final Integer timeout) {
- this.timeout = timeout;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(final String url) {
- this.url = url;
- }
-
- public Boolean getSent() {
- return sent;
- }
-
- public void setSent(final Boolean sent) {
- this.sent = sent;
- }
+ static final AlibabaDubboConfigCache INSTANCE = new
AlibabaDubboConfigCache();
}
-
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaAbstractDubboPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaAbstractDubboPluginDataHandler.java
new file mode 100644
index 0000000..a11b1ac
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaAbstractDubboPluginDataHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.alibaba.dubbo.handler;
+
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
+import org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache;
+import
org.apache.shenyu.plugin.dubbo.common.handler.AbstractDubboPluginDataHandler;
+
+/**
+ * The type Alibaba dubbo plugin data subscriber.
+ */
+public class AlibabaAbstractDubboPluginDataHandler extends
AbstractDubboPluginDataHandler {
+
+ @Override
+ protected void initConfigCache(final DubboRegisterConfig
dubboRegisterConfig) {
+ AlibabaDubboConfigCache.getInstance().init(dubboRegisterConfig);
+ AlibabaDubboConfigCache.getInstance().invalidateAll();
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataHandler.java
deleted file mode 100644
index 642fc6b..0000000
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataHandler.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.shenyu.plugin.alibaba.dubbo.handler;
-
-import org.apache.commons.collections4.CollectionUtils;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.dto.PluginData;
-import org.apache.shenyu.common.dto.RuleData;
-import org.apache.shenyu.common.dto.SelectorData;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
-import org.apache.shenyu.common.dto.convert.rule.impl.DubboRuleHandle;
-import org.apache.shenyu.common.dto.convert.selector.DubboUpstream;
-import org.apache.shenyu.common.enums.PluginEnum;
-import org.apache.shenyu.common.utils.GsonUtils;
-import org.apache.shenyu.common.utils.Singleton;
-import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
-import org.apache.shenyu.loadbalancer.entity.Upstream;
-import org.apache.shenyu.plugin.alibaba.dubbo.cache.ApplicationConfigCache;
-import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
-import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
-import org.apache.shenyu.plugin.base.utils.BeanHolder;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Objects;
-import java.util.function.Supplier;
-import java.util.stream.Collectors;
-
-/**
- * The type Alibaba dubbo plugin data subscriber.
- */
-public class AlibabaDubboPluginDataHandler implements PluginDataHandler {
-
- public static final Supplier<CommonHandleCache<String, DubboRuleHandle>>
RULE_CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
-
- public static final Supplier<CommonHandleCache<String,
List<DubboUpstream>>> SELECTOR_CACHED_HANDLE = new
BeanHolder<>(CommonHandleCache::new);
-
- @Override
- public void handlerPlugin(final PluginData pluginData) {
- if (null != pluginData && pluginData.getEnabled()) {
- DubboRegisterConfig dubboRegisterConfig =
GsonUtils.getInstance().fromJson(pluginData.getConfig(),
DubboRegisterConfig.class);
- DubboRegisterConfig exist =
Singleton.INST.get(DubboRegisterConfig.class);
- if (Objects.isNull(dubboRegisterConfig)) {
- return;
- }
- if (Objects.isNull(exist) || !dubboRegisterConfig.equals(exist)) {
- // If it is null, initialize it
- ApplicationConfigCache.getInstance().init(dubboRegisterConfig);
- ApplicationConfigCache.getInstance().invalidateAll();
- }
- Singleton.INST.single(DubboRegisterConfig.class,
dubboRegisterConfig);
- }
- }
-
- @Override
- public void handlerSelector(final SelectorData selectorData) {
- List<DubboUpstream> dubboUpstreams =
GsonUtils.getInstance().fromList(selectorData.getHandle(), DubboUpstream.class);
- if (CollectionUtils.isEmpty(dubboUpstreams)) {
- return;
- }
- List<DubboUpstream> graySelectorHandle = new ArrayList<>();
- for (DubboUpstream each : dubboUpstreams) {
- if (StringUtils.isNotBlank(each.getUpstreamUrl()) &&
Objects.nonNull(each.isGray()) && each.isGray()) {
- graySelectorHandle.add(each);
- }
- }
- if (CollectionUtils.isNotEmpty(graySelectorHandle)) {
- SELECTOR_CACHED_HANDLE.get().cachedHandle(selectorData.getId(),
graySelectorHandle);
- UpstreamCacheManager.getInstance().submit(selectorData.getId(),
convertUpstreamList(graySelectorHandle));
- }
- }
-
- @Override
- public void removeSelector(final SelectorData selectorData) {
- SELECTOR_CACHED_HANDLE.get().removeHandle(selectorData.getId());
- UpstreamCacheManager.getInstance().removeByKey(selectorData.getId());
- }
-
- @Override
- public void handlerRule(final RuleData ruleData) {
- RULE_CACHED_HANDLE.get().cachedHandle(ruleData.getId(),
GsonUtils.getInstance().fromJson(ruleData.getHandle(), DubboRuleHandle.class));
- }
-
- @Override
- public void removeRule(final RuleData ruleData) {
- RULE_CACHED_HANDLE.get().removeHandle(ruleData.getId());
- }
-
- @Override
- public String pluginNamed() {
- return PluginEnum.DUBBO.getName();
- }
-
- private List<Upstream> convertUpstreamList(final List<DubboUpstream>
handleList) {
- return handleList.stream().map(u -> Upstream.builder()
- .protocol(u.getProtocol())
- .url(u.getUpstreamUrl())
- .weight(u.getWeight())
- .status(u.isStatus())
- .timestamp(u.getTimestamp())
- .warmup(u.getWarmup())
- .group(u.getGroup())
- .version(u.getVersion())
- .build()).collect(Collectors.toList());
- }
-}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboGrayLoadBalance.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboGrayLoadBalance.java
index 94e2904..a817fdc 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboGrayLoadBalance.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboGrayLoadBalance.java
@@ -31,7 +31,7 @@ import
org.apache.shenyu.common.dto.convert.selector.DubboUpstream;
import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
import org.apache.shenyu.loadbalancer.entity.Upstream;
import org.apache.shenyu.loadbalancer.factory.LoadBalancerFactory;
-import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaAbstractDubboPluginDataHandler;
import java.util.List;
import java.util.stream.Collectors;
@@ -43,12 +43,11 @@ public class AlibabaDubboGrayLoadBalance implements
LoadBalance {
@Override
public <T> Invoker<T> select(final List<Invoker<T>> invokers, final URL
url, final Invocation invocation) throws RpcException {
-
String shenyuSelectorId =
invocation.getAttachment(Constants.DUBBO_SELECTOR_ID);
String shenyuRuleId =
invocation.getAttachment(Constants.DUBBO_RULE_ID);
String remoteAddressIp =
invocation.getAttachment(Constants.DUBBO_REMOTE_ADDRESS);
- List<DubboUpstream> dubboUpstreams =
AlibabaDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle(shenyuSelectorId);
- DubboRuleHandle dubboRuleHandle =
AlibabaDubboPluginDataHandler.RULE_CACHED_HANDLE.get().obtainHandle(shenyuRuleId);
+ List<DubboUpstream> dubboUpstreams =
AlibabaAbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle(shenyuSelectorId);
+ DubboRuleHandle dubboRuleHandle =
AlibabaAbstractDubboPluginDataHandler.RULE_CACHED_HANDLE.get().obtainHandle(shenyuRuleId);
// if gray list is not empty,just use load balance to choose one.
if (CollectionUtils.isNotEmpty(dubboUpstreams)) {
Upstream upstream =
LoadBalancerFactory.selector(UpstreamCacheManager.getInstance().findUpstreamListBySelectorId(shenyuSelectorId),
dubboRuleHandle.getLoadbalance(), remoteAddressIp);
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyService.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyService.java
index 9c02d32..61837b8 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyService.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyService.java
@@ -29,7 +29,7 @@ import org.apache.commons.lang3.tuple.Pair;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.utils.ParamCheckUtils;
-import org.apache.shenyu.plugin.alibaba.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache;
import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -63,10 +63,10 @@ public class AlibabaDubboProxyService {
* @throws ShenyuException the shenyu exception
*/
public ResponseFuture genericInvoker(final String body, final MetaData
metaData) throws ShenyuException {
- ReferenceConfig<GenericService> reference =
ApplicationConfigCache.getInstance().get(metaData.getPath());
+ ReferenceConfig<GenericService> reference =
AlibabaDubboConfigCache.getInstance().get(metaData.getPath());
if (Objects.isNull(reference) ||
StringUtils.isEmpty(reference.getInterface())) {
-
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
- reference = ApplicationConfigCache.getInstance().initRef(metaData);
+
AlibabaDubboConfigCache.getInstance().invalidate(metaData.getPath());
+ reference =
AlibabaDubboConfigCache.getInstance().initRef(metaData);
}
try {
GenericService genericService = reference.get();
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/AlibabaDubboMetaDataSubscriber.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/AlibabaDubboMetaDataSubscriber.java
index d251b11..165e9d6 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/AlibabaDubboMetaDataSubscriber.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/AlibabaDubboMetaDataSubscriber.java
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.alibaba.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache;
import org.apache.shenyu.sync.data.api.MetaDataSubscriber;
/**
@@ -38,9 +38,9 @@ public class AlibabaDubboMetaDataSubscriber implements
MetaDataSubscriber {
public void onSubscribe(final MetaData metaData) {
if (RpcTypeEnum.DUBBO.getName().equals(metaData.getRpcType())) {
MetaData exist = META_DATA.get(metaData.getPath());
- if (Objects.isNull(exist) ||
Objects.isNull(ApplicationConfigCache.getInstance().get(metaData.getPath()))) {
+ if (Objects.isNull(exist) ||
Objects.isNull(AlibabaDubboConfigCache.getInstance().get(metaData.getPath()))) {
// The first initialization
- ApplicationConfigCache.getInstance().initRef(metaData);
+ AlibabaDubboConfigCache.getInstance().initRef(metaData);
} else {
// There are updates, which only support the update of four
properties of serviceName rpcExt parameterTypes methodName,
// because these four properties will affect the call of Dubbo;
@@ -48,7 +48,7 @@ public class AlibabaDubboMetaDataSubscriber implements
MetaDataSubscriber {
|| !Objects.equals(metaData.getRpcExt(),
exist.getRpcExt())
|| !Objects.equals(metaData.getParameterTypes(),
exist.getParameterTypes())
|| !Objects.equals(metaData.getMethodName(),
exist.getMethodName())) {
- ApplicationConfigCache.getInstance().build(metaData);
+ AlibabaDubboConfigCache.getInstance().build(metaData);
}
}
META_DATA.put(metaData.getPath(), metaData);
@@ -58,7 +58,7 @@ public class AlibabaDubboMetaDataSubscriber implements
MetaDataSubscriber {
@Override
public void unSubscribe(final MetaData metaData) {
if (RpcTypeEnum.DUBBO.getName().equals(metaData.getRpcType())) {
-
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
+
AlibabaDubboConfigCache.getInstance().invalidate(metaData.getPath());
META_DATA.remove(metaData.getPath());
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCacheTest.java
similarity index 65%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCacheTest.java
index 67d19d6..4437dbb 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/ApplicationConfigCacheTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/cache/AlibabaDubboConfigCacheTest.java
@@ -19,9 +19,10 @@ package org.apache.shenyu.plugin.alibaba.dubbo.cache;
import com.alibaba.dubbo.config.ReferenceConfig;
import com.alibaba.dubbo.config.RegistryConfig;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboParam;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -37,21 +38,21 @@ import static org.mockito.Mockito.when;
/**
- * The Test Case For ApplicationConfigCache.
+ * The Test Case For AlibabaDubboConfigCache.
*/
@RunWith(MockitoJUnitRunner.class)
-public final class ApplicationConfigCacheTest {
+public final class AlibabaDubboConfigCacheTest {
- private ApplicationConfigCache applicationConfigCache;
+ private AlibabaDubboConfigCache alibabaDubboConfigCache;
@Before
public void setUp() {
- applicationConfigCache = ApplicationConfigCache.getInstance();
+ alibabaDubboConfigCache = AlibabaDubboConfigCache.getInstance();
}
@Test
public void getInstance() {
- assertNotNull(this.applicationConfigCache);
+ assertNotNull(this.alibabaDubboConfigCache);
}
@Test
@@ -59,13 +60,13 @@ public final class ApplicationConfigCacheTest {
DubboRegisterConfig dubboRegisterConfig = new DubboRegisterConfig();
dubboRegisterConfig.setRegister("zookeeper://127.0.0.1:2181");
dubboRegisterConfig.setProtocol("dubbo");
- this.applicationConfigCache.init(dubboRegisterConfig);
+ this.alibabaDubboConfigCache.init(dubboRegisterConfig);
RegistryConfig registryConfig = null;
try {
- Field registryConfigField =
ApplicationConfigCache.class.getDeclaredField("registryConfig");
+ Field registryConfigField =
AlibabaDubboConfigCache.class.getDeclaredField("registryConfig");
registryConfigField.setAccessible(true);
- Object config =
registryConfigField.get(this.applicationConfigCache);
+ Object config =
registryConfigField.get(this.alibabaDubboConfigCache);
assertNotNull(config);
registryConfig = (RegistryConfig) config;
} catch (NoSuchFieldException | IllegalAccessException e) {
@@ -75,13 +76,13 @@ public final class ApplicationConfigCacheTest {
DubboRegisterConfig dubboRegisterConfig1 = new DubboRegisterConfig();
dubboRegisterConfig1.setRegister("zookeeper://127.0.0.2:2181");
dubboRegisterConfig1.setProtocol("dubbo");
- this.applicationConfigCache.init(dubboRegisterConfig1);
+ this.alibabaDubboConfigCache.init(dubboRegisterConfig1);
RegistryConfig registryConfig1 = null;
try {
- Field registryConfigField =
ApplicationConfigCache.class.getDeclaredField("registryConfig");
+ Field registryConfigField =
AlibabaDubboConfigCache.class.getDeclaredField("registryConfig");
registryConfigField.setAccessible(true);
- Object config =
registryConfigField.get(this.applicationConfigCache);
+ Object config =
registryConfigField.get(this.alibabaDubboConfigCache);
assertNotNull(config);
registryConfig1 = (RegistryConfig) config;
} catch (NoSuchFieldException | IllegalAccessException e) {
@@ -94,34 +95,34 @@ public final class ApplicationConfigCacheTest {
public void testInitRef() {
MetaData metaData = new MetaData();
metaData.setPath("/test");
- ApplicationConfigCache applicationConfigCacheMock =
mock(ApplicationConfigCache.class);
- when(applicationConfigCacheMock.initRef(metaData))
+ AlibabaDubboConfigCache alibabaDubboConfigCacheMock =
mock(AlibabaDubboConfigCache.class);
+ when(alibabaDubboConfigCacheMock.initRef(metaData))
.thenReturn(new ReferenceConfig());
- assertNotNull(applicationConfigCacheMock.initRef(metaData));
+ assertNotNull(alibabaDubboConfigCacheMock.initRef(metaData));
}
@Test
public void testGet() {
- assertNotNull(this.applicationConfigCache.get("/test"));
+ assertNotNull(this.alibabaDubboConfigCache.get("/test"));
}
@Test
public void testBuild() {
- ApplicationConfigCache.DubboParamExtInfo dubboParamExtInfo = new
ApplicationConfigCache.DubboParamExtInfo();
- dubboParamExtInfo.setVersion("2.6.5");
- dubboParamExtInfo.setGroup("Group");
- dubboParamExtInfo.setUrl("http://192.168.55.113/dubbo");
+ DubboParam dubboParam = new DubboParam();
+ dubboParam.setVersion("2.6.5");
+ dubboParam.setGroup("Group");
+ dubboParam.setUrl("http://192.168.55.113/dubbo");
MetaData metaData = new MetaData();
- metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParamExtInfo));
- ApplicationConfigCache applicationConfigCacheMock =
mock(ApplicationConfigCache.class);
- when(applicationConfigCacheMock.build(metaData))
+ metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParam));
+ AlibabaDubboConfigCache alibabaDubboConfigCacheMock =
mock(AlibabaDubboConfigCache.class);
+ when(alibabaDubboConfigCacheMock.build(metaData))
.thenReturn(new ReferenceConfig());
- assertNotNull(applicationConfigCacheMock.build(metaData));
+ assertNotNull(alibabaDubboConfigCacheMock.build(metaData));
}
@Test
public void testInvalidate() {
- this.applicationConfigCache.invalidate("/test");
- this.applicationConfigCache.invalidateAll();
+ this.alibabaDubboConfigCache.invalidate("/test");
+ this.alibabaDubboConfigCache.invalidateAll();
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataTest.java
index e584b0c..4e618c5 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/handler/AlibabaDubboPluginDataTest.java
@@ -37,13 +37,13 @@ import org.mockito.junit.MockitoJUnitRunner;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public final class AlibabaDubboPluginDataTest {
- private AlibabaDubboPluginDataHandler alibabaDubboPluginDataHandler;
+ private AlibabaAbstractDubboPluginDataHandler
alibabaDubboPluginDataHandler;
private final String registryConfig =
"{\"protocol\":\"zookeeper\",\"register\":\"127.0.0.1:2181\"}";
@Before
public void setUp() {
- alibabaDubboPluginDataHandler = new AlibabaDubboPluginDataHandler();
+ alibabaDubboPluginDataHandler = new
AlibabaAbstractDubboPluginDataHandler();
MetaData metaData = new MetaData();
metaData.setId("1332017966661636096");
metaData.setAppName("dubbo");
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyServiceTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyServiceTest.java
index e597679..b51e7b2 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyServiceTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/proxy/AlibabaDubboProxyServiceTest.java
@@ -28,7 +28,7 @@ import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.alibaba.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache;
import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService;
import org.junit.After;
import org.junit.Assert;
@@ -70,7 +70,7 @@ public final class AlibabaDubboProxyServiceTest {
@After
public void after() {
- ApplicationConfigCache.getInstance().invalidateAll();
+ AlibabaDubboConfigCache.getInstance().invalidateAll();
}
@Test
@@ -84,10 +84,10 @@ public final class AlibabaDubboProxyServiceTest {
RpcContext.getContext().setFuture(new FutureAdapter<>(new
SimpleFuture(new RpcResult(sample))));
return sample;
});
- try (MockedStatic<ApplicationConfigCache>
applicationConfigCacheMockedStatic = mockStatic(ApplicationConfigCache.class)) {
- ApplicationConfigCache applicationConfigCache =
mock(ApplicationConfigCache.class);
-
applicationConfigCacheMockedStatic.when(ApplicationConfigCache::getInstance).thenReturn(applicationConfigCache);
-
when(applicationConfigCache.initRef(metaData)).thenReturn(referenceConfig);
+ try (MockedStatic<AlibabaDubboConfigCache>
applicationConfigCacheMockedStatic = mockStatic(AlibabaDubboConfigCache.class))
{
+ AlibabaDubboConfigCache alibabaDubboConfigCache =
mock(AlibabaDubboConfigCache.class);
+
applicationConfigCacheMockedStatic.when(AlibabaDubboConfigCache::getInstance).thenReturn(alibabaDubboConfigCache);
+
when(alibabaDubboConfigCache.initRef(metaData)).thenReturn(referenceConfig);
AlibabaDubboProxyService alibabaDubboProxyService = new
AlibabaDubboProxyService(new BodyParamResolveServiceImpl());
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
index 9b46778..91bb6e4 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/plugin/alibaba/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
@@ -21,7 +21,7 @@ import com.alibaba.dubbo.config.ReferenceConfig;
import com.google.common.cache.LoadingCache;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.alibaba.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.alibaba.dubbo.cache.AlibabaDubboConfigCache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -62,10 +62,10 @@ public final class ApacheDubboMetaDataSubscriberTest {
public void testOnSubscribe() throws NoSuchFieldException,
IllegalAccessException {
ReferenceConfig referenceConfig = mock(ReferenceConfig.class);
when(referenceConfig.getInterface()).thenReturn("/dubbo/findAll");
- ApplicationConfigCache applicationConfigCache =
ApplicationConfigCache.getInstance();
- Field field = ApplicationConfigCache.class.getDeclaredField("cache");
+ AlibabaDubboConfigCache alibabaDubboConfigCache =
AlibabaDubboConfigCache.getInstance();
+ Field field = AlibabaDubboConfigCache.class.getDeclaredField("cache");
field.setAccessible(true);
- ((LoadingCache)
field.get(applicationConfigCache)).put("/dubbo/findAll", referenceConfig);
+ ((LoadingCache)
field.get(alibabaDubboConfigCache)).put("/dubbo/findAll", referenceConfig);
alibabaDubboMetaDataSubscriber.onSubscribe(metaData);
MetaData metaData = MetaData.builder()
.id("1332017966661636096")
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java
index 2887775..6180597 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/ApacheDubboPlugin.java
@@ -17,7 +17,6 @@
package org.apache.shenyu.plugin.apache.dubbo;
-import org.apache.commons.lang3.StringUtils;
import org.apache.dubbo.rpc.RpcContext;
import org.apache.shenyu.common.constant.Constants;
import org.apache.shenyu.common.dto.MetaData;
@@ -25,14 +24,7 @@ import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.plugin.apache.dubbo.proxy.ApacheDubboProxyService;
import org.apache.shenyu.plugin.api.ShenyuPluginChain;
-import org.apache.shenyu.plugin.api.context.ShenyuContext;
-import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
-import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
-import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
import org.apache.shenyu.plugin.dubbo.common.AbstractDubboPlugin;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.http.HttpStatus;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@@ -43,8 +35,6 @@ import java.util.Objects;
*/
public class ApacheDubboPlugin extends AbstractDubboPlugin {
- private static final Logger LOG =
LoggerFactory.getLogger(ApacheDubboPlugin.class);
-
private final ApacheDubboProxyService dubboProxyService;
/**
@@ -56,41 +46,26 @@ public class ApacheDubboPlugin extends AbstractDubboPlugin {
this.dubboProxyService = dubboProxyService;
}
+ /**
+ * do dubbo invoker.
+ *
+ * @param exchange exchange the current server exchange {@linkplain
ServerWebExchange}
+ * @param chain chain the current chain {@linkplain ServerWebExchange}
+ * @param metaData the medata
+ * @param param the param
+ * @return {@code Mono<Void>} to indicate when request handling is complete
+ */
@Override
- protected Mono<Void> doExecute(final ServerWebExchange exchange, final
ShenyuPluginChain chain, final SelectorData selector, final RuleData rule) {
- String param = exchange.getAttribute(Constants.PARAM_TRANSFORM);
- ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
- assert shenyuContext != null;
- MetaData metaData = exchange.getAttribute(Constants.META_DATA);
- if (!checkMetaData(metaData)) {
- LOG.error(" path is : {}, meta data have error : {}",
shenyuContext.getPath(), metaData);
-
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
- Object error =
ShenyuResultWrap.error(ShenyuResultEnum.META_DATA_ERROR.getCode(),
ShenyuResultEnum.META_DATA_ERROR.getMsg(), null);
- return WebFluxResultUtils.result(exchange, error);
- }
- if (StringUtils.isNoneBlank(metaData.getParameterTypes()) &&
StringUtils.isBlank(param)) {
-
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
- Object error =
ShenyuResultWrap.error(ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getCode(),
ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getMsg(), null);
- return WebFluxResultUtils.result(exchange, error);
- }
+ protected Mono<Void> doDubboInvoker(final ServerWebExchange exchange,
+ final ShenyuPluginChain chain,
+ final SelectorData selector,
+ final RuleData rule,
+ final MetaData metaData,
+ final String param) {
RpcContext.getContext().setAttachment(Constants.DUBBO_SELECTOR_ID,
selector.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_RULE_ID,
rule.getId());
RpcContext.getContext().setAttachment(Constants.DUBBO_REMOTE_ADDRESS,
Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress());
final Mono<Object> result = dubboProxyService.genericInvoker(param,
metaData, exchange);
return result.then(chain.execute(exchange));
}
-
- @Override
- protected Mono<Void> handleSelectorIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
- return WebFluxResultUtils.noSelectorResult(pluginName, exchange);
- }
-
- @Override
- protected Mono<Void> handleRuleIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
- return WebFluxResultUtils.noRuleResult(pluginName, exchange);
- }
-
- private boolean checkMetaData(final MetaData metaData) {
- return null != metaData &&
!StringUtils.isBlank(metaData.getMethodName()) &&
!StringUtils.isBlank(metaData.getServiceName());
- }
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCache.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
similarity index 70%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCache.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
index 2ca6475..ecb9d43 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCache.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCache.java
@@ -26,10 +26,11 @@ import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.shenyu.common.constant.Constants;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.exception.ShenyuException;
-import org.apache.shenyu.common.utils.GsonUtils;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboConfigCache;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -44,9 +45,9 @@ import java.util.concurrent.ExecutionException;
/**
* The type Application config cache.
*/
-public final class ApplicationConfigCache {
+public final class ApacheDubboConfigCache extends DubboConfigCache {
- private static final Logger LOG =
LoggerFactory.getLogger(ApplicationConfigCache.class);
+ private static final Logger LOG =
LoggerFactory.getLogger(ApacheDubboConfigCache.class);
private ApplicationConfig applicationConfig;
@@ -76,7 +77,7 @@ public final class ApplicationConfigCache {
}
});
- private ApplicationConfigCache() {
+ private ApacheDubboConfigCache() {
}
/**
@@ -84,7 +85,7 @@ public final class ApplicationConfigCache {
*
* @return the instance
*/
- public static ApplicationConfigCache getInstance() {
+ public static ApacheDubboConfigCache getInstance() {
return ApplicationConfigCacheInstance.INSTANCE;
}
@@ -94,7 +95,7 @@ public final class ApplicationConfigCache {
* @param dubboRegisterConfig the dubbo register config
*/
public void init(final DubboRegisterConfig dubboRegisterConfig) {
- if (applicationConfig == null) {
+ if (Objects.isNull(applicationConfig)) {
applicationConfig = new ApplicationConfig("shenyu_proxy");
}
if (needUpdateRegistryConfig(dubboRegisterConfig)) {
@@ -109,15 +110,12 @@ public final class ApplicationConfigCache {
}
private boolean needUpdateRegistryConfig(final DubboRegisterConfig
dubboRegisterConfig) {
- if (registryConfig == null) {
+ if (Objects.isNull(registryConfig)) {
return true;
}
- if (!Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())
+ return !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())
|| !Objects.equals(dubboRegisterConfig.getRegister(),
registryConfig.getAddress())
- || !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol())) {
- return true;
- }
- return false;
+ || !Objects.equals(dubboRegisterConfig.getProtocol(),
registryConfig.getProtocol());
}
/**
@@ -136,7 +134,6 @@ public final class ApplicationConfigCache {
LOG.error("init dubbo ref exception", e);
}
return build(metaData);
-
}
/**
@@ -165,24 +162,24 @@ public final class ApplicationConfigCache {
reference.setParameters(parameters);
String rpcExt = metaData.getRpcExt();
- DubboParamExtInfo dubboParamExtInfo =
GsonUtils.getInstance().fromJson(rpcExt, DubboParamExtInfo.class);
- if (Objects.nonNull(dubboParamExtInfo)) {
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getVersion())) {
- reference.setVersion(dubboParamExtInfo.getVersion());
+ DubboParam dubboParam = parserToDubboParam(rpcExt);
+ if (Objects.nonNull(dubboParam)) {
+ if (StringUtils.isNoneBlank(dubboParam.getVersion())) {
+ reference.setVersion(dubboParam.getVersion());
}
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getGroup())) {
- reference.setGroup(dubboParamExtInfo.getGroup());
+ if (StringUtils.isNoneBlank(dubboParam.getGroup())) {
+ reference.setGroup(dubboParam.getGroup());
}
- if (StringUtils.isNoneBlank(dubboParamExtInfo.getUrl())) {
- reference.setUrl(dubboParamExtInfo.getUrl());
+ if (StringUtils.isNoneBlank(dubboParam.getUrl())) {
+ reference.setUrl(dubboParam.getUrl());
}
-
Optional.ofNullable(dubboParamExtInfo.getTimeout()).ifPresent(reference::setTimeout);
-
Optional.ofNullable(dubboParamExtInfo.getRetries()).ifPresent(reference::setRetries);
-
Optional.ofNullable(dubboParamExtInfo.getSent()).ifPresent(reference::setSent);
+
Optional.ofNullable(dubboParam.getTimeout()).ifPresent(reference::setTimeout);
+
Optional.ofNullable(dubboParam.getRetries()).ifPresent(reference::setRetries);
+
Optional.ofNullable(dubboParam.getSent()).ifPresent(reference::setSent);
}
try {
Object obj = reference.get();
- if (obj != null) {
+ if (Objects.nonNull(obj)) {
LOG.info("init apache dubbo reference success there meteData
is :{}", metaData);
cache.put(metaData.getPath(), reference);
}
@@ -230,82 +227,6 @@ public final class ApplicationConfigCache {
/**
* The Instance.
*/
- static final ApplicationConfigCache INSTANCE = new
ApplicationConfigCache();
- }
-
- /**
- * The type Dubbo param ext info.
- */
- static class DubboParamExtInfo {
-
- private String group;
-
- private String version;
-
- private String loadbalance;
-
- private Integer retries;
-
- private Integer timeout;
-
- private String url;
-
- private Boolean sent;
-
- public String getGroup() {
- return group;
- }
-
- public void setGroup(final String group) {
- this.group = group;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(final String version) {
- this.version = version;
- }
-
- public String getLoadbalance() {
- return loadbalance;
- }
-
- public void setLoadbalance(final String loadbalance) {
- this.loadbalance = loadbalance;
- }
-
- public Integer getRetries() {
- return retries;
- }
-
- public void setRetries(final Integer retries) {
- this.retries = retries;
- }
-
- public Integer getTimeout() {
- return timeout;
- }
-
- public void setTimeout(final Integer timeout) {
- this.timeout = timeout;
- }
-
- public String getUrl() {
- return url;
- }
-
- public void setUrl(final String url) {
- this.url = url;
- }
-
- public Boolean getSent() {
- return sent;
- }
-
- public void setSent(final Boolean sent) {
- this.sent = sent;
- }
+ static final ApacheDubboConfigCache INSTANCE = new
ApacheDubboConfigCache();
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandler.java
new file mode 100644
index 0000000..dabcb4a
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandler.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.apache.dubbo.handler;
+
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
+import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache;
+import
org.apache.shenyu.plugin.dubbo.common.handler.AbstractDubboPluginDataHandler;
+
+/**
+ * The type Apache dubbo plugin data handler.
+ */
+public class ApacheAbstractDubboPluginDataHandler extends
AbstractDubboPluginDataHandler {
+
+ @Override
+ protected void initConfigCache(final DubboRegisterConfig
dubboRegisterConfig) {
+ ApacheDubboConfigCache.getInstance().init(dubboRegisterConfig);
+ ApacheDubboConfigCache.getInstance().invalidateAll();
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboGrayLoadBalance.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboGrayLoadBalance.java
index 34bed02..2c64ecb 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboGrayLoadBalance.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboGrayLoadBalance.java
@@ -31,7 +31,7 @@ import
org.apache.shenyu.common.dto.convert.selector.DubboUpstream;
import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
import org.apache.shenyu.loadbalancer.entity.Upstream;
import org.apache.shenyu.loadbalancer.factory.LoadBalancerFactory;
-import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheAbstractDubboPluginDataHandler;
import java.util.List;
import java.util.stream.Collectors;
@@ -46,8 +46,8 @@ public class ApacheDubboGrayLoadBalance implements
LoadBalance {
String shenyuSelectorId =
invocation.getAttachment(Constants.DUBBO_SELECTOR_ID);
String shenyuRuleId =
invocation.getAttachment(Constants.DUBBO_RULE_ID);
String remoteAddressIp =
invocation.getAttachment(Constants.DUBBO_REMOTE_ADDRESS);
- List<DubboUpstream> dubboUpstreams =
ApacheDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle(shenyuSelectorId);
- DubboRuleHandle dubboRuleHandle =
ApacheDubboPluginDataHandler.RULE_CACHED_HANDLE.get().obtainHandle(shenyuRuleId);
+ List<DubboUpstream> dubboUpstreams =
ApacheAbstractDubboPluginDataHandler.SELECTOR_CACHED_HANDLE.get().obtainHandle(shenyuSelectorId);
+ DubboRuleHandle dubboRuleHandle =
ApacheAbstractDubboPluginDataHandler.RULE_CACHED_HANDLE.get().obtainHandle(shenyuRuleId);
// if gray list is not empty,just use load balance to choose one.
if (CollectionUtils.isNotEmpty(dubboUpstreams)) {
Upstream upstream =
LoadBalancerFactory.selector(UpstreamCacheManager.getInstance().findUpstreamListBySelectorId(shenyuSelectorId),
dubboRuleHandle.getLoadbalance(), remoteAddressIp);
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java
index 1653b7a..47ba83b 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java
@@ -30,7 +30,7 @@ import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.ResultEnum;
import org.apache.shenyu.common.exception.ShenyuException;
import org.apache.shenyu.common.utils.ParamCheckUtils;
-import org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache;
import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;
@@ -69,10 +69,10 @@ public class ApacheDubboProxyService {
if (StringUtils.isNotBlank(dubboTagRouteFromHttpHeaders)) {
RpcContext.getContext().setAttachment(CommonConstants.TAG_KEY,
dubboTagRouteFromHttpHeaders);
}
- ReferenceConfig<GenericService> reference =
ApplicationConfigCache.getInstance().get(metaData.getPath());
+ ReferenceConfig<GenericService> reference =
ApacheDubboConfigCache.getInstance().get(metaData.getPath());
if (Objects.isNull(reference) ||
StringUtils.isEmpty(reference.getInterface())) {
-
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
- reference = ApplicationConfigCache.getInstance().initRef(metaData);
+
ApacheDubboConfigCache.getInstance().invalidate(metaData.getPath());
+ reference = ApacheDubboConfigCache.getInstance().initRef(metaData);
}
GenericService genericService = reference.get();
Pair<String[], Object[]> pair;
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriber.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriber.java
index c13ce48..ba007fe 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriber.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriber.java
@@ -24,7 +24,7 @@ import java.util.concurrent.ConcurrentMap;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache;
import org.apache.shenyu.sync.data.api.MetaDataSubscriber;
/**
@@ -38,9 +38,9 @@ public class ApacheDubboMetaDataSubscriber implements
MetaDataSubscriber {
public void onSubscribe(final MetaData metaData) {
if (RpcTypeEnum.DUBBO.getName().equals(metaData.getRpcType())) {
MetaData exist = META_DATA.get(metaData.getPath());
- if (Objects.isNull(exist) ||
Objects.isNull(ApplicationConfigCache.getInstance().get(metaData.getPath()))) {
+ if (Objects.isNull(exist) ||
Objects.isNull(ApacheDubboConfigCache.getInstance().get(metaData.getPath()))) {
// The first initialization
- ApplicationConfigCache.getInstance().initRef(metaData);
+ ApacheDubboConfigCache.getInstance().initRef(metaData);
} else {
// There are updates, which only support the update of four
properties of serviceName rpcExt parameterTypes methodName,
// because these four properties will affect the call of Dubbo;
@@ -48,7 +48,7 @@ public class ApacheDubboMetaDataSubscriber implements
MetaDataSubscriber {
|| !Objects.equals(metaData.getRpcExt(),
exist.getRpcExt())
|| !Objects.equals(metaData.getParameterTypes(),
exist.getParameterTypes())
|| !Objects.equals(metaData.getMethodName(),
exist.getMethodName())) {
- ApplicationConfigCache.getInstance().build(metaData);
+ ApacheDubboConfigCache.getInstance().build(metaData);
}
}
META_DATA.put(metaData.getPath(), metaData);
@@ -58,7 +58,7 @@ public class ApacheDubboMetaDataSubscriber implements
MetaDataSubscriber {
@Override
public void unSubscribe(final MetaData metaData) {
if (RpcTypeEnum.DUBBO.getName().equals(metaData.getRpcType())) {
-
ApplicationConfigCache.getInstance().invalidate(metaData.getPath());
+
ApacheDubboConfigCache.getInstance().invalidate(metaData.getPath());
META_DATA.remove(metaData.getPath());
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCacheTest.java
similarity index 70%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCacheTest.java
index 1d6667c..343f1db 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApplicationConfigCacheTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/cache/ApacheDubboConfigCacheTest.java
@@ -19,10 +19,10 @@ package org.apache.shenyu.plugin.apache.dubbo.cache;
import com.alibaba.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.utils.GsonUtils;
-import
org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache.DubboParamExtInfo;
+import org.apache.shenyu.plugin.dubbo.common.cache.DubboParam;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
@@ -38,21 +38,21 @@ import static org.mockito.Mockito.when;
/**
- * The Test Case For ApplicationConfigCache.
+ * The Test Case For ApacheDubboConfigCache.
*/
@RunWith(MockitoJUnitRunner.class)
-public final class ApplicationConfigCacheTest {
+public final class ApacheDubboConfigCacheTest {
- private ApplicationConfigCache applicationConfigCache;
+ private ApacheDubboConfigCache apacheDubboConfigCache;
@Before
public void setUp() {
- applicationConfigCache = ApplicationConfigCache.getInstance();
+ apacheDubboConfigCache = ApacheDubboConfigCache.getInstance();
}
@Test
public void getInstance() {
- assertNotNull(this.applicationConfigCache);
+ assertNotNull(this.apacheDubboConfigCache);
}
@Test
@@ -60,13 +60,13 @@ public final class ApplicationConfigCacheTest {
DubboRegisterConfig dubboRegisterConfig = new DubboRegisterConfig();
dubboRegisterConfig.setRegister("zookeeper://127.0.0.1:2181");
dubboRegisterConfig.setProtocol("dubbo");
- this.applicationConfigCache.init(dubboRegisterConfig);
+ this.apacheDubboConfigCache.init(dubboRegisterConfig);
RegistryConfig registryConfig = null;
try {
- Field registryConfigField =
ApplicationConfigCache.class.getDeclaredField("registryConfig");
+ Field registryConfigField =
ApacheDubboConfigCache.class.getDeclaredField("registryConfig");
registryConfigField.setAccessible(true);
- Object config =
registryConfigField.get(this.applicationConfigCache);
+ Object config =
registryConfigField.get(this.apacheDubboConfigCache);
assertNotNull(config);
registryConfig = (RegistryConfig) config;
} catch (NoSuchFieldException | IllegalAccessException e) {
@@ -76,13 +76,13 @@ public final class ApplicationConfigCacheTest {
DubboRegisterConfig dubboRegisterConfig1 = new DubboRegisterConfig();
dubboRegisterConfig1.setRegister("zookeeper://127.0.0.2:2181");
dubboRegisterConfig1.setProtocol("dubbo");
- this.applicationConfigCache.init(dubboRegisterConfig1);
+ this.apacheDubboConfigCache.init(dubboRegisterConfig1);
RegistryConfig registryConfig1 = null;
try {
- Field registryConfigField =
ApplicationConfigCache.class.getDeclaredField("registryConfig");
+ Field registryConfigField =
ApacheDubboConfigCache.class.getDeclaredField("registryConfig");
registryConfigField.setAccessible(true);
- Object config =
registryConfigField.get(this.applicationConfigCache);
+ Object config =
registryConfigField.get(this.apacheDubboConfigCache);
assertNotNull(config);
registryConfig1 = (RegistryConfig) config;
} catch (NoSuchFieldException | IllegalAccessException e) {
@@ -95,35 +95,35 @@ public final class ApplicationConfigCacheTest {
public void testInitRef() {
MetaData metaData = new MetaData();
metaData.setPath("/test");
- ApplicationConfigCache applicationConfigCacheMock =
mock(ApplicationConfigCache.class);
- when(applicationConfigCacheMock.initRef(metaData))
+ ApacheDubboConfigCache apacheDubboConfigCacheMock =
mock(ApacheDubboConfigCache.class);
+ when(apacheDubboConfigCacheMock.initRef(metaData))
.thenReturn(new ReferenceConfig());
- assertNotNull(applicationConfigCacheMock.initRef(metaData));
+ assertNotNull(apacheDubboConfigCacheMock.initRef(metaData));
}
@Test
public void testGet() {
- assertNotNull(this.applicationConfigCache.get("/test"));
+ assertNotNull(this.apacheDubboConfigCache.get("/test"));
}
@Test
public void testBuild() {
- DubboParamExtInfo dubboParamExtInfo = new DubboParamExtInfo();
+ DubboParam dubboParamExtInfo = new DubboParam();
dubboParamExtInfo.setVersion("2.7.5");
dubboParamExtInfo.setGroup("Group");
dubboParamExtInfo.setLoadbalance("Balance");
dubboParamExtInfo.setUrl("http://192.168.55.113/dubbo");
MetaData metaData = new MetaData();
metaData.setRpcExt(GsonUtils.getInstance().toJson(dubboParamExtInfo));
- ApplicationConfigCache applicationConfigCacheMock =
mock(ApplicationConfigCache.class);
- when(applicationConfigCacheMock.build(metaData))
+ ApacheDubboConfigCache apacheDubboConfigCacheMock =
mock(ApacheDubboConfigCache.class);
+ when(apacheDubboConfigCacheMock.build(metaData))
.thenReturn(new ReferenceConfig());
- assertNotNull(applicationConfigCacheMock.build(metaData));
+ assertNotNull(apacheDubboConfigCacheMock.build(metaData));
}
@Test
public void testInvalidate() {
- this.applicationConfigCache.invalidate("/test");
- this.applicationConfigCache.invalidateAll();
+ this.apacheDubboConfigCache.invalidate("/test");
+ this.apacheDubboConfigCache.invalidateAll();
}
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandlerTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandlerTest.java
similarity index 87%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandlerTest.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandlerTest.java
index ef7f5ac..99cb28b 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandlerTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheAbstractDubboPluginDataHandlerTest.java
@@ -29,15 +29,15 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
/**
- * The Test Case For ApacheDubboPluginDataHandler.
+ * The Test Case For ApacheAbstractDubboPluginDataHandler.
*/
-public final class ApacheDubboPluginDataHandlerTest {
+public final class ApacheAbstractDubboPluginDataHandlerTest {
- private ApacheDubboPluginDataHandler apacheDubboPluginDataHandler;
+ private ApacheAbstractDubboPluginDataHandler apacheDubboPluginDataHandler;
@Before
public void setUp() {
- apacheDubboPluginDataHandler = new ApacheDubboPluginDataHandler();
+ apacheDubboPluginDataHandler = new
ApacheAbstractDubboPluginDataHandler();
}
@Test
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java
index 38920d2..67b6626 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyServiceTest.java
@@ -24,7 +24,7 @@ import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache;
import org.apache.shenyu.plugin.dubbo.common.param.DubboParamResolveService;
import org.junit.After;
import org.junit.Before;
@@ -72,7 +72,7 @@ public final class ApacheDubboProxyServiceTest {
@After
public void after() {
- ApplicationConfigCache.getInstance().invalidateAll();
+ ApacheDubboConfigCache.getInstance().invalidateAll();
}
@Test
@@ -83,10 +83,10 @@ public final class ApacheDubboProxyServiceTest {
when(referenceConfig.getInterface()).thenReturn(PATH);
CompletableFuture<Object> future = new CompletableFuture<>();
when(genericService.$invoke(METHOD_NAME, LEFT,
RIGHT)).thenReturn(future);
- ApplicationConfigCache applicationConfigCache =
ApplicationConfigCache.getInstance();
- Field field = ApplicationConfigCache.class.getDeclaredField("cache");
+ ApacheDubboConfigCache apacheDubboConfigCache =
ApacheDubboConfigCache.getInstance();
+ Field field = ApacheDubboConfigCache.class.getDeclaredField("cache");
field.setAccessible(true);
- ((LoadingCache) field.get(applicationConfigCache)).put(PATH,
referenceConfig);
+ ((LoadingCache) field.get(apacheDubboConfigCache)).put(PATH,
referenceConfig);
ApacheDubboProxyService apacheDubboProxyService = new
ApacheDubboProxyService(new BodyParamResolveServiceImpl());
apacheDubboProxyService.genericInvoker("", metaData, exchange);
future.complete("success");
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
index a4f0e27..4c24651 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/test/java/org/apache/shenyu/plugin/apache/dubbo/subscriber/ApacheDubboMetaDataSubscriberTest.java
@@ -21,7 +21,7 @@ import com.google.common.cache.LoadingCache;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.shenyu.common.dto.MetaData;
import org.apache.shenyu.common.enums.RpcTypeEnum;
-import org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache;
+import org.apache.shenyu.plugin.apache.dubbo.cache.ApacheDubboConfigCache;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -61,10 +61,10 @@ public final class ApacheDubboMetaDataSubscriberTest {
public void testOnSubscribe() throws NoSuchFieldException,
IllegalAccessException {
ReferenceConfig referenceConfig = mock(ReferenceConfig.class);
when(referenceConfig.getInterface()).thenReturn("/dubbo/findAll");
- ApplicationConfigCache applicationConfigCache =
ApplicationConfigCache.getInstance();
- Field field = ApplicationConfigCache.class.getDeclaredField("cache");
+ ApacheDubboConfigCache apacheDubboConfigCache =
ApacheDubboConfigCache.getInstance();
+ Field field = ApacheDubboConfigCache.class.getDeclaredField("cache");
field.setAccessible(true);
- ((LoadingCache)
field.get(applicationConfigCache)).put("/dubbo/findAll", referenceConfig);
+ ((LoadingCache)
field.get(apacheDubboConfigCache)).put("/dubbo/findAll", referenceConfig);
apacheDubboMetaDataSubscriber.onSubscribe(metaData);
MetaData metaData = MetaData.builder()
.id("1332017966661636096")
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/pom.xml
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/pom.xml
index 9619b0a..e4669bf 100644
--- a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/pom.xml
+++ b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/pom.xml
@@ -32,6 +32,11 @@
<version>${project.version}</version>
</dependency>
<dependency>
+ <groupId>org.apache.shenyu</groupId>
+ <artifactId>shenyu-loadbalancer</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/AbstractDubboPlugin.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/AbstractDubboPlugin.java
index 07dc11e..281f75a 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/AbstractDubboPlugin.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/AbstractDubboPlugin.java
@@ -17,12 +17,24 @@
package org.apache.shenyu.plugin.dubbo.common;
+import org.apache.commons.lang3.StringUtils;
import org.apache.shenyu.common.constant.Constants;
+import org.apache.shenyu.common.dto.MetaData;
+import org.apache.shenyu.common.dto.RuleData;
+import org.apache.shenyu.common.dto.SelectorData;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.plugin.api.ShenyuPluginChain;
import org.apache.shenyu.plugin.api.context.ShenyuContext;
+import org.apache.shenyu.plugin.api.result.ShenyuResultEnum;
+import org.apache.shenyu.plugin.api.result.ShenyuResultWrap;
+import org.apache.shenyu.plugin.api.utils.WebFluxResultUtils;
import org.apache.shenyu.plugin.base.AbstractShenyuPlugin;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.http.HttpStatus;
import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Mono;
import java.util.Objects;
@@ -31,6 +43,58 @@ import java.util.Objects;
*/
public abstract class AbstractDubboPlugin extends AbstractShenyuPlugin {
+ private static final Logger LOG =
LoggerFactory.getLogger(AbstractDubboPlugin.class);
+
+ /**
+ * do dubbo invoker.
+ *
+ * @param exchange exchange the current server exchange {@linkplain
ServerWebExchange}
+ * @param chain chain the current chain {@linkplain ServerWebExchange}
+ * @param selector selector {@linkplain SelectorData}
+ * @param rule rule {@linkplain RuleData}
+ * @param metaData the medata
+ * @param param the param
+ * @return {@code Mono<Void>} to indicate when request handling is complete
+ */
+ protected abstract Mono<Void> doDubboInvoker(ServerWebExchange exchange,
+ ShenyuPluginChain chain,
+ SelectorData selector,
+ RuleData rule,
+ MetaData metaData,
+ String param);
+
+ /**
+ * this is Template Method child has Implement your own logic.
+ *
+ * @param exchange exchange the current server exchange {@linkplain
ServerWebExchange}
+ * @param chain chain the current chain {@linkplain ServerWebExchange}
+ * @param selector selector {@linkplain SelectorData}
+ * @param rule rule {@linkplain RuleData}
+ * @return {@code Mono<Void>} to indicate when request handling is complete
+ */
+ @Override
+ public Mono<Void> doExecute(final ServerWebExchange exchange,
+ final ShenyuPluginChain chain,
+ final SelectorData selector,
+ final RuleData rule) {
+ String param = exchange.getAttribute(Constants.PARAM_TRANSFORM);
+ ShenyuContext shenyuContext = exchange.getAttribute(Constants.CONTEXT);
+ assert shenyuContext != null;
+ MetaData metaData = exchange.getAttribute(Constants.META_DATA);
+ if (!checkMetaData(metaData)) {
+ LOG.error(" path is : {}, meta data have error : {}",
shenyuContext.getPath(), metaData);
+
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
+ Object error =
ShenyuResultWrap.error(ShenyuResultEnum.META_DATA_ERROR.getCode(),
ShenyuResultEnum.META_DATA_ERROR.getMsg(), null);
+ return WebFluxResultUtils.result(exchange, error);
+ }
+ if (StringUtils.isNoneBlank(metaData.getParameterTypes()) &&
StringUtils.isBlank(param)) {
+
exchange.getResponse().setStatusCode(HttpStatus.INTERNAL_SERVER_ERROR);
+ Object error =
ShenyuResultWrap.error(ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getCode(),
ShenyuResultEnum.DUBBO_HAVE_BODY_PARAM.getMsg(), null);
+ return WebFluxResultUtils.result(exchange, error);
+ }
+ return this.doDubboInvoker(exchange, chain, selector, rule, metaData,
param);
+ }
+
/**
* return plugin order .
* This attribute To determine the plugin execution order in the same type
plugin.
@@ -67,4 +131,20 @@ public abstract class AbstractDubboPlugin extends
AbstractShenyuPlugin {
assert shenyuContext != null;
return !Objects.equals(shenyuContext.getRpcType(),
RpcTypeEnum.DUBBO.getName());
}
+
+ private boolean checkMetaData(final MetaData metaData) {
+ return Objects.nonNull(metaData)
+ && StringUtils.isNoneBlank(metaData.getMethodName())
+ && StringUtils.isNoneBlank(metaData.getServiceName());
+ }
+
+ @Override
+ protected Mono<Void> handleSelectorIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
+ return WebFluxResultUtils.noSelectorResult(pluginName, exchange);
+ }
+
+ @Override
+ protected Mono<Void> handleRuleIfNull(final String pluginName, final
ServerWebExchange exchange, final ShenyuPluginChain chain) {
+ return WebFluxResultUtils.noRuleResult(pluginName, exchange);
+ }
}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboConfigCache.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboConfigCache.java
new file mode 100644
index 0000000..d2bc56a
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboConfigCache.java
@@ -0,0 +1,36 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.dubbo.common.cache;
+
+import org.apache.shenyu.common.utils.GsonUtils;
+
+/**
+ * DubboConfigCache.
+ */
+public class DubboConfigCache<T extends DubboConfigCache<?>> {
+
+ /**
+ * parser the rpc ext to dubbo param.
+ *
+ * @param rpcExt the rpc ext
+ * @return parsed dubbo param
+ */
+ protected DubboParam parserToDubboParam(final String rpcExt) {
+ return GsonUtils.getInstance().fromJson(rpcExt, DubboParam.class);
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
new file mode 100644
index 0000000..7f9dbbe
--- /dev/null
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/cache/DubboParam.java
@@ -0,0 +1,185 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.shenyu.plugin.dubbo.common.cache;
+
+/**
+ * DubboParam.
+ */
+public class DubboParam {
+
+ /**
+ * the group.
+ */
+ private String group;
+
+ /**
+ * the version.
+ */
+ private String version;
+
+ /**
+ * the loadbalance.
+ */
+ private String loadbalance;
+
+ /**
+ * the retries.
+ */
+ private Integer retries;
+
+ /**
+ * the timeout.
+ */
+ private Integer timeout;
+
+ /**
+ * the url.
+ */
+ private String url;
+
+ /**
+ * the sent.
+ */
+ private Boolean sent;
+
+ /**
+ * Gets group.
+ *
+ * @return the group
+ */
+ public String getGroup() {
+ return group;
+ }
+
+ /**
+ * Sets group.
+ *
+ * @param group the group
+ */
+ public void setGroup(final String group) {
+ this.group = group;
+ }
+
+ /**
+ * Gets version.
+ *
+ * @return the version
+ */
+ public String getVersion() {
+ return version;
+ }
+
+ /**
+ * Sets version.
+ *
+ * @param version the version
+ */
+ public void setVersion(final String version) {
+ this.version = version;
+ }
+
+ /**
+ * Gets loadbalance.
+ *
+ * @return the loadbalance
+ */
+ public String getLoadbalance() {
+ return loadbalance;
+ }
+
+ /**
+ * Sets loadbalance.
+ *
+ * @param loadbalance the loadbalance
+ */
+ public void setLoadbalance(final String loadbalance) {
+ this.loadbalance = loadbalance;
+ }
+
+ /**
+ * Gets retries.
+ *
+ * @return the retries
+ */
+ public Integer getRetries() {
+ return retries;
+ }
+
+ /**
+ * Sets retries.
+ *
+ * @param retries the retries
+ */
+ public void setRetries(final Integer retries) {
+ this.retries = retries;
+ }
+
+ /**
+ * Gets timeout.
+ *
+ * @return the timeout
+ */
+ public Integer getTimeout() {
+ return timeout;
+ }
+
+ /**
+ * Sets timeout.
+ *
+ * @param timeout the timeout
+ */
+ public void setTimeout(final Integer timeout) {
+ this.timeout = timeout;
+ }
+
+ /**
+ * Gets url.
+ *
+ * @return the url
+ */
+ public String getUrl() {
+ return url;
+ }
+
+ /**
+ * Sets url.
+ *
+ * @param url the url
+ */
+ public void setUrl(final String url) {
+ this.url = url;
+ }
+
+ /**
+ * Gets sent.
+ *
+ * @return the sent
+ */
+ public Boolean getSent() {
+ return sent;
+ }
+
+ /**
+ * Sets sent.
+ *
+ * @param sent the sent
+ */
+ public void setSent(final Boolean sent) {
+ this.sent = sent;
+ }
+}
diff --git
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
similarity index 91%
rename from
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java
rename to
shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
index 41baa6a..0bc1637 100644
---
a/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/handler/ApacheDubboPluginDataHandler.java
+++
b/shenyu-plugin/shenyu-plugin-dubbo/shenyu-plugin-dubbo-common/src/main/java/org/apache/shenyu/plugin/dubbo/common/handler/AbstractDubboPluginDataHandler.java
@@ -15,14 +15,14 @@
* limitations under the License.
*/
-package org.apache.shenyu.plugin.apache.dubbo.handler;
+package org.apache.shenyu.plugin.dubbo.common.handler;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
-import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.PluginData;
import org.apache.shenyu.common.dto.RuleData;
import org.apache.shenyu.common.dto.SelectorData;
+import org.apache.shenyu.common.dto.convert.plugin.DubboRegisterConfig;
import org.apache.shenyu.common.dto.convert.rule.impl.DubboRuleHandle;
import org.apache.shenyu.common.dto.convert.selector.DubboUpstream;
import org.apache.shenyu.common.enums.PluginEnum;
@@ -30,7 +30,6 @@ import org.apache.shenyu.common.utils.GsonUtils;
import org.apache.shenyu.common.utils.Singleton;
import org.apache.shenyu.loadbalancer.cache.UpstreamCacheManager;
import org.apache.shenyu.loadbalancer.entity.Upstream;
-import org.apache.shenyu.plugin.apache.dubbo.cache.ApplicationConfigCache;
import org.apache.shenyu.plugin.base.cache.CommonHandleCache;
import org.apache.shenyu.plugin.base.handler.PluginDataHandler;
import org.apache.shenyu.plugin.base.utils.BeanHolder;
@@ -42,17 +41,19 @@ import java.util.function.Supplier;
import java.util.stream.Collectors;
/**
- * The type Apache dubbo plugin data handler.
+ * The common dubbo plugin data handler.
*/
-public class ApacheDubboPluginDataHandler implements PluginDataHandler {
+public abstract class AbstractDubboPluginDataHandler implements
PluginDataHandler {
public static final Supplier<CommonHandleCache<String, DubboRuleHandle>>
RULE_CACHED_HANDLE = new BeanHolder<>(CommonHandleCache::new);
public static final Supplier<CommonHandleCache<String,
List<DubboUpstream>>> SELECTOR_CACHED_HANDLE = new
BeanHolder<>(CommonHandleCache::new);
+ protected abstract void initConfigCache(DubboRegisterConfig
dubboRegisterConfig);
+
@Override
public void handlerPlugin(final PluginData pluginData) {
- if (null != pluginData && pluginData.getEnabled()) {
+ if (Objects.nonNull(pluginData) && pluginData.getEnabled()) {
DubboRegisterConfig dubboRegisterConfig =
GsonUtils.getInstance().fromJson(pluginData.getConfig(),
DubboRegisterConfig.class);
DubboRegisterConfig exist =
Singleton.INST.get(DubboRegisterConfig.class);
if (Objects.isNull(dubboRegisterConfig)) {
@@ -60,8 +61,7 @@ public class ApacheDubboPluginDataHandler implements
PluginDataHandler {
}
if (Objects.isNull(exist) || !dubboRegisterConfig.equals(exist)) {
// If it is null, initialize it
- ApplicationConfigCache.getInstance().init(dubboRegisterConfig);
- ApplicationConfigCache.getInstance().invalidateAll();
+ this.initConfigCache(dubboRegisterConfig);
}
Singleton.INST.single(DubboRegisterConfig.class,
dubboRegisterConfig);
}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo
[...]
index dd52b7e..5adb7d2 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfiguration.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.plugin.alibaba.dubbo;
import org.apache.shenyu.plugin.alibaba.dubbo.AlibabaDubboPlugin;
-import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaAbstractDubboPluginDataHandler;
import org.apache.shenyu.plugin.alibaba.dubbo.proxy.AlibabaDubboProxyService;
import
org.apache.shenyu.plugin.alibaba.dubbo.subscriber.AlibabaDubboMetaDataSubscriber;
import org.apache.shenyu.plugin.api.ShenyuPlugin;
@@ -58,7 +58,7 @@ public class AlibabaDubboPluginConfiguration {
*/
@Bean
public PluginDataHandler alibabaDubboPluginDataHandler() {
- return new AlibabaDubboPluginDataHandler();
+ return new AlibabaAbstractDubboPluginDataHandler();
}
/**
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfigurationTest.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/alibaba/d
[...]
index b3f33ba..d8f056d 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfigurationTest.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-alibaba-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/alibaba/dubbo/AlibabaDubboPluginConfigurationTest.java
@@ -19,7 +19,7 @@ package
org.apache.shenyu.springboot.starter.plugin.alibaba.dubbo;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.plugin.alibaba.dubbo.AlibabaDubboPlugin;
-import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.alibaba.dubbo.handler.AlibabaAbstractDubboPluginDataHandler;
import
org.apache.shenyu.plugin.alibaba.dubbo.subscriber.AlibabaDubboMetaDataSubscriber;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,7 +50,7 @@ public final class AlibabaDubboPluginConfigurationTest {
private AlibabaDubboPlugin alibabaDubboPlugin;
@Autowired(required = false)
- private AlibabaDubboPluginDataHandler alibabaDubboPluginDataHandler;
+ private AlibabaAbstractDubboPluginDataHandler
alibabaDubboPluginDataHandler;
@Autowired(required = false)
private AlibabaDubboMetaDataSubscriber alibabaDubboMetaDataSubscriber;
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/Apac
[...]
index 3e2df95..ef5d896 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfiguration.java
@@ -18,7 +18,7 @@
package org.apache.shenyu.springboot.starter.plugin.apache.dubbo;
import org.apache.shenyu.plugin.apache.dubbo.ApacheDubboPlugin;
-import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheAbstractDubboPluginDataHandler;
import org.apache.shenyu.plugin.apache.dubbo.proxy.ApacheDubboProxyService;
import
org.apache.shenyu.plugin.apache.dubbo.subscriber.ApacheDubboMetaDataSubscriber;
import org.apache.shenyu.plugin.api.ShenyuPlugin;
@@ -58,7 +58,7 @@ public class ApacheDubboPluginConfiguration {
*/
@Bean
public PluginDataHandler apacheDubboPluginDataHandler() {
- return new ApacheDubboPluginDataHandler();
+ return new ApacheAbstractDubboPluginDataHandler();
}
/**
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfigurationTest.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/
[...]
index 65829dc..615c20b 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfigurationTest.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-plugin/shenyu-spring-boot-starter-plugin-dubbo/shenyu-spring-boot-starter-plugin-apache-dubbo/src/test/java/org/apache/shenyu/springboot/starter/plugin/apache/dubbo/ApacheDubboPluginConfigurationTest.java
@@ -19,7 +19,7 @@ package
org.apache.shenyu.springboot.starter.plugin.apache.dubbo;
import org.apache.shenyu.common.enums.PluginEnum;
import org.apache.shenyu.plugin.apache.dubbo.ApacheDubboPlugin;
-import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheDubboPluginDataHandler;
+import
org.apache.shenyu.plugin.apache.dubbo.handler.ApacheAbstractDubboPluginDataHandler;
import
org.apache.shenyu.plugin.apache.dubbo.subscriber.ApacheDubboMetaDataSubscriber;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -50,7 +50,7 @@ public final class ApacheDubboPluginConfigurationTest {
private ApacheDubboPlugin apacheDubboPlugin;
@Autowired(required = false)
- private ApacheDubboPluginDataHandler apacheDubboPluginDataHandler;
+ private ApacheAbstractDubboPluginDataHandler apacheDubboPluginDataHandler;
@Autowired(required = false)
private ApacheDubboMetaDataSubscriber apacheDubboMetaDataSubscriber;