Skip to content

Commit

Permalink
[ISSUE #4810] Rule's Operation about path containing '@PathVariable' …
Browse files Browse the repository at this point in the history
…should be match (#4852)

Co-authored-by: tian-pengfei <[email protected]>
  • Loading branch information
tian-pengfei and tian-pengfei authored Jul 16, 2023
1 parent ddda44b commit 788d362
Showing 1 changed file with 24 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,28 +63,28 @@
* 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;

Expand All @@ -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.
*
Expand All @@ -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.
*
Expand Down Expand Up @@ -234,7 +234,7 @@ public String doRegisterURI(final String selectorName, final List<URIRegisterDTO
}
return ShenyuResultMessage.SUCCESS;
}

/**
* Gets meta data service.
*
Expand All @@ -243,7 +243,7 @@ public String doRegisterURI(final String selectorName, final List<URIRegisterDTO
public MetaDataService getMetaDataService() {
return metaDataService;
}

/**
* Gets selector service.
*
Expand All @@ -252,7 +252,7 @@ public MetaDataService getMetaDataService() {
public SelectorService getSelectorService() {
return selectorService;
}

/**
* Gets rule service.
*
Expand All @@ -261,7 +261,7 @@ public SelectorService getSelectorService() {
public RuleService getRuleService() {
return ruleService;
}

/**
* Gets event publisher.
*
Expand All @@ -270,7 +270,7 @@ public RuleService getRuleService() {
public ApplicationEventPublisher getEventPublisher() {
return eventPublisher;
}

/**
* Do submit.
*
Expand All @@ -283,7 +283,7 @@ protected boolean doSubmit(final String selectorId, final List<? extends CommonU
return commonUpstreamList.stream().map(upstream -> upstreamCheckService.checkAndSubmit(selectorId, upstream))
.collect(Collectors.toList()).stream().findAny().orElse(false);
}

/**
* Build context path default rule dto rule dto.
*
Expand All @@ -296,11 +296,11 @@ protected RuleDTO buildContextPathDefaultRuleDTO(final String selectorId, final
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)
Expand All @@ -312,16 +312,18 @@ private RuleDTO buildRuleDTO(final String selectorId, final String ruleHandler,
.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());
Expand All @@ -333,6 +335,7 @@ private RuleDTO buildRuleDTO(final String selectorId, final String ruleHandler,
/**
* 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
*/
Expand Down

0 comments on commit 788d362

Please sign in to comment.