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

likeguo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/shenyu.git


The following commit(s) were added to refs/heads/master by this push:
     new 788d36268 [ISSUE #4810] Rule's Operation about path containing 
'@PathVariable' should be match (#4852)
788d36268 is described below

commit 788d36268dea3fe6524ac284a078f75bd0638a9a
Author: tiandy tian <[email protected]>
AuthorDate: Sun Jul 16 22:07:26 2023 +0800

    [ISSUE #4810] Rule's Operation about path containing '@PathVariable' should 
be match (#4852)
    
    Co-authored-by: tian-pengfei <[email protected]>
---
 .../AbstractShenyuClientRegisterServiceImpl.java   | 45 ++++++++++++----------
 1 file changed, 24 insertions(+), 21 deletions(-)

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 02f570a28..6c391e5db 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
@@ -63,28 +63,28 @@ import java.util.stream.Collectors;
  * Abstract strategy.
  */
 public abstract class AbstractShenyuClientRegisterServiceImpl extends 
FallbackShenyuClientRegisterService implements ShenyuClientRegisterService {
-    
+
     /**
      * The Event publisher.
      */
     @Resource
     private ApplicationEventPublisher eventPublisher;
-    
+
     /**
      * The Selector service.
      */
     @Resource
     private SelectorService selectorService;
-    
+
     @Resource
     private MetaDataService metaDataService;
-    
+
     /**
      * The Rule service.
      */
     @Resource
     private RuleService ruleService;
-    
+
     @Resource
     private UpstreamCheckService upstreamCheckService;
 
@@ -101,21 +101,21 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
      * @return the string
      */
     protected abstract String selectorHandler(MetaDataRegisterDTO metaDataDTO);
-    
+
     /**
      * Rule handler string.
      *
      * @return the string
      */
     protected abstract String ruleHandler();
-    
+
     /**
      * Register metadata.
      *
      * @param metaDataDTO the meta data dto
      */
     protected abstract void registerMetadata(MetaDataRegisterDTO metaDataDTO);
-    
+
     /**
      * Build handle string.
      *
@@ -124,7 +124,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
      * @return the string
      */
     protected abstract String buildHandle(List<URIRegisterDTO> uriList, 
SelectorDO selectorDO);
-    
+
     /**
      * Register meta data.
      *
@@ -234,7 +234,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
         }
         return ShenyuResultMessage.SUCCESS;
     }
-    
+
     /**
      * Gets meta data service.
      *
@@ -243,7 +243,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     public MetaDataService getMetaDataService() {
         return metaDataService;
     }
-    
+
     /**
      * Gets selector service.
      *
@@ -252,7 +252,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     public SelectorService getSelectorService() {
         return selectorService;
     }
-    
+
     /**
      * Gets rule service.
      *
@@ -261,7 +261,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     public RuleService getRuleService() {
         return ruleService;
     }
-    
+
     /**
      * Gets event publisher.
      *
@@ -270,7 +270,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     public ApplicationEventPublisher getEventPublisher() {
         return eventPublisher;
     }
-    
+
     /**
      * Do submit.
      *
@@ -283,7 +283,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
         return commonUpstreamList.stream().map(upstream -> 
upstreamCheckService.checkAndSubmit(selectorId, upstream))
                 .collect(Collectors.toList()).stream().findAny().orElse(false);
     }
-    
+
     /**
      * Build context path default rule dto rule dto.
      *
@@ -296,11 +296,11 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
         String contextPath = metaDataDTO.getContextPath();
         return buildRuleDTO(selectorId, ruleHandler, contextPath, 
PathUtils.decoratorPath(contextPath));
     }
-    
+
     private RuleDTO buildRpcDefaultRuleDTO(final String selectorId, final 
MetaDataRegisterDTO metaDataDTO, final String ruleHandler) {
         return buildRuleDTO(selectorId, ruleHandler, 
metaDataDTO.getRuleName(), metaDataDTO.getPath());
     }
-    
+
     private RuleDTO buildRuleDTO(final String selectorId, final String 
ruleHandler, final String ruleName, final String path) {
         RuleDTO ruleDTO = RuleDTO.builder()
                 .selectorId(selectorId)
@@ -312,16 +312,18 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
                 .sort(1)
                 .handle(ruleHandler)
                 .build();
+
+        String conditionPath = this.rewritePath(path);
         RuleConditionDTO ruleConditionDTO = RuleConditionDTO.builder()
                 .paramType(ParamTypeEnum.URI.getName())
                 .paramName("/")
-                .paramValue(this.rewritePath(path))
+                .paramValue(conditionPath)
                 .build();
-        if (path.endsWith(AdminConstants.URI_SLASH_SUFFIX)) {
+        if (conditionPath.endsWith(AdminConstants.URI_SLASH_SUFFIX)) {
             ruleConditionDTO.setOperator(OperatorEnum.STARTS_WITH.getAlias());
-        } else if (path.endsWith(AdminConstants.URI_SUFFIX)) {
+        } else if (conditionPath.endsWith(AdminConstants.URI_SUFFIX)) {
             ruleConditionDTO.setOperator(OperatorEnum.PATH_PATTERN.getAlias());
-        } else if (path.indexOf("*") > 1) {
+        } else if (conditionPath.indexOf("*") > 1) {
             ruleConditionDTO.setOperator(OperatorEnum.MATCH.getAlias());
         } else {
             ruleConditionDTO.setOperator(OperatorEnum.EQ.getAlias());
@@ -333,6 +335,7 @@ public abstract class 
AbstractShenyuClientRegisterServiceImpl extends FallbackSh
     /**
      * adjustment such as '/aa/${xxx}/cc' replace to `/aa/`**`/cc` for client 
simpler annotation.
      * link: https://github.com/apache/shenyu/pull/3819
+     *
      * @param path the path
      * @return the replaced path
      */

Reply via email to