Copilot commented on code in PR #10:
URL: https://github.com/apache/shenyu-client-java/pull/10#discussion_r3458462184


##########
.github/workflows/ci.yml:
##########
@@ -24,57 +24,44 @@ on:
 jobs:
   build:
     strategy:
+      fail-fast: false
       matrix:
-        java: [ 8, 11, 17 ]
+        java: [ 8, 17, 21, 23, 25 ]
         os: [ ubuntu-latest ]
     runs-on: ${{ matrix.os }}
     if: (github.repository == 'apache/shenyu-client-java')
     steps:
       - name: Support longpaths
         if: ${{ matrix.os == 'windows-latest'}}
         run: git config --system core.longpaths true
-      - uses: actions/checkout@v3
+      - uses: actions/checkout@v4
         with:
           submodules: true
 #      - uses: dorny/paths-filter@v2
 #        id: filter
 #        with:
 #          filters: '.github/filters.yml'
 #          list-files: json
-      - name: Restore ShenYu Maven Repos
-#        if: steps.filter.outputs.changed == 'true'
-        id: restore-maven-cache
-        uses: actions/cache/restore@v3
-        with:
-          path: ~/.m2/repository
-          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
-          restore-keys: |
-            ${{ runner.os }}-maven-
-      - uses: actions/setup-java@v1
+      - uses: actions/setup-java@v4
 #        if: steps.filter.outputs.changed == 'true'
         with:
+          distribution: temurin
           java-version: ${{ matrix.java }}
+          cache: maven
       - name: Build with Maven
 #        if: steps.filter.outputs.changed == 'true'
-        run: ./mvnw -B clean test -Prelease
-      - uses: codecov/codecov-action@v1
+        run: ./mvnw -B clean test
+      - uses: codecov/codecov-action@v4
         with:
           token: 2760af6a-3405-4882-9e61-04c5176fecfa

Review Comment:
   The Codecov token is committed directly in the workflow, which is a secret 
leakage risk and makes rotation difficult. Store it as a 
repository/organization secret (e.g., `secrets.CODECOV_TOKEN`) and reference it 
from the workflow instead of hardcoding.



##########
shenyu-client-core/src/main/java/org/apache/shenyu/client/core/register/InstanceRegisterListener.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.client.core.register;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.client.core.dto.DiscoveryUpstreamData;
+import org.apache.shenyu.client.core.register.config.ShenyuDiscoveryConfig;
+import org.apache.shenyu.registry.api.ShenyuInstanceRegisterRepository;
+import org.apache.shenyu.registry.api.config.RegisterConfig;
+import org.apache.shenyu.registry.api.entity.InstanceEntity;
+import org.apache.shenyu.spi.ExtensionLoader;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.context.ApplicationListener;
+import org.springframework.context.event.ContextRefreshedEvent;
+import org.springframework.core.Ordered;
+
+import java.net.URI;
+import java.util.Objects;
+import java.util.Optional;
+import java.util.Properties;
+
+/**
+ * Instance register listener.
+ */
+public class InstanceRegisterListener implements 
ApplicationListener<ContextRefreshedEvent>, Ordered {
+
+    private static final Logger LOGGER = 
LoggerFactory.getLogger(InstanceRegisterListener.class);
+
+    private final DiscoveryUpstreamData currentInstanceUpstream;
+
+    private final RegisterConfig discoveryConfig;
+
+    private final String path;
+
+    private ShenyuInstanceRegisterRepository discoveryService;
+
+    public InstanceRegisterListener(final DiscoveryUpstreamData 
discoveryUpstream, final ShenyuDiscoveryConfig shenyuDiscoveryConfig) {
+        this.currentInstanceUpstream = discoveryUpstream;
+        this.currentInstanceUpstream.setProps("{\"warmupTime\":\"10\"}");
+        this.discoveryConfig = new RegisterConfig();
+        
this.discoveryConfig.setServerLists(shenyuDiscoveryConfig.getServerList());
+        this.discoveryConfig.setRegisterType(shenyuDiscoveryConfig.getType());
+        
this.discoveryConfig.setProps(Optional.ofNullable(shenyuDiscoveryConfig.getProps()).orElse(new
 Properties()));
+        this.path = shenyuDiscoveryConfig.getRegisterPath();
+        Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() {
+            @Override
+            public void run() {
+                LOGGER.info("unregister upstream server by jvm runtime hook");
+                if (Objects.nonNull(discoveryService)) {
+                    discoveryService.close();
+                }
+            }
+        }));
+    }
+
+    @Override
+    public void onApplicationEvent(final ContextRefreshedEvent event) {
+        try {
+            if (StringUtils.isBlank(discoveryConfig.getRegisterType()) || 
StringUtils.equalsIgnoreCase(discoveryConfig.getRegisterType(), "local")) {
+                return;
+            }
+            this.discoveryService = 
ExtensionLoader.getExtensionLoader(ShenyuInstanceRegisterRepository.class).getJoin(discoveryConfig.getRegisterType());
+            discoveryConfig.getProps().put("watchPath", path);
+            discoveryService.init(discoveryConfig);
+            InstanceEntity instance = new InstanceEntity();
+            instance.setStatus(currentInstanceUpstream.getStatus());
+            instance.setWeight(currentInstanceUpstream.getWeight());
+            URI uri = URI.create(currentInstanceUpstream.getProtocol() + 
currentInstanceUpstream.getUrl());
+            instance.setPort(uri.getPort());
+            instance.setHost(uri.getHost());
+            
instance.setAppName(discoveryConfig.getProps().getProperty("name"));
+            discoveryService.persistInstance(instance);

Review Comment:
   URI construction is missing the scheme separator. If `protocol` is `http` 
and `url` is `127.0.0.1:8080`, this builds `http127.0.0.1:8080`, which won't 
parse correctly and can produce null host/port. Build the URI using `protocol + 
\"://\" + url` (or use `URI` components) so `getHost()`/`getPort()` are 
reliable.



-- 
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]

Reply via email to