Copilot commented on code in PR #5953: URL: https://github.com/apache/shenyu/pull/5953#discussion_r2044880619
########## shenyu-plugin/shenyu-plugin-proxy/shenyu-plugin-rpc/shenyu-plugin-dubbo/shenyu-plugin-apache-dubbo/src/main/java/org/apache/shenyu/plugin/apache/dubbo/proxy/ApacheDubboProxyService.java: ########## @@ -103,4 +108,80 @@ private CompletableFuture<Object> invokeAsync(final GenericService genericServic Object resultFromFuture = RpcContext.getContext().getFuture(); return resultFromFuture instanceof CompletableFuture ? (CompletableFuture<Object>) resultFromFuture : CompletableFuture.completedFuture(resultFromFuture); } + + /** + * get dubbo reference config. + * + * @param selectorData the selector data + * @param ruleData the rule data + * @param metaData the meta data + * @param exchange the webExchange + * @return dubbo reference config + */ + private ReferenceConfig<GenericService> getReferenceConfig(final SelectorData selectorData, final RuleData ruleData, final MetaData metaData, final ServerWebExchange exchange) { + String referenceKey = metaData.getPath(); + String namespace = ""; + if (CollectionUtils.isNotEmpty(exchange.getRequest().getHeaders().get(Constants.NAMESPACE))) { + namespace = exchange.getRequest().getHeaders().get(Constants.NAMESPACE).get(0); + } + + List<DubboUpstream> dubboUpstreams = GsonUtils.getInstance().fromList(selectorData.getHandle(), DubboUpstream.class); + dubboUpstreams = CollectionUtils.isEmpty(dubboUpstreams) ? null + : dubboUpstreams.stream().filter(u -> u.isStatus() && StringUtils.isNotBlank(u.getRegistry())).collect(Collectors.toList()); + // if dubboUpstreams is empty, use default plugin config + if (CollectionUtils.isEmpty(dubboUpstreams)) { + referenceKey = StringUtils.isNotBlank(namespace) ? namespace + ":" + referenceKey : referenceKey; + ReferenceConfig<GenericService> reference = ApacheDubboConfigCache.getInstance().get(referenceKey); + if (StringUtils.isEmpty(reference.getInterface())) { + ApacheDubboConfigCache.getInstance().invalidate(referenceKey); + reference = ApacheDubboConfigCache.getInstance().initRefN(metaData, namespace); + } + return reference; + } + + List<Upstream> upstreams = this.convertUpstreamList(dubboUpstreams); + String ip = Objects.requireNonNull(exchange.getRequest().getRemoteAddress()).getAddress().getHostAddress(); + Upstream upstream = LoadBalancerFactory.selector(upstreams, LoadBalanceEnum.RANDOM.getName(), ip); + DubboUpstream dubboUpstream = null; + for (DubboUpstream upstreamItem : dubboUpstreams) { + if (Objects.equals(upstreamItem.getRegistry(), upstreamItem.getRegistry()) Review Comment: Self-comparison of 'upstreamItem.getRegistry()' is detected. It is likely intended to compare 'upstreamItem.getRegistry()' with 'upstream.getRegistry()'. ```suggestion if (Objects.equals(upstreamItem.getRegistry(), upstream.getRegistry()) ``` -- 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: notifications-unsubscr...@shenyu.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org