dragon-zhang opened a new issue, #3414:
URL: https://github.com/apache/incubator-shenyu/issues/3414
### Question
In `org.apache.shenyu.client.motan.MotanServiceBeanPostProcessor#handler`,
we use
`org.apache.shenyu.client.motan.MotanServiceBeanPostProcessor#buildRpcExt(java.lang.reflect.Method[],
java.lang.Integer)` to build `metadata`, I think this leads to the redundancy
of the `metadata`.
Below is the current code in `MotanServiceBeanPostProcessor`:
```java
private void handler(final Object bean) {
if (group == null) {
group = ((BasicServiceConfigBean)
applicationContext.getBean(BASE_SERVICE_CONFIG)).getGroup();
}
timeout = Optional.ofNullable(((BasicServiceConfigBean)
applicationContext.getBean(BASE_SERVICE_CONFIG)).getRequestTimeout()).orElse(1000);
Class<?> clazz = bean.getClass();
if (AopUtils.isAopProxy(bean)) {
clazz = AopUtils.getTargetClass(bean);
}
Method[] methods = ReflectionUtils.getUniqueDeclaredMethods(clazz);
MotanService service = clazz.getAnnotation(MotanService.class);
for (Method method : methods) {
ShenyuMotanClient shenyuMotanClient =
method.getAnnotation(ShenyuMotanClient.class);
if (Objects.nonNull(shenyuMotanClient)) {
publisher.publishEvent(buildMetaDataDTO(clazz, service,
//here, when build rpcExt, I think we should only use one "method" rather
than "methods"
shenyuMotanClient, method, buildRpcExt(methods,
timeout)));
}
}
}
private String buildRpcExt(final Method[] methods, final Integer
timeout) {
List<MotanRpcExt.RpcExt> list = new ArrayList<>();
for (Method method : methods) {
ShenyuMotanClient shenyuMotanClient =
method.getAnnotation(ShenyuMotanClient.class);
if (Objects.nonNull(shenyuMotanClient)) {
list.add(buildRpcExt(method));
}
}
MotanRpcExt buildList = new MotanRpcExt(list, group, timeout);
return GsonUtils.getInstance().toJson(buildList);
}
```
And in `org.apache.shenyu.plugin.motan.cache.ApplicationConfigCache#build`,
we should not use `forEach`:
```java
public RefererConfig<CommonHandler> build(final MetaData metaData) {
if (Objects.isNull(protocolConfig) ||
Objects.isNull(registryConfig)) {
return new RefererConfig<>();
}
RefererConfig<CommonHandler> reference = new RefererConfig<>();
reference.setInterface(CommonHandler.class);
reference.setServiceInterface(metaData.getServiceName());
// the group of motan rpc call
MotanParamExtInfo motanParamExtInfo =
GsonUtils.getInstance().fromJson(metaData.getRpcExt(),
MotanParamExtInfo.class);
//here we should not use "forEach"
motanParamExtInfo.getMethodInfo().forEach(methodInfo -> {
if (CollectionUtils.isNotEmpty(methodInfo.getParams())) {
try {
Class<?>[] paramTypes = new
Class[methodInfo.getParams().size()];
String[] paramNames = new
String[methodInfo.getParams().size()];
for (int i = 0; i < methodInfo.getParams().size(); i++) {
Pair<String, String> pair =
methodInfo.getParams().get(i);
paramTypes[i] =
PrxInfoUtil.getParamClass(pair.getKey());
paramNames[i] = pair.getValue();
PARAM_MAP.put(methodInfo.getMethodName(), new
MotanParamInfo(paramTypes, paramNames));
}
} catch (Exception e) {
LOG.error("failed to init motan, {}", e.getMessage());
}
}
});
reference.setGroup(motanParamExtInfo.getGroup());
reference.setVersion("1.0");
reference.setRequestTimeout(Optional.ofNullable(motanParamExtInfo.getTimeout()).orElse(1000));
reference.setRegistry(registryConfig);
reference.setProtocol(protocolConfig);
CommonHandler obj = reference.getRef();
if (Objects.nonNull(obj)) {
LOG.info("init motan reference success there meteData is :{}",
metaData);
cache.put(metaData.getPath(), reference);
}
return reference;
}
```
Similar problems also exist in `tars`, are these bugs ?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]