This is an automated email from the ASF dual-hosted git repository.
zhangzicheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new 10375c520 [Task]add client duplicate jar check (#4156) (#4240)
10375c520 is described below
commit 10375c5204c67f9889235f19fe2d6e8eb0438a5a
Author: mahaitao <[email protected]>
AuthorDate: Sat Dec 10 20:43:52 2022 +0800
[Task]add client duplicate jar check (#4156) (#4240)
* feat:add client duplicate jar check
* feat:add note
* feat:fix
Co-authored-by: mahaitao617 <[email protected]>
Co-authored-by: mahaitao617 <[email protected]>
Co-authored-by: dragon-zhang <[email protected]>
---
.../apache/shenyu/common/utils/VersionUtils.java | 45 ++++++++++++++++++++++
.../dubbo/proxy/ApacheDubboProxyService.java | 2 +-
.../ShenyuAlibabaDubboClientConfiguration.java | 7 +++-
.../ShenyuApacheDubboClientConfiguration.java | 7 +++-
.../client/grpc/ShenyuGrpcClientConfiguration.java | 7 +++-
.../motan/ShenyuMotanClientConfiguration.java | 5 +++
.../client/sofa/ShenyuSofaClientConfiguration.java | 5 +++
.../ShenyuSpringWebSocketClientConfiguration.java | 5 +++
.../ShenyuSpringCloudClientConfiguration.java | 7 +++-
.../ShenyuSpringMvcClientConfiguration.java | 5 +++
.../client/tars/ShenyuTarsClientConfiguration.java | 5 +++
11 files changed, 95 insertions(+), 5 deletions(-)
diff --git
a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/VersionUtils.java
b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/VersionUtils.java
index 6d2c4fe05..c3ce365db 100644
---
a/shenyu-common/src/main/java/org/apache/shenyu/common/utils/VersionUtils.java
+++
b/shenyu-common/src/main/java/org/apache/shenyu/common/utils/VersionUtils.java
@@ -17,6 +17,11 @@
package org.apache.shenyu.common.utils;
+import java.io.IOException;
+import java.net.URL;
+import java.util.Enumeration;
+import java.util.HashSet;
+import java.util.Set;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -95,6 +100,46 @@ public final class VersionUtils {
// return default version if no version info is found
return StringUtils.isBlank(version) ? defaultVersion : version;
}
+
+ /**
+ * checkDuplicate,this method refers to the design of
dubbo,url:https://dubbo.apache.org/zh/docs/v2.7/dev/principals/dummy/ .
+ * @param cls cls
+ */
+ public static void checkDuplicate(final Class<?> cls) {
+ try {
+ String path = cls.getName().replace('.', '/') + ".class";
+ Set<String> files = readResources(path, cls);
+ // duplicated jar is found
+ if (files.size() > 1) {
+ String error = "Duplicate class " + path + " in " +
files.size() + " jar " + files;
+ LOG.error("checkDuplicate error,{}", error);
+ }
+ } catch (Throwable e) {
+ LOG.error("checkDuplicate error,msg={},e={}", e.getMessage(), e);
+ }
+ }
+
+ /**
+ * readResources.
+ * @param path path
+ * @param cls cls
+ * @return set
+ * @throws IOException ioexception
+ */
+ private static Set<String> readResources(final String path, final Class<?>
cls) throws IOException {
+ Enumeration<URL> urls = cls.getClassLoader().getResources(path);
+ Set<String> files = new HashSet<String>();
+ while (urls.hasMoreElements()) {
+ URL url = urls.nextElement();
+ if (url != null) {
+ String file = url.getFile();
+ if (StringUtils.isNotEmpty(file)) {
+ files.add(file);
+ }
+ }
+ }
+ return files;
+ }
}
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 b2f2ec82d..334ed5744 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
@@ -64,7 +64,7 @@ public class ApacheDubboProxyService {
*/
public Mono<Object> genericInvoker(final String body, final MetaData
metaData, final ServerWebExchange exchange) throws ShenyuException {
ReferenceConfig<GenericService> reference =
ApacheDubboConfigCache.getInstance().get(metaData.getPath());
- if (Objects.isNull(reference) ||
StringUtils.isEmpty(reference.getInterface())) {
+ if (StringUtils.isEmpty(reference.getInterface())) {
ApacheDubboConfigCache.getInstance().invalidate(metaData.getPath());
reference = ApacheDubboConfigCache.getInstance().initRef(metaData);
}
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/alibaba/dubbo/ShenyuAlibabaDubboClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/alibaba/dubbo/ShenyuAlibabaDubboClientConfiguration.java
index 08427b110..acf66a244 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/alibaba/dubbo/ShenyuAlibabaDubboClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-alibaba-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/alibaba/dubbo/ShenyuAlibabaDubboClientConfiguration.java
@@ -19,6 +19,7 @@ package
org.apache.shenyu.springboot.starter.client.alibaba.dubbo;
import org.apache.shenyu.client.alibaba.dubbo.AlibabaDubboServiceBeanListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -34,7 +35,11 @@ import org.springframework.context.annotation.Configuration;
@ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class)
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuAlibabaDubboClientConfiguration {
-
+
+ static {
+
VersionUtils.checkDuplicate(ShenyuAlibabaDubboClientConfiguration.class);
+ }
+
/**
* Alibaba dubbo service bean listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java
index 7198dd915..2e6d9c17e 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-apache-dubbo/src/main/java/org/apache/shenyu/springboot/starter/client/apache/dubbo/ShenyuApacheDubboClientConfiguration.java
@@ -19,6 +19,7 @@ package
org.apache.shenyu.springboot.starter.client.apache.dubbo;
import org.apache.shenyu.client.apache.dubbo.ApacheDubboServiceBeanListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -34,7 +35,11 @@ import org.springframework.context.annotation.Configuration;
@ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class)
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuApacheDubboClientConfiguration {
-
+
+ static {
+
VersionUtils.checkDuplicate(ShenyuApacheDubboClientConfiguration.class);
+ }
+
/**
* Apache dubbo service bean listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java
index 2b9e511a5..fe170d64e 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-grpc/src/main/java/org/apache/springboot/starter/client/grpc/ShenyuGrpcClientConfiguration.java
@@ -21,6 +21,7 @@ import org.apache.shenyu.client.grpc.GrpcClientEventListener;
import org.apache.shenyu.client.grpc.server.GrpcServerBuilder;
import org.apache.shenyu.client.grpc.server.GrpcServerRunner;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -36,7 +37,11 @@ import org.springframework.context.annotation.Configuration;
@ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class)
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuGrpcClientConfiguration {
-
+
+ static {
+ VersionUtils.checkDuplicate(ShenyuGrpcClientConfiguration.class);
+ }
+
/**
* Grpc client event listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
index 34dc950d2..3aea1514a 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-motan/src/main/java/org/apache/shenyu/springboot/starter/client/motan/ShenyuMotanClientConfiguration.java
@@ -25,6 +25,7 @@ import
com.weibo.api.motan.config.springsupport.RegistryConfigBean;
import com.weibo.api.motan.util.MotanSwitcherUtil;
import org.apache.shenyu.client.motan.MotanServiceEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -47,6 +48,10 @@ import
org.springframework.context.event.ContextRefreshedEvent;
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuMotanClientConfiguration implements
ApplicationListener<ContextRefreshedEvent> {
+ static {
+ VersionUtils.checkDuplicate(ShenyuMotanClientConfiguration.class);
+ }
+
/**
* Motan service event listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
index 75020aa1d..7d2502113 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-sofa/src/main/java/org/apache/shenyu/springboot/starter/client/sofa/ShenyuSofaClientConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.springboot.starter.client.sofa;
import org.apache.shenyu.client.sofa.SofaServiceEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -35,6 +36,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuSofaClientConfiguration {
+ static {
+ VersionUtils.checkDuplicate(ShenyuSofaClientConfiguration.class);
+ }
+
/**
* Sofa service event listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
index 8a4af17ec..1627fa617 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-spring-websocket/src/main/java/org/apache/shenyu/springboot/starter/client/spring/websocket/ShenyuSpringWebSocketClientConfiguration.java
@@ -19,6 +19,7 @@ package
org.apache.shenyu.springboot.starter.client.spring.websocket;
import
org.apache.shenyu.client.spring.websocket.init.SpringWebSocketClientEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -35,6 +36,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuSpringWebSocketClientConfiguration {
+ static {
+
VersionUtils.checkDuplicate(ShenyuSpringWebSocketClientConfiguration.class);
+ }
+
/**
* Spring web socket client event listener.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springcloud/src/main/java/org/apache/shenyu/springboot/starter/client/springcloud/ShenyuSpringCloudClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springcloud/src/main/java/org/apache/shenyu/springboot/starter/client/springcloud/ShenyuSpringCloudClientConfiguration.java
index d8d57f776..a70609031 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springcloud/src/main/java/org/apache/shenyu/springboot/starter/client/springcloud/ShenyuSpringCloudClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springcloud/src/main/java/org/apache/shenyu/springboot/starter/client/springcloud/ShenyuSpringCloudClientConfiguration.java
@@ -19,6 +19,7 @@ package
org.apache.shenyu.springboot.starter.client.springcloud;
import
org.apache.shenyu.client.springcloud.init.SpringCloudClientEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -35,7 +36,11 @@ import
org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
@ImportAutoConfiguration(ShenyuClientCommonBeanConfiguration.class)
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuSpringCloudClientConfiguration {
-
+
+ static {
+
VersionUtils.checkDuplicate(ShenyuSpringCloudClientConfiguration.class);
+ }
+
/**
* Spring cloud client bean post processor.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcClientConfiguration.java
index aa68ea495..b0ad2c696 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-springmvc/src/main/java/org/apache/shenyu/springboot/starter/client/springmvc/ShenyuSpringMvcClientConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.springboot.starter.client.springmvc;
import org.apache.shenyu.client.springmvc.init.SpringMvcClientEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -35,6 +36,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuSpringMvcClientConfiguration {
+ static {
+ VersionUtils.checkDuplicate(ShenyuSpringMvcClientConfiguration.class);
+ }
+
/**
* Spring mvc client bean post processor.
*
diff --git
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-tars/src/main/java/org/apache/shenyu/springboot/starter/client/tars/ShenyuTarsClientConfiguration.java
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-tars/src/main/java/org/apache/shenyu/springboot/starter/client/tars/ShenyuTarsClientConfiguration.java
index 8bbf5a060..830acadae 100644
---
a/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-tars/src/main/java/org/apache/shenyu/springboot/starter/client/tars/ShenyuTarsClientConfiguration.java
+++
b/shenyu-spring-boot-starter/shenyu-spring-boot-starter-client/shenyu-spring-boot-starter-client-tars/src/main/java/org/apache/shenyu/springboot/starter/client/tars/ShenyuTarsClientConfiguration.java
@@ -19,6 +19,7 @@ package org.apache.shenyu.springboot.starter.client.tars;
import org.apache.shenyu.client.tars.TarsServiceBeanEventListener;
import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.VersionUtils;
import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
import org.apache.shenyu.register.common.config.ShenyuClientConfig;
import
org.apache.shenyu.springboot.starter.client.common.config.ShenyuClientCommonBeanConfiguration;
@@ -35,6 +36,10 @@ import org.springframework.context.annotation.Configuration;
@ConditionalOnProperty(value = "shenyu.register.enabled", matchIfMissing =
true, havingValue = "true")
public class ShenyuTarsClientConfiguration {
+ static {
+ VersionUtils.checkDuplicate(ShenyuTarsClientConfiguration.class);
+ }
+
/**
* Tars service bean post processor.
*