You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@shenyu.apache.org by as...@apache.org on 2022/01/05 10:06:25 UTC

[incubator-shenyu] branch master updated: [type: bug] fix shenyu client config isFull is true (#2709)

This is an automated email from the ASF dual-hosted git repository.

asxing 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 0d3f271  [type: bug] fix shenyu client config isFull is true (#2709)
0d3f271 is described below

commit 0d3f271482f5c5ce4c156baca279055df915c224
Author: xiaoyu <xi...@apache.org>
AuthorDate: Wed Jan 5 18:06:19 2022 +0800

    [type: bug] fix shenyu client config isFull is true (#2709)
    
    * [type: bug] fix shenyu client config isFull is true
    
    * [type: bug] fix shenyu client config isFull is true
---
 .../admin/service/impl/SelectorServiceImpl.java    |  2 +-
 .../AbstractContextPathRegisterService.java        |  3 +-
 .../AbstractShenyuClientRegisterServiceImpl.java   |  3 +-
 ...ShenyuClientRegisterSpringCloudServiceImpl.java |  3 +-
 .../org/apache/shenyu/admin/utils/PathUtils.java   | 47 ++++++++++++
 .../springcloud/init/ContextRegisterListener.java  |  1 -
 .../springmvc/init/ContextRegisterListener.java    |  6 +-
 .../shenyu/common/constant/AdminConstants.java     | 85 ++++++++++++----------
 8 files changed, 102 insertions(+), 48 deletions(-)

diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
index 6c0a3c7..da1b4e7 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/SelectorServiceImpl.java
@@ -436,7 +436,7 @@ public class SelectorServiceImpl implements SelectorService {
         selectorConditionDTO.setParamType(ParamTypeEnum.URI.getName());
         selectorConditionDTO.setParamName("/");
         selectorConditionDTO.setOperator(OperatorEnum.MATCH.getAlias());
-        selectorConditionDTO.setParamValue(contextPath + "/**");
+        selectorConditionDTO.setParamValue(contextPath + AdminConstants.URI_SUFFIX);
         return Collections.singletonList(selectorConditionDTO);
     }
 }
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java
index 8ba6662..98c01f1 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractContextPathRegisterService.java
@@ -17,6 +17,7 @@
 
 package org.apache.shenyu.admin.service.register;
 
+import org.apache.shenyu.admin.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.ContextMappingRuleHandle;
 import org.apache.shenyu.common.enums.PluginEnum;
 import org.apache.shenyu.register.common.dto.MetaDataRegisterDTO;
@@ -30,7 +31,7 @@ public abstract class AbstractContextPathRegisterService extends AbstractShenyuC
     public void registerContextPath(final MetaDataRegisterDTO dto) {
         String contextPathSelectorId = getSelectorService().registerDefault(dto, PluginEnum.CONTEXT_PATH.getName(), "");
         ContextMappingRuleHandle handle = new ContextMappingRuleHandle();
-        handle.setContextPath(dto.getContextPath());
+        handle.setContextPath(PathUtils.decoratorContextPath(dto.getContextPath()));
         getRuleService().registerDefault(buildContextPathDefaultRuleDTO(contextPathSelectorId, dto, handle.toJson()));
     }
 }
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
index 5198499..da6d565 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/AbstractShenyuClientRegisterServiceImpl.java
@@ -28,6 +28,7 @@ import org.apache.shenyu.admin.service.RuleService;
 import org.apache.shenyu.admin.service.SelectorService;
 import org.apache.shenyu.admin.service.impl.UpstreamCheckService;
 import org.apache.shenyu.admin.utils.CommonUpstreamUtils;
+import org.apache.shenyu.admin.utils.PathUtils;
 import org.apache.shenyu.admin.utils.ShenyuResultMessage;
 import org.apache.shenyu.common.dto.SelectorData;
 import org.apache.shenyu.common.dto.convert.selector.CommonUpstream;
@@ -210,7 +211,7 @@ public abstract class AbstractShenyuClientRegisterServiceImpl extends FallbackSh
      */
     protected RuleDTO buildContextPathDefaultRuleDTO(final String selectorId, final MetaDataRegisterDTO metaDataDTO, final String ruleHandler) {
         String contextPath = metaDataDTO.getContextPath();
-        return buildRuleDTO(selectorId, ruleHandler, contextPath, contextPath + "/**");
+        return buildRuleDTO(selectorId, ruleHandler, contextPath, PathUtils.decoratorPath(contextPath));
     }
     
     private RuleDTO buildRpcDefaultRuleDTO(final String selectorId, final MetaDataRegisterDTO metaDataDTO, final String ruleHandler) {
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java
index ba577f0..9770d9e 100644
--- a/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/register/ShenyuClientRegisterSpringCloudServiceImpl.java
@@ -22,6 +22,7 @@ import org.apache.shenyu.admin.model.entity.MetaDataDO;
 import org.apache.shenyu.admin.model.entity.SelectorDO;
 import org.apache.shenyu.admin.service.MetaDataService;
 import org.apache.shenyu.admin.utils.CommonUpstreamUtils;
+import org.apache.shenyu.admin.utils.PathUtils;
 import org.apache.shenyu.common.dto.convert.rule.impl.SpringCloudRuleHandle;
 import org.apache.shenyu.common.dto.convert.selector.DivideUpstream;
 import org.apache.shenyu.common.dto.convert.selector.SpringCloudSelectorHandle;
@@ -59,7 +60,7 @@ public class ShenyuClientRegisterSpringCloudServiceImpl extends AbstractContextP
     @Override
     protected void registerMetadata(final MetaDataRegisterDTO metaDataDTO) {
         MetaDataService metaDataService = getMetaDataService();
-        metaDataDTO.setPath(metaDataDTO.getContextPath() + "/**");
+        metaDataDTO.setPath(PathUtils.decoratorPath(metaDataDTO.getContextPath()));
         MetaDataDO metaDataDO = metaDataService.findByPath(metaDataDTO.getPath());
         metaDataService.saveOrUpdateMetaData(metaDataDO, metaDataDTO);
     }
diff --git a/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PathUtils.java b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PathUtils.java
new file mode 100644
index 0000000..dc36e3e
--- /dev/null
+++ b/shenyu-admin/src/main/java/org/apache/shenyu/admin/utils/PathUtils.java
@@ -0,0 +1,47 @@
+/*
+ * 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.admin.utils;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.shenyu.common.constant.AdminConstants;
+
+/**
+ * The type Path utils.
+ */
+public final class PathUtils {
+    
+    /**
+     * Decorator path string.
+     *
+     * @param contextPath the context path
+     * @return the string
+     */
+    public static String decoratorPath(final String contextPath) {
+        return StringUtils.contains(contextPath, AdminConstants.URI_SUFFIX) ? contextPath : contextPath + AdminConstants.URI_SUFFIX;
+    }
+    
+    /**
+     * Decorator context path string.
+     *
+     * @param contextPath the context path
+     * @return the string
+     */
+    public static String decoratorContextPath(final String contextPath) {
+        return StringUtils.contains(contextPath, AdminConstants.URI_SUFFIX) ? StringUtils.substringBefore(contextPath, AdminConstants.URI_SUFFIX) : contextPath;
+    }
+}
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 05f4f46..6928b5d 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
@@ -73,7 +73,6 @@ public class ContextRegisterListener implements ApplicationListener<ContextRefre
                 LOG.error(errorMsg);
                 throw new ShenyuClientIllegalArgumentException(errorMsg);
             }
-            this.contextPath = contextPath + "/**";
         }
         port = Integer.parseInt(props.getProperty(ShenyuClientConstants.PORT));
         this.appName = env.getProperty("spring.application.name");
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 5e06b2a..5ca1f8d 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
@@ -17,8 +17,6 @@
 
 package org.apache.shenyu.client.springmvc.init;
 
-import java.util.Properties;
-import java.util.concurrent.atomic.AtomicBoolean;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shenyu.client.core.constant.ShenyuClientConstants;
 import org.apache.shenyu.client.core.disruptor.ShenyuClientRegisterEventPublisher;
@@ -34,6 +32,9 @@ import org.springframework.context.ApplicationListener;
 import org.springframework.context.event.ContextRefreshedEvent;
 import org.springframework.lang.NonNull;
 
+import java.util.Properties;
+import java.util.concurrent.atomic.AtomicBoolean;
+
 /**
  * The type Context register listener.
  */
@@ -72,7 +73,6 @@ public class ContextRegisterListener implements ApplicationListener<ContextRefre
                 LOG.error(errorMsg);
                 throw new ShenyuClientIllegalArgumentException(errorMsg);
             }
-            this.contextPath = contextPath + "/**";
         }
         this.port = Integer.parseInt(props.getProperty(ShenyuClientConstants.PORT));
         this.appName = props.getProperty(ShenyuClientConstants.APP_NAME);
diff --git a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java
index 1d51eb4..cacbc89 100644
--- a/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java
+++ b/shenyu-common/src/main/java/org/apache/shenyu/common/constant/AdminConstants.java
@@ -21,204 +21,209 @@ package org.apache.shenyu.common.constant;
  * The type Admin constants.
  */
 public final class AdminConstants {
-
+    
     /**
      * The constant SUCCESS, equals to ShenyuResultMessage.SUCCESS.
      */
     public static final String SUCCESS = "SUCCESS";
-
+    
     /**
      * The constant PLUGIN_NAME_IS_EXIST.
      */
     public static final String PLUGIN_NAME_IS_EXIST = "The plugin name already exists and can't be added repeatedly!";
-
+    
     /**
      * The constant ID_NOT_EXIST.
      */
     public static final String ID_NOT_EXIST = "ID NOT EXIST!";
-
+    
     /**
      * The constant PLUGIN_NAME_NOT_EXIST.
      */
     public static final String PLUGIN_NAME_NOT_EXIST = "The plugin name not exist!";
-
+    
     /**
      * The constant SYS_PLUGIN_NOT_DELETE.
      */
     public static final String SYS_PLUGIN_NOT_DELETE = "System plugins can't be deleted!";
-
+    
     /**
      * The constant SYS_PLUGIN_ID_NOT_EXIST.
      */
     public static final String SYS_PLUGIN_ID_NOT_EXIST = "The plugin(s) does not exist!";
-
+    
     /**
      * The constant DATA_PATH_IS_EXIST.
      */
     public static final String DATA_PATH_IS_EXIST = "The path already exists and can't be added repeatedly!";
-
+    
     /**
      * The constant PARAMS_ERROR.
      */
     public static final String PARAMS_ERROR = "Error parameter!";
-
+    
     /**
      * The constant Super Role ID.
      */
     public static final String ROLE_SUPER_ID = "1346358560427216896";
-
+    
     /**
      * The constant Plugin Menu ID.
      */
     public static final String RESOURCE_PLUGIN_ID = "1346775491550474240";
-
+    
     /**
      * The constant Plugin Url prefix.
      */
     public static final String RESOURCE_PLUGIN_URL_PREFIX = "/plug/";
-
+    
     /**
      * The constant Plugin Resource Icon.
      */
     public static final String RESOURCE_PLUGIN_DEFAULT_ICON = "block";
-
+    
     /**
      * The constant Selector Name.
      */
     public static final String DATA_PERMISSION_SELECTOR = "selector";
-
+    
     /**
      * The constant Rule Name.
      */
     public static final String DATA_PERMISSION_RULE = "rule";
-
+    
     /**
      * The constant Admin Name.
      */
     public static final String ADMIN_NAME = "admin";
-
+    
     /**
      * The constant selector data type.
      */
     public static final Integer SELECTOR_DATA_TYPE = 0;
-
+    
     /**
      * the constant rule data type.
      */
     public static final Integer RULE_DATA_TYPE = 1;
-
+    
     /**
      * the constant selector add.
      */
     public static final String PLUGIN_SELECTOR_ADD = "SHENYU.BUTTON.PLUGIN.SELECTOR.ADD";
-
+    
     /**
      * the constant selector type add.
      */
     public static final String PLUGIN_TYPE_SELECTOR_ADD = "Selector:add";
-
+    
     /**
      * the constant selector query.
      */
     public static final String PLUGIN_SELECTOR_QUERY = "SHENYU.BUTTON.PLUGIN.SELECTOR.QUERY";
-
+    
     /**
      * the constant selector type query.
      */
     public static final String PLUGIN_TYPE_SELECTOR_QUERY = "Selector:query";
-
+    
     /**
      * the constant selector edit.
      */
     public static final String PLUGIN_SELECTOR_EDIT = "SHENYU.BUTTON.PLUGIN.SELECTOR.EDIT";
-
+    
     /**
      * the constant selector type edit.
      */
     public static final String PLUGIN_TYPE_SELECTOR_EDIT = "Selector:edit";
-
+    
     /**
      * the constant selector delete.
      */
     public static final String PLUGIN_SELECTOR_DELETE = "SHENYU.BUTTON.PLUGIN.SELECTOR.DELETE";
-
+    
     /**
      * the constant selector type delete.
      */
     public static final String PLUGIN_TYPE_SELECTOR_DELETE = "Selector:delete";
-
+    
     /**
      * the constant rule add.
      */
     public static final String PLUGIN_RULE_ADD = "SHENYU.BUTTON.PLUGIN.RULE.ADD";
-
+    
     /**
      * the constant rule type add.
      */
     public static final String PLUGIN_TYPE_RULE_ADD = "Rule:add";
-
+    
     /**
      * the constant rule query.
      */
     public static final String PLUGIN_RULE_QUERY = "SHENYU.BUTTON.PLUGIN.RULE.QUERY";
-
+    
     /**
      * the constant rule type query.
      */
     public static final String PLUGIN_TYPE_RULE_QUERY = "Rule:query";
-
+    
     /**
      * the constant rule edit.
      */
     public static final String PLUGIN_RULE_EDIT = "SHENYU.BUTTON.PLUGIN.RULE.EDIT";
-
+    
     /**
      * the constant rule type edit.
      */
     public static final String PLUGIN_TYPE_RULE_EDIT = "Rule:edit";
-
+    
     /**
      * the constant rule delete.
      */
     public static final String PLUGIN_RULE_DELETE = "SHENYU.BUTTON.PLUGIN.RULE.DELETE";
-
+    
     /**
      * the constant rule type delete.
      */
     public static final String PLUGIN_TYPE_RULE_DELETE = "Rule:delete";
-
+    
     /**
      * the constant plugin synchronize.
      */
     public static final String PLUGIN_SYNCHRONIZE = "SHENYU.BUTTON.PLUGIN.SYNCHRONIZE";
-
+    
     /**
      * the constant plugin type modify.
      */
     public static final String PLUGIN_TYPE_SYNCHRONIZE = ":modify";
-
+    
     /**
      * the constant table init dict type.
      */
     public static final String DICT_TABLE_FLAG_TYPE = "table";
-
+    
     /**
      * the constant table init dict code.
      */
     public static final String DICT_TABLE_FLAG_DICTCODE = "INIT_FLAG";
-
+    
     /**
      * the constant table init dict name.
      */
     public static final String DICT_TABLE_FLAG_DICTNAME = "status";
-
+    
     /**
      * the constant table init dict desc.
      */
     public static final String DICT_TABLE_FLAG_DESC = "table(resource,permission) init status";
-
+    
     /**
      * the constant table init dict sort.
      */
     public static final Integer DICT_TABLE_FLAG_SORT = 0;
+    
+    /**
+     * The constant URI_SUFFIX.
+     */
+    public static final String URI_SUFFIX = "/**";
 }