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/shenyu.git
The following commit(s) were added to refs/heads/master by this push:
new fe8f232ad [ISSUE #3839] fill metadata as much as possible (#3840)
fe8f232ad is described below
commit fe8f232ad1b055f973296cd3571b74abb9c85ae4
Author: dragon-zhang <[email protected]>
AuthorDate: Sat Aug 13 10:20:27 2022 +0800
[ISSUE #3839] fill metadata as much as possible (#3840)
---
.../springcloud/init/SpringCloudClientEventListener.java | 16 +++++++++++++---
.../springmvc/init/SpringMvcClientEventListener.java | 16 +++++++++++++---
2 files changed, 26 insertions(+), 6 deletions(-)
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java
index 9b40e686c..60dd37c77 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientEventListener.java
@@ -45,11 +45,13 @@ import
org.springframework.web.bind.annotation.RequestMapping;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
+import java.util.stream.Collectors;
/**
* The type Spring cloud client event listener.
@@ -124,7 +126,7 @@ public class SpringCloudClientEventListener implements
ApplicationListener<Conte
final String superPath = buildApiSuperPath(clazz, beanShenyuClient);
// Compatible with previous versions
if (Objects.nonNull(beanShenyuClient) && superPath.contains("*")) {
- publisher.publishEvent(buildMetaDataDTO(beanShenyuClient,
pathJoin(contextPath, superPath)));
+ publisher.publishEvent(buildMetaDataDTO(beanShenyuClient,
pathJoin(contextPath, superPath), clazz, null));
return;
}
final Method[] methods =
ReflectionUtils.getUniqueDeclaredMethods(clazz);
@@ -135,7 +137,7 @@ public class SpringCloudClientEventListener implements
ApplicationListener<Conte
// the result of ReflectionUtils#getUniqueDeclaredMethods contains
methods such as hashCode, wait, toSting
// add Objects.nonNull(requestMapping) to make sure not register
wrong method
if (Objects.nonNull(methodShenyuClient) &&
Objects.nonNull(requestMapping)) {
- publisher.publishEvent(buildMetaDataDTO(methodShenyuClient,
buildApiPath(method, superPath, methodShenyuClient)));
+ publisher.publishEvent(buildMetaDataDTO(methodShenyuClient,
buildApiPath(method, superPath, methodShenyuClient), clazz, method));
}
}
}
@@ -202,7 +204,8 @@ public class SpringCloudClientEventListener implements
ApplicationListener<Conte
return result.toString();
}
- private MetaDataRegisterDTO buildMetaDataDTO(final ShenyuSpringCloudClient
shenyuSpringCloudClient, final String path) {
+ private MetaDataRegisterDTO buildMetaDataDTO(final ShenyuSpringCloudClient
shenyuSpringCloudClient,
+ final String path, final
Class<?> clazz, final Method method) {
String appName = env.getProperty("spring.application.name");
String desc = shenyuSpringCloudClient.desc();
String configRuleName = shenyuSpringCloudClient.ruleName();
@@ -210,8 +213,15 @@ public class SpringCloudClientEventListener implements
ApplicationListener<Conte
return MetaDataRegisterDTO.builder()
.contextPath(StringUtils.defaultIfBlank(this.contextPath,
this.servletContextPath))
.appName(appName)
+ .serviceName(clazz.getName())
+
.methodName(Optional.ofNullable(method).map(Method::getName).orElse(null))
.path(path)
.pathDesc(desc)
+ .parameterTypes(Optional.ofNullable(method)
+ .map(m -> Arrays.stream(m.getParameterTypes())
+ .map(Class::getName)
+ .collect(Collectors.joining(","))
+ ).orElse(null))
.rpcType(RpcTypeEnum.SPRING_CLOUD.getName())
.enabled(shenyuSpringCloudClient.enabled())
.ruleName(ruleName)
diff --git
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java
index 360476384..532e1fb89 100644
---
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java
+++
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientEventListener.java
@@ -49,11 +49,13 @@ import
org.springframework.web.bind.annotation.RequestMapping;
import java.lang.annotation.Annotation;
import java.lang.reflect.Method;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Map;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Properties;
+import java.util.stream.Collectors;
/**
* The type Shenyu spring mvc client event listener.
@@ -126,7 +128,7 @@ public class SpringMvcClientEventListener implements
ApplicationListener<Context
final String superPath = buildApiSuperPath(clazz);
// Compatible with previous versions
if (Objects.nonNull(beanShenyuClient) && superPath.contains("*")) {
- publisher.publishEvent(buildMetaDataDTO(beanShenyuClient,
pathJoin(contextPath, superPath)));
+ publisher.publishEvent(buildMetaDataDTO(beanShenyuClient,
pathJoin(contextPath, superPath), clazz, null));
return;
}
final Method[] methods =
ReflectionUtils.getUniqueDeclaredMethods(clazz);
@@ -137,7 +139,7 @@ public class SpringMvcClientEventListener implements
ApplicationListener<Context
// the result of ReflectionUtils#getUniqueDeclaredMethods contains
method such as hashCode, wait, toSting
// add Objects.nonNull(requestMapping) to make sure not register
wrong method
if (Objects.nonNull(methodShenyuClient) &&
Objects.nonNull(requestMapping)) {
- publisher.publishEvent(buildMetaDataDTO(methodShenyuClient,
buildApiPath(method, superPath)));
+ publisher.publishEvent(buildMetaDataDTO(methodShenyuClient,
buildApiPath(method, superPath), clazz, method));
}
}
}
@@ -205,12 +207,20 @@ public class SpringMvcClientEventListener implements
ApplicationListener<Context
return result.toString();
}
- private MetaDataRegisterDTO buildMetaDataDTO(@NonNull final
ShenyuSpringMvcClient shenyuSpringMvcClient, final String path) {
+ private MetaDataRegisterDTO buildMetaDataDTO(@NonNull final
ShenyuSpringMvcClient shenyuSpringMvcClient,
+ final String path, final
Class<?> clazz, final Method method) {
return MetaDataRegisterDTO.builder()
.contextPath(contextPath)
.appName(appName)
+ .serviceName(clazz.getName())
+
.methodName(Optional.ofNullable(method).map(Method::getName).orElse(null))
.path(path)
.pathDesc(shenyuSpringMvcClient.desc())
+ .parameterTypes(Optional.ofNullable(method)
+ .map(m -> Arrays.stream(m.getParameterTypes())
+ .map(Class::getName)
+ .collect(Collectors.joining(","))
+ ).orElse(null))
.rpcType(RpcTypeEnum.HTTP.getName())
.enabled(shenyuSpringMvcClient.enabled())
.ruleName(StringUtils.defaultIfBlank(shenyuSpringMvcClient.ruleName(), path))