Skip to content

Commit c17a92f

Browse files
Merge pull request #2240 from GDLMadushanka/SIEL2
Add function param support
2 parents e062c34 + 744b93f commit c17a92f

31 files changed

+666
-450
lines changed

modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ VAR: 'var';
99
PAYLOAD: 'payload' | '$';
1010
HEADERS: 'headers';
1111
CONFIG: 'config';
12-
ATTRIBUTES: 'attributes' | 'attr';
12+
PARAMS: 'params';
13+
PROPERTY: 'props' | 'properties';
1314
AND: 'and' | '&&';
1415
OR: 'or' | '||';
1516
NOT: '!';

modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionParser.g4

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ factor
3838
| payloadAccess
3939
| headerAccess
4040
| configAccess
41-
| attributeAccess
41+
| parameterAccess
42+
| propertyAccess
4243
| LPAREN expression RPAREN
4344
;
4445

@@ -50,8 +51,12 @@ headerAccess
5051
: HEADERS propertyName
5152
;
5253

53-
attributeAccess
54-
: ATTRIBUTES (DOT ID propertyName)
54+
parameterAccess
55+
: PARAMS (DOT ID propertyName)
56+
;
57+
58+
propertyAccess
59+
: PROPERTY (DOT ID propertyName)
5560
;
5661

5762
propertyName
@@ -126,7 +131,8 @@ filterComponent
126131
| payloadAccess
127132
| headerAccess
128133
| configAccess
129-
| attributeAccess
134+
| parameterAccess
135+
| propertyAccess
130136
| functionCall
131137
| stringOrOperator
132138
;
@@ -144,4 +150,4 @@ functionCall
144150
functionCallSuffix
145151
: DOT ID LPAREN (expression (COMMA expression)*)? RPAREN // Method chaining
146152
| jsonPathExpression
147-
;
153+
;

modules/core/src/main/java/org/apache/synapse/SynapseConstants.java

Lines changed: 0 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -626,59 +626,4 @@ public enum ENDPOINT_TIMEOUT_TYPE { ENDPOINT_TIMEOUT, GLOBAL_TIMEOUT, HTTP_CONNE
626626

627627
public static final String ANALYTICS_METADATA = "ANALYTICS_METADATA";
628628

629-
// Constants related to Synapse Expressions
630-
public static final String AND = "and";
631-
public static final String OR = "or";
632-
public static final String NOT = "not";
633-
public static final String TO_LOWER = "toLower";
634-
public static final String TO_UPPER = "toUpper";
635-
public static final String LENGTH = "length";
636-
public static final String SUBSTRING = "subString";
637-
public static final String STARTS_WITH = "startsWith";
638-
public static final String ENDS_WITH = "endsWith";
639-
public static final String CONTAINS = "contains";
640-
public static final String TRIM = "trim";
641-
public static final String REPLACE = "replace";
642-
public static final String SPLIT = "split";
643-
public static final String INDEX_OF = "indexOf";
644-
public static final String ABS = "abs";
645-
public static final String CEIL = "ceil";
646-
public static final String FLOOR = "floor";
647-
public static final String SQRT = "sqrt";
648-
public static final String LOG = "log";
649-
public static final String POW = "pow";
650-
public static final String B64ENCODE = "base64encode";
651-
public static final String B64DECODE = "base64decode";
652-
public static final String URL_ENCODE = "urlEncode";
653-
public static final String URL_DECODE = "urlDecode";
654-
public static final String IS_NUMBER = "isNumber";
655-
public static final String IS_STRING = "isString";
656-
public static final String IS_ARRAY = "isArray";
657-
public static final String IS_OBJECT = "isObject";
658-
public static final String OBJECT = "object";
659-
public static final String ARRAY = "array";
660-
public static final String REGISTRY = "registry";
661-
public static final String EXISTS = "exists";
662-
public static final String XPATH = "xpath";
663-
public static final String SECRET = "secret";
664-
public static final String NOW = "now";
665-
public static final String FORMAT_DATE_TIME = "formatDateTime";
666-
public static final String CHAR_AT = "charAt";
667-
668-
public static final String ROUND = "round";
669-
public static final String INTEGER = "integer";
670-
public static final String FLOAT = "float";
671-
public static final String STRING = "string";
672-
public static final String BOOLEAN = "boolean";
673-
674-
public static final String PAYLOAD = "payload";
675-
public static final String PAYLOAD_$ = "$";
676-
public static final String SYNAPSE_EXPRESSION_IDENTIFIER_START = "${";
677-
public static final String SYNAPSE_EXPRESSION_IDENTIFIER_END = "}";
678-
public static final String AXIS2 = "axis2";
679-
public static final String QUERY_PARAM = "queryParams";
680-
public static final String URI_PARAM = "uriParams";
681-
682-
public static final String UNKNOWN = "unknown";
683-
public static final String VAULT_LOOKUP = "wso2:vault-lookup('";
684629
}

modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import org.apache.axiom.om.OMAttribute;
2323
import org.apache.axiom.om.OMElement;
2424
import org.apache.synapse.Mediator;
25-
import org.apache.synapse.SynapseConstants;
2625
import org.apache.synapse.SynapseException;
2726
import org.apache.synapse.mediators.Value;
2827
import org.apache.synapse.mediators.builtin.PropertyMediator;
2928
import org.apache.synapse.util.MediatorPropertyUtils;
29+
import org.apache.synapse.util.synapse.expression.constants.ExpressionConstants;
3030
import org.apache.synapse.util.xpath.SynapseJsonPath;
3131
import org.apache.synapse.util.xpath.SynapseExpression;
3232
import org.apache.synapse.util.xpath.SynapseXPath;
@@ -85,8 +85,8 @@ public Mediator createSpecificMediator(OMElement elem, Properties properties) {
8585
String nameExpression = nameAttributeValue.substring(1, nameAttributeValue.length() - 1);
8686
if(nameExpression.startsWith("json-eval(")) {
8787
new SynapseJsonPath(nameExpression.substring(10, nameExpression.length() - 1));
88-
} else if (nameExpression.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
89-
nameExpression.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
88+
} else if (nameExpression.startsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
89+
nameExpression.endsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
9090
new SynapseExpression(nameExpression.substring(2, nameExpression.length() - 1));
9191
} else {
9292
new SynapseXPath(nameExpression);

modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePath.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
import org.apache.axiom.om.xpath.AXIOMXPath;
55
import org.apache.commons.logging.Log;
66
import org.apache.synapse.MessageContext;
7-
import org.apache.synapse.SynapseConstants;
87
import org.apache.synapse.SynapseException;
98
import org.apache.synapse.transport.util.MessageHandlerProvider;
109
import org.apache.synapse.transport.passthru.PassThroughConstants;
1110
import org.apache.synapse.transport.passthru.Pipe;
1211
import org.apache.synapse.transport.passthru.config.PassThroughConfiguration;
1312
import org.apache.synapse.util.streaming_xpath.custom.components.ParserComponent;
13+
import org.apache.synapse.util.synapse.expression.constants.ExpressionConstants;
1414
import org.apache.synapse.util.xpath.DOMSynapseXPathNamespaceMap;
1515
import org.jaxen.JaxenException;
1616

@@ -63,8 +63,8 @@ public SynapsePath(String path, String pathType, Log log) throws JaxenException
6363
private String inferPathType(String expression) {
6464
if (expression.startsWith("json-eval(")) {
6565
return JSON_PATH;
66-
} else if (expression.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START)
67-
&& expression.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
66+
} else if (expression.startsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START)
67+
&& expression.endsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
6868
return SYNAPSE_EXPRESSIONS_PATH;
6969
} else {
7070
return X_PATH;

modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePathFactory.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import org.apache.synapse.SynapseConstants;
2727
import org.apache.synapse.SynapseException;
2828
import org.apache.synapse.config.SynapsePropertiesLoader;
29+
import org.apache.synapse.util.synapse.expression.constants.ExpressionConstants;
2930
import org.apache.synapse.util.xpath.SynapseJsonPath;
3031
import org.apache.synapse.util.xpath.SynapseExpression;
3132
import org.apache.synapse.util.xpath.SynapseXPath;
@@ -50,8 +51,8 @@ public static org.apache.synapse.config.xml.SynapsePath getSynapsePath(OMElement
5051

5152
if(pathAttrib.getAttributeValue().startsWith("json-eval(")) {
5253
path = new SynapseJsonPath(pathAttrib.getAttributeValue().substring(10, pathAttrib.getAttributeValue().length() - 1));
53-
} else if (pathAttrib.getAttributeValue().startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
54-
pathAttrib.getAttributeValue().endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
54+
} else if (pathAttrib.getAttributeValue().startsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
55+
pathAttrib.getAttributeValue().endsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
5556
path = new SynapseExpression(pathAttrib.getAttributeValue().substring(2, pathAttrib.getAttributeValue().length() - 1));
5657
} else {
5758
try {

modules/core/src/main/java/org/apache/synapse/mediators/Value.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import org.apache.commons.logging.Log;
2424
import org.apache.commons.logging.LogFactory;
2525
import org.apache.synapse.MessageContext;
26-
import org.apache.synapse.SynapseConstants;
2726
import org.apache.synapse.SynapseException;
2827
import org.apache.synapse.config.xml.SynapsePath;
28+
import org.apache.synapse.util.synapse.expression.constants.ExpressionConstants;
2929
import org.apache.synapse.util.xpath.SynapseJsonPath;
3030
import org.apache.synapse.util.xpath.SynapseXPath;
3131
import org.apache.synapse.util.xpath.SynapseExpression;
@@ -103,8 +103,8 @@ public SynapsePath getExpression() {
103103
new SynapseJsonPath(expressionString.substring(10, expressionString.length() - 1));
104104
expression = expressionTypeKey;
105105

106-
} else if (expressionString.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
107-
expressionString.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
106+
} else if (expressionString.startsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) &&
107+
expressionString.endsWith(ExpressionConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) {
108108
expression = new SynapseExpression(
109109
expressionString.substring(2, expressionString.length() - 1));
110110
} else {

modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArgumentListNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public List<ExpressionNode> getArguments() {
4040
}
4141

4242
@Override
43-
public ExpressionResult evaluate(EvaluationContext context) {
43+
public ExpressionResult evaluate(EvaluationContext context, boolean isObjectValue) {
4444
return null;
4545
}
4646

modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArrayIndexNode.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ public ArrayIndexNode(ArgumentListNode arguments, char separator) {
3535
}
3636

3737
@Override
38-
public ExpressionResult evaluate(EvaluationContext context) {
38+
public ExpressionResult evaluate(EvaluationContext context, boolean isObjectValue) {
3939
List<String> indexList = new ArrayList<>();
4040
for (ExpressionNode index : indexArray) {
4141
if (index == null) {
4242
indexList.add("");
4343
continue;
4444
}
45-
ExpressionResult result = index.evaluate(context);
45+
ExpressionResult result = index.evaluate(context, isObjectValue);
4646
if (result != null) {
4747
indexList.add(result.asString());
4848
}

modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/BinaryOperationNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ public BinaryOperationNode(ExpressionNode left, String operator, ExpressionNode
7171
}
7272

7373
@Override
74-
public ExpressionResult evaluate(EvaluationContext context) throws EvaluationException {
75-
ExpressionResult leftValue = left.evaluate(context);
76-
ExpressionResult rightValue = right.evaluate(context);
74+
public ExpressionResult evaluate(EvaluationContext context, boolean isObjectValue) throws EvaluationException {
75+
ExpressionResult leftValue = left.evaluate(context, isObjectValue);
76+
ExpressionResult rightValue = right.evaluate(context, isObjectValue);
7777
if ((leftValue == null || rightValue == null) &&
7878
(operator != Operator.EQUALS && operator != Operator.NOT_EQUALS)) {
7979
throw new EvaluationException("Null inputs for " + operator + " operation: " + leftValue

0 commit comments

Comments
 (0)