org.apache.shenyu.plugin.base.condition.judge.PredicateJudge
.pr
to the official website if you have a good common plugin.<dependencies> <dependency> <groupId>org.apache.shenyu</groupId> <artifactId>shenyu-plugin-base</artifactId> <version>${project.version}</version> </dependency> </dependencies>
CustomPredicateJudge
, implements org.apache.shenyu.plugin.base.condition.judge.PredicateJudge
, add annotation org.apache.shenyu.spi.Join
./** * custom predicate judge. */ @Join public class CustomPredicateJudge implements PredicateJudge { @Override public Boolean judge(final ConditionData conditionData, final String realData) { // Custom Predicate Judge } }
org.apache.shenyu.plugin.base.condition.judge.PredicateJudge
file, add key-value as following:${spi name} = ${custom class path}
${spi name}
represents the name of spi
and ${custom class path}
represents the fully qualified name of the class. Such as:
custom=xxx.xxx.xxx.CustomPredicateJudge
Package the project and copy it to the lib
or ext-lib
directory of the gateway (bootstrap-bin).
In the Apache ShenYu
gateway management system --> BasicConfig --> Dictionary, find the dictionary code as OPERATOR
, add a new piece of data, pay attention to the dictionary name: ${spi name}
.
DictionaryType:
operator
;DictionaryCode:
OPERATOR
;DictionaryName:
${spi name}
, input your custom spi name;DictionaryValue: When used, the value of the drop-down box, do not repeat with the existing;
DictionaryDescribe: desc your custom match strategy;
Sort: to sort;
Status: open or close.
GroovyPredicateJudge
and SpELPredicateJudge
extension./** * Groovy predicate judge. */ @Join public class GroovyPredicateJudge implements PredicateJudge { @Override public Boolean judge(final ConditionData conditionData, final String realData) { return (Boolean) Eval.me(conditionData.getParamName(), realData, conditionData.getParamValue()); } }
/** * SpEL predicate judge. */ @Join public class SpELPredicateJudge implements PredicateJudge { private static final ExpressionParser EXPRESSION_PARSER = new SpelExpressionParser(); @Override public Boolean judge(final ConditionData conditionData, final String realData) { Expression expression = EXPRESSION_PARSER.parseExpression(conditionData.getParamValue().replace('#' + conditionData.getParamName(), realData)); return expression.getValue(Boolean.class); } }
org.apache.shenyu.plugin.base.condition.judge.PredicateJudge
:Groovy=xxx.xxx.xxx.GroovyPredicateJudge SpEL=xxx.xxx.xxx.SpELPredicateJudge