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/incubator-shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new f8c6ae2cd [ISSUE #3350] why contextpath "/springcloud" != 
"springcloud" ? (#3430)
f8c6ae2cd is described below

commit f8c6ae2cd1b4b2a4909c16add67fdf5811f14a24
Author: Sixh-PrFor <[email protected]>
AuthorDate: Wed May 25 09:47:07 2022 +0800

    [ISSUE #3350] why contextpath "/springcloud" != "springcloud" ? (#3430)
    
    * Add a bug that the contextPath of spring cloud and spring mvc does not 
start with "/".
    
    * Add a bug that the contextPath of spring cloud and spring mvc does not 
start with "/".
---
 .../shenyu/client/springcloud/init/ContextRegisterListener.java       | 3 ++-
 .../client/springcloud/init/SpringCloudClientBeanPostProcessor.java   | 4 +++-
 .../apache/shenyu/client/springmvc/init/ContextRegisterListener.java  | 3 ++-
 .../client/springmvc/init/SpringMvcClientBeanPostProcessor.java       | 4 +++-
 4 files changed, 10 insertions(+), 4 deletions(-)

diff --git 
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListener.java
 
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListener.java
index db712b71e..0588324c6 100644
--- 
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListener.java
+++ 
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/ContextRegisterListener.java
@@ -25,6 +25,7 @@ import org.apache.shenyu.common.enums.RpcTypeEnum;
 import org.apache.shenyu.common.utils.IpUtils;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.utils.PortUtils;
+import org.apache.shenyu.common.utils.UriUtils;
 import org.apache.shenyu.register.common.config.PropertiesConfig;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
 import org.apache.shenyu.register.common.dto.URIRegisterDTO;
@@ -74,7 +75,7 @@ public class ContextRegisterListener implements 
ApplicationListener<ContextRefre
     public ContextRegisterListener(final PropertiesConfig config, final 
Environment env) {
         Properties props = config.getProps();
         this.isFull = 
Boolean.parseBoolean(props.getProperty(ShenyuClientConstants.IS_FULL, 
Boolean.FALSE.toString()));
-        this.contextPath = 
props.getProperty(ShenyuClientConstants.CONTEXT_PATH);
+        this.contextPath = 
Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse(null);
         if (Boolean.TRUE.equals(isFull)) {
             if (StringUtils.isBlank(contextPath)) {
                 String errorMsg = "http register param must config the 
contextPath";
diff --git 
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientBeanPostProcessor.java
 
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientBeanPostProcessor.java
index 1e709acb3..b5208c32f 100644
--- 
a/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientBeanPostProcessor.java
+++ 
b/shenyu-client/shenyu-client-http/shenyu-client-springcloud/src/main/java/org/apache/shenyu/client/springcloud/init/SpringCloudClientBeanPostProcessor.java
@@ -24,6 +24,7 @@ import 
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublishe
 import 
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
 import org.apache.shenyu.client.springcloud.annotation.ShenyuSpringCloudClient;
 import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.UriUtils;
 import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
 import org.apache.shenyu.register.common.config.PropertiesConfig;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
@@ -48,6 +49,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Properties;
 
 /**
@@ -88,7 +90,7 @@ public class SpringCloudClientBeanPostProcessor implements 
BeanPostProcessor {
                                               final Environment env) {
         String appName = env.getProperty("spring.application.name");
         Properties props = clientConfig.getProps();
-        this.contextPath = 
props.getProperty(ShenyuClientConstants.CONTEXT_PATH);
+        this.contextPath = 
Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse(null);
         if (StringUtils.isBlank(appName)) {
             String errorMsg = "spring cloud param must config the appName";
             LOG.error(errorMsg);
diff --git 
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListener.java
 
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListener.java
index ebbebf5c1..050444989 100644
--- 
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListener.java
+++ 
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/ContextRegisterListener.java
@@ -26,6 +26,7 @@ import org.apache.shenyu.common.exception.ShenyuException;
 import org.apache.shenyu.common.utils.IpUtils;
 import org.apache.shenyu.common.utils.PathUtils;
 import org.apache.shenyu.common.utils.PortUtils;
+import org.apache.shenyu.common.utils.UriUtils;
 import org.apache.shenyu.register.common.config.PropertiesConfig;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
 import org.apache.shenyu.register.common.dto.URIRegisterDTO;
@@ -75,7 +76,7 @@ public class ContextRegisterListener implements 
ApplicationListener<ContextRefre
     public ContextRegisterListener(final PropertiesConfig clientConfig) {
         final Properties props = clientConfig.getProps();
         this.isFull = 
Boolean.parseBoolean(props.getProperty(ShenyuClientConstants.IS_FULL, 
Boolean.FALSE.toString()));
-        this.contextPath = 
props.getProperty(ShenyuClientConstants.CONTEXT_PATH);
+        this.contextPath = 
Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse(null);
         if (Boolean.TRUE.equals(isFull)) {
             if (StringUtils.isBlank(contextPath)) {
                 final String errorMsg = "http register param must config the 
contextPath";
diff --git 
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientBeanPostProcessor.java
 
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientBeanPostProcessor.java
index 6bd607bb4..bd932e5ab 100644
--- 
a/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientBeanPostProcessor.java
+++ 
b/shenyu-client/shenyu-client-http/shenyu-client-springmvc/src/main/java/org/apache/shenyu/client/springmvc/init/SpringMvcClientBeanPostProcessor.java
@@ -24,6 +24,7 @@ import 
org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublishe
 import 
org.apache.shenyu.client.core.exception.ShenyuClientIllegalArgumentException;
 import org.apache.shenyu.client.springmvc.annotation.ShenyuSpringMvcClient;
 import org.apache.shenyu.common.enums.RpcTypeEnum;
+import org.apache.shenyu.common.utils.UriUtils;
 import org.apache.shenyu.register.client.api.ShenyuClientRegisterRepository;
 import org.apache.shenyu.register.common.config.PropertiesConfig;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
@@ -47,6 +48,7 @@ import java.lang.reflect.Method;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Objects;
+import java.util.Optional;
 import java.util.Properties;
 
 /**
@@ -83,7 +85,7 @@ public class SpringMvcClientBeanPostProcessor implements 
BeanPostProcessor {
                                             final 
ShenyuClientRegisterRepository shenyuClientRegisterRepository) {
         Properties props = clientConfig.getProps();
         this.appName = props.getProperty(ShenyuClientConstants.APP_NAME);
-        this.contextPath = 
props.getProperty(ShenyuClientConstants.CONTEXT_PATH, "");
+        this.contextPath = 
Optional.ofNullable(props.getProperty(ShenyuClientConstants.CONTEXT_PATH)).map(UriUtils::repairData).orElse("");
         if (StringUtils.isBlank(appName) && StringUtils.isBlank(contextPath)) {
             String errorMsg = "http register param must config the appName or 
contextPath";
             LOG.error(errorMsg);

Reply via email to