diff --git a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionLexer.g4 b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 similarity index 55% rename from modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionLexer.g4 rename to modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 index 3317424110..6e2a4030bc 100644 --- a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionLexer.g4 +++ b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 @@ -1,6 +1,8 @@ lexer grammar ExpressionLexer; -JSONPATH_FUNCTIONS: 'contains ' | 'in' | 'nin' | 'subsetof' | 'size' | 'empty' | 'empty true' | 'empty false' | '=~'; +JSONPATH_PARAMS: 'in' | 'nin' | 'subsetof' | 'anyof' | 'noneof' | 'size' | 'empty' | '=~'; + +JSONPATH_FUNCTIONS: 'length()' | 'size()' | 'min()' | 'max()' | 'avg()' | 'sum()' | 'stddev()' | 'keys()' | 'first()' | 'last()'; // Tokens for identifiers, operators, and keywords VAR: 'var'; @@ -8,51 +10,9 @@ PAYLOAD: 'payload' | '$'; HEADERS: 'headers'; CONFIG: 'config'; ATTRIBUTES: 'attributes' | 'attr'; -AXIS2: 'axis2'; -SYNAPSE: 'synapse'; -QUERY_PARAM: 'queryParams'; -URI_PARAM: 'uriParams'; -REGISTRY: 'registry'; -SECRET: 'secret'; -BASE64ENCODE: 'base64encode'; -BASE64DECODE: 'base64decode'; -URLENCODE: 'urlEncode'; -URLDECODE: 'urlDecode'; -NOW: 'now'; -TODAY: 'today'; -FORMATDATE: 'formatDate'; -ISNUMBER: 'isNumber'; -ISSTRING: 'isString'; -ISARRAY: 'isArray'; -ISOBJECT: 'isObject'; -ROUND: 'round'; -INTEGER: 'integer'; -FLOAT: 'float'; -STRING: 'string'; -BOOLEAN: 'boolean'; -OBJECT: 'object'; -ARRAY: 'array'; -XPATH: 'xpath'; -ABS: 'abs'; -FLOOR: 'floor'; -CEIL: 'ceil'; -SQRT: 'sqrt'; -LOG: 'log'; -POW: 'pow'; -LENGTH: 'length'; -TOUPPER: 'toUpper'; -TOLOWER: 'toLower'; -SUBSTRING: 'subString'; -STARTSWITH: 'startsWith'; -ENDSWITH: 'endsWith'; -CONTAINS: 'contains'; -EXISTS: 'exists'; -TRIM: 'trim'; -REPLACE: 'replace'; -SPLIT: 'split'; AND: 'and' | '&&'; OR: 'or' | '||'; -NOT: 'not' | '!'; +NOT: '!'; DOUBLE_DOT : '..'; ASTERISK : '*'; @@ -110,8 +70,8 @@ NULL_LITERAL ; // Identifiers -GETPROPERTY: 'getProperty'; ID: [a-zA-Z_][a-zA-Z_0-9]*; + // Special symbols for JSONPath filter expressions QUESTION: '?'; AT: '@'; diff --git a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionParser.g4 b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionParser.g4 new file mode 100644 index 0000000000..38ae834964 --- /dev/null +++ b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionParser.g4 @@ -0,0 +1,147 @@ +parser grammar ExpressionParser; + +options { + tokenVocab = ExpressionLexer; +} + +expression + : comparisonExpression + | conditionalExpression + | EOF + ; + +conditionalExpression + : comparisonExpression (QUESTION expression COLON expression)? + ; + +comparisonExpression + : logicalExpression ( (GT | LT | GTE | LTE | EQ | NEQ) logicalExpression )* + | logicalExpression (EQ | NEQ) NULL_LITERAL + ; + +logicalExpression + : arithmeticExpression (AND logicalExpression | OR logicalExpression)? + ; + +arithmeticExpression + : term ( (PLUS | MINUS) term )* + ; + +term + : factor ( (ASTERISK | DIV | MODULO) factor )* + ; + +factor + : literal + | functionCall + | variableAccess + | payloadAccess + | headerAccess + | configAccess + | attributeAccess + | LPAREN expression RPAREN + ; + +configAccess + : CONFIG propertyName + ; + +headerAccess + : HEADERS propertyName + ; + +attributeAccess + : ATTRIBUTES (DOT ID propertyName) + ; + +propertyName + : DOT ID + | (DOT)? LBRACKET STRING_LITERAL RBRACKET + ; + +literal + : arrayLiteral + | BOOLEAN_LITERAL + | NUMBER + | STRING_LITERAL + | NULL_LITERAL + ; + +jsonPathExpression + :( DOT JSONPATH_FUNCTIONS + |DOUBLE_DOT ASTERISK + | DOUBLE_DOT ID + | DOT ID + | (DOT)? LBRACKET arrayIndex RBRACKET + | DOT ASTERISK + | DOUBLE_DOT ID (LBRACKET arrayIndex RBRACKET)?)+ + ; + + +variableAccess + : VAR ( DOT ID + | DOT STRING_LITERAL + | (DOT)? LBRACKET STRING_LITERAL RBRACKET // Bracket notation: var["variableName"] + ) + ( jsonPathExpression )? + ; + +arrayLiteral + : LBRACKET (expression (COMMA expression)*)? RBRACKET // Array with zero or more literals, separated by commas + ; + +payloadAccess + : PAYLOAD ( jsonPathExpression)? + ; + +arrayIndex + : NUMBER + | STRING_LITERAL + | expression + | multipleArrayIndices + | sliceArrayIndex + | expression ( (PLUS | MINUS | ASTERISK | DIV ) expression)* + | ASTERISK + | QUESTION? filterExpression + ; + +multipleArrayIndices + : expression (COMMA expression)+ + ; + +sliceArrayIndex + : signedExpressions? COLON signedExpressions? (COLON signedExpressions?)? + ; + +signedExpressions + : MINUS? expression + ; + +filterExpression + : (filterComponent)+ + ; + +filterComponent + : variableAccess + | payloadAccess + | headerAccess + | configAccess + | attributeAccess + | functionCall + | stringOrOperator + ; + +stringOrOperator + : QUESTION | AT | JSONPATH_PARAMS | STRING_LITERAL |NUMBER | BOOLEAN_LITERAL | ID | GT | LT | GTE | LTE | EQ | NEQ + | PLUS | MINUS | DIV | LPAREN | RPAREN | DOT | COMMA | COLON | WS | AND | OR | NOT | ASTERISK + ; + + +functionCall + : ID LPAREN (expression (COMMA expression)*)? RPAREN functionCallSuffix? + ; + +functionCallSuffix + : DOT ID LPAREN (expression (COMMA expression)*)? RPAREN // Method chaining + | jsonPathExpression + ; \ No newline at end of file diff --git a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionParser.g4 b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionParser.g4 deleted file mode 100644 index 9a590963ee..0000000000 --- a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_path/ExpressionParser.g4 +++ /dev/null @@ -1,182 +0,0 @@ -parser grammar ExpressionParser; - -options { - tokenVocab = ExpressionLexer; -} - -expression - : comparisonExpression - | conditionalExpression - | EOF - ; - -conditionalExpression - : comparisonExpression (QUESTION expression COLON expression)? - ; - -comparisonExpression - : logicalExpression ( (GT | LT | GTE | LTE | EQ | NEQ) logicalExpression )* - | logicalExpression (EQ | NEQ) NULL_LITERAL // Allow comparison to null - ; - -logicalExpression - : arithmeticExpression (AND logicalExpression | OR logicalExpression)? - ; - -arithmeticExpression - : term ( (PLUS | MINUS) term )* - ; - -term - : factor ( (ASTERISK | DIV | MODULO) factor )* - ; - -factor - : literal - | functionCall - | variableAccess - | payloadAccess - | headerAccess - | configAccess - | attributeAccess - | LPAREN expression RPAREN - ; - -configAccess - : CONFIG propertyName - ; - -headerAccess - : HEADERS propertyName - ; - -attributeAccess - : ATTRIBUTES (DOT AXIS2 propertyName - | DOT SYNAPSE propertyName - | DOT QUERY_PARAM propertyName - | DOT URI_PARAM propertyName) - ; - -propertyName - : DOT ID - | (DOT)? LBRACKET STRING_LITERAL RBRACKET - ; - -literal - : arrayLiteral - | BOOLEAN_LITERAL - | NUMBER - | STRING_LITERAL - | NULL_LITERAL - ; - -jsonPathExpression - :( (DOUBLE_DOT ASTERISK - | DOUBLE_DOT ID - | DOT ID - | LBRACKET arrayIndex RBRACKET - | DOT LBRACKET arrayIndex RBRACKET - | DOT ASTERISK)* - | DOUBLE_DOT ID (LBRACKET arrayIndex RBRACKET)? ) - ; - - -variableAccess - : VAR ( DOT ID - | DOT STRING_LITERAL - | (DOT)? LBRACKET STRING_LITERAL RBRACKET // Bracket notation: var["variableName"] - ) - ( jsonPathExpression )? - ; - -arrayLiteral - : LBRACKET (expression (COMMA expression)*)? RBRACKET // Array with zero or more literals, separated by commas - ; - -payloadAccess - : PAYLOAD ( jsonPathExpression)? - ; - -arrayIndex - : NUMBER - | STRING_LITERAL - | expression - | multipleArrayIndices - | sliceArrayIndex - | expression ( (PLUS | MINUS | MULT | DIV ) expression)* - | ASTERISK - | QUESTION? filterExpression - ; - -multipleArrayIndices - : expression (COMMA expression)+ - ; - -sliceArrayIndex - : signedExpressions? COLON signedExpressions? (COLON signedExpressions?)? - ; - -signedExpressions - : MINUS? expression - ; - -filterExpression - : (filterComponent)+ - ; - -filterComponent - : variableAccess - | payloadAccess - | stringOrOperator - | headerAccess - | configAccess - | attributeAccess - | functionCall - ; - -stringOrOperator - : QUESTION | AT | JSONPATH_FUNCTIONS| STRING_LITERAL |NUMBER | BOOLEAN_LITERAL | ID | GT | LT | GTE | LTE | EQ | NEQ - | PLUS | MINUS | MULT | DIV | LPAREN | RPAREN | DOT | COMMA | COLON | WS | AND | OR | NOT | ASTERISK - ; - -functionCall - : LENGTH LPAREN expression RPAREN - | TOUPPER LPAREN expression RPAREN - | TOLOWER LPAREN expression RPAREN - | SUBSTRING LPAREN expression COMMA expression (COMMA expression)? RPAREN - | STARTSWITH LPAREN expression COMMA expression RPAREN - | ENDSWITH LPAREN expression COMMA expression RPAREN - | CONTAINS LPAREN expression COMMA expression RPAREN - | TRIM LPAREN expression RPAREN - | REPLACE LPAREN expression COMMA expression COMMA expression RPAREN - | SPLIT LPAREN expression COMMA expression RPAREN - | ABS LPAREN expression RPAREN - | FLOOR LPAREN expression RPAREN - | CEIL LPAREN expression RPAREN - | SQRT LPAREN expression RPAREN - | LOG LPAREN expression RPAREN - | POW LPAREN expression COMMA expression RPAREN - | REGISTRY LPAREN expression RPAREN ( (DOT GETPROPERTY LPAREN expression RPAREN) | jsonPathExpression )? - | SECRET LPAREN expression RPAREN - | BASE64ENCODE LPAREN expression (COMMA expression)? RPAREN - | BASE64DECODE LPAREN expression RPAREN - | URLENCODE LPAREN expression (COMMA expression)? RPAREN - | URLDECODE LPAREN expression RPAREN - | ISNUMBER LPAREN expression RPAREN - | ISSTRING LPAREN expression RPAREN - | ISARRAY LPAREN expression RPAREN - | ISOBJECT LPAREN expression RPAREN - | NOW LPAREN RPAREN - | TODAY LPAREN STRING_LITERAL RPAREN - | FORMATDATE LPAREN expression COMMA STRING_LITERAL RPAREN - | ROUND LPAREN expression RPAREN - | INTEGER LPAREN expression RPAREN - | FLOAT LPAREN expression RPAREN - | STRING LPAREN expression RPAREN - | BOOLEAN LPAREN expression RPAREN - | EXISTS LPAREN expression RPAREN - | OBJECT LPAREN expression RPAREN (jsonPathExpression)? - | ARRAY LPAREN expression RPAREN (LBRACKET arrayIndex RBRACKET)? - | XPATH LPAREN expression RPAREN - | NOT LPAREN expression RPAREN - ; diff --git a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java index 27544d2192..01a99133e4 100644 --- a/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java +++ b/modules/core/src/main/java/org/apache/synapse/SynapseConstants.java @@ -626,7 +626,7 @@ public enum ENDPOINT_TIMEOUT_TYPE { ENDPOINT_TIMEOUT, GLOBAL_TIMEOUT, HTTP_CONNE public static final String ANALYTICS_METADATA = "ANALYTICS_METADATA"; - // Constants related to SIEL + // Constants related to Synapse Expressions public static final String AND = "and"; public static final String OR = "or"; public static final String NOT = "not"; @@ -670,8 +670,8 @@ public enum ENDPOINT_TIMEOUT_TYPE { ENDPOINT_TIMEOUT, GLOBAL_TIMEOUT, HTTP_CONNE public static final String PAYLOAD = "payload"; public static final String PAYLOAD_$ = "$"; - public static final String SIEL_IDENTIFIER_START = "#["; - public static final String SIEL_IDENTIFIER_END = "]"; + public static final String SYNAPSE_EXPRESSION_IDENTIFIER_START = "${"; + public static final String SYNAPSE_EXPRESSION_IDENTIFIER_END = "}"; public static final String AXIS2 = "axis2"; public static final String QUERY_PARAM = "queryParams"; public static final String URI_PARAM = "uriParams"; diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java index 952c8abfde..4d71c611c2 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java @@ -28,7 +28,7 @@ import org.apache.synapse.mediators.builtin.PropertyMediator; import org.apache.synapse.util.MediatorPropertyUtils; import org.apache.synapse.util.xpath.SynapseJsonPath; -import org.apache.synapse.util.xpath.Synapse_Path; +import org.apache.synapse.util.xpath.SynapseExpression; import org.apache.synapse.util.xpath.SynapseXPath; import org.jaxen.JaxenException; @@ -85,9 +85,9 @@ public Mediator createSpecificMediator(OMElement elem, Properties properties) { String nameExpression = nameAttributeValue.substring(1, nameAttributeValue.length() - 1); if(nameExpression.startsWith("json-eval(")) { new SynapseJsonPath(nameExpression.substring(10, nameExpression.length() - 1)); - } else if (nameExpression.startsWith(SynapseConstants.SIEL_IDENTIFIER_START) && - nameExpression.endsWith(SynapseConstants.SIEL_IDENTIFIER_END)) { - new Synapse_Path(nameExpression.substring(2, nameExpression.length() - 1)); + } else if (nameExpression.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) && + nameExpression.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) { + new SynapseExpression(nameExpression.substring(2, nameExpression.length() - 1)); } else { new SynapseXPath(nameExpression); } diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePath.java b/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePath.java index c66d4eb27f..811f349761 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePath.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePath.java @@ -4,6 +4,7 @@ import org.apache.axiom.om.xpath.AXIOMXPath; import org.apache.commons.logging.Log; import org.apache.synapse.MessageContext; +import org.apache.synapse.SynapseConstants; import org.apache.synapse.SynapseException; import org.apache.synapse.transport.util.MessageHandlerProvider; import org.apache.synapse.transport.passthru.PassThroughConstants; @@ -27,7 +28,7 @@ public abstract class SynapsePath extends AXIOMXPath { public static final String X_PATH = "X_PATH"; public static final String JSON_PATH = "JSON_PATH"; - public static final String SIEL_PATH = "SIEL_PATH"; + public static final String SYNAPSE_EXPRESSIONS_PATH = "SYNAPSE_EXPRESSIONS_PATH"; private String pathType = null; public DOMSynapseXPathNamespaceMap domNamespaceMap = new DOMSynapseXPathNamespaceMap(); @@ -62,8 +63,9 @@ public SynapsePath(String path, String pathType, Log log) throws JaxenException private String inferPathType(String expression) { if (expression.startsWith("json-eval(")) { return JSON_PATH; - } else if(expression.startsWith("#[") && expression.endsWith("]")) { - return SIEL_PATH; + } else if(expression.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) + && expression.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) { + return SYNAPSE_EXPRESSIONS_PATH; } else { return X_PATH; } diff --git a/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePathFactory.java b/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePathFactory.java index eccdf91bf1..d5195cd8bd 100644 --- a/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePathFactory.java +++ b/modules/core/src/main/java/org/apache/synapse/config/xml/SynapsePathFactory.java @@ -27,7 +27,7 @@ import org.apache.synapse.SynapseException; import org.apache.synapse.config.SynapsePropertiesLoader; import org.apache.synapse.util.xpath.SynapseJsonPath; -import org.apache.synapse.util.xpath.Synapse_Path; +import org.apache.synapse.util.xpath.SynapseExpression; import org.apache.synapse.util.xpath.SynapseXPath; import org.jaxen.JaxenException; @@ -50,9 +50,9 @@ public static org.apache.synapse.config.xml.SynapsePath getSynapsePath(OMElement if(pathAttrib.getAttributeValue().startsWith("json-eval(")) { path = new SynapseJsonPath(pathAttrib.getAttributeValue().substring(10, pathAttrib.getAttributeValue().length() - 1)); - } else if (pathAttrib.getAttributeValue().startsWith(SynapseConstants.SIEL_IDENTIFIER_START) && - pathAttrib.getAttributeValue().endsWith(SynapseConstants.SIEL_IDENTIFIER_END)) { - path = new Synapse_Path(pathAttrib.getAttributeValue().substring(2, pathAttrib.getAttributeValue().length() - 1)); + } else if (pathAttrib.getAttributeValue().startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) && + pathAttrib.getAttributeValue().endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) { + path = new SynapseExpression(pathAttrib.getAttributeValue().substring(2, pathAttrib.getAttributeValue().length() - 1)); } else { try { path = new SynapseXPath(pathAttrib.getAttributeValue()); diff --git a/modules/core/src/main/java/org/apache/synapse/mediators/Value.java b/modules/core/src/main/java/org/apache/synapse/mediators/Value.java index 9c8d9002b3..2cef385741 100644 --- a/modules/core/src/main/java/org/apache/synapse/mediators/Value.java +++ b/modules/core/src/main/java/org/apache/synapse/mediators/Value.java @@ -28,7 +28,7 @@ import org.apache.synapse.config.xml.SynapsePath; import org.apache.synapse.util.xpath.SynapseJsonPath; import org.apache.synapse.util.xpath.SynapseXPath; -import org.apache.synapse.util.xpath.Synapse_Path; +import org.apache.synapse.util.xpath.SynapseExpression; import org.jaxen.JaxenException; import java.util.ArrayList; @@ -103,9 +103,9 @@ public SynapsePath getExpression() { new SynapseJsonPath(expressionString.substring(10, expressionString.length() - 1)); expression = expressionTypeKey; - } else if (expressionString.startsWith(SynapseConstants.SIEL_IDENTIFIER_START) && - expressionString.endsWith(SynapseConstants.SIEL_IDENTIFIER_END)) { - expression = new Synapse_Path( + } else if (expressionString.startsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_START) && + expressionString.endsWith(SynapseConstants.SYNAPSE_EXPRESSION_IDENTIFIER_END)) { + expression = new SynapseExpression( expressionString.substring(2, expressionString.length() - 1)); } else { SynapseXPath expressionTypeKey = new SynapseXPath(expressionString); diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArgumentListNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArgumentListNode.java similarity index 90% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArgumentListNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArgumentListNode.java index e2f8f2bc61..4685beccfa 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArgumentListNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArgumentListNode.java @@ -15,9 +15,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; import java.util.ArrayList; import java.util.List; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArrayIndexNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArrayIndexNode.java similarity index 92% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArrayIndexNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArrayIndexNode.java index 72a42694f6..6f4b4bf7f8 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ArrayIndexNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ArrayIndexNode.java @@ -15,9 +15,9 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; import java.util.ArrayList; import java.util.List; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/BinaryOperationNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/BinaryOperationNode.java similarity index 97% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/BinaryOperationNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/BinaryOperationNode.java index 05b85b8bbb..977b2730a1 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/BinaryOperationNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/BinaryOperationNode.java @@ -15,10 +15,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; import java.util.function.BiFunction; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ConditionalExpressionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ConditionalExpressionNode.java similarity index 89% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ConditionalExpressionNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ConditionalExpressionNode.java index 20b9a5f35c..5b51405d60 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ConditionalExpressionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ConditionalExpressionNode.java @@ -16,10 +16,10 @@ * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; /** * Represents a conditional expression node ( a ? b : c ) in the AST. diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionNode.java similarity index 79% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionNode.java index bd3847ef43..f9f63358aa 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionNode.java @@ -16,10 +16,10 @@ * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; /** * Represents a node in the AST. diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionResult.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionResult.java similarity index 97% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionResult.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionResult.java index 83db46bae8..8dc0a60b55 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/ExpressionResult.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/ExpressionResult.java @@ -16,7 +16,7 @@ * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import com.google.gson.JsonArray; import com.google.gson.JsonElement; @@ -27,7 +27,7 @@ import com.google.gson.JsonSyntaxException; import com.google.gson.internal.LazilyParsedNumber; import org.apache.axiom.om.OMElement; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; /** * This class represents the result of an expression evaluation. @@ -60,6 +60,10 @@ public ExpressionResult(int value) { this.value = value; } + public ExpressionResult(Long value) { + this.value = value; + } + public ExpressionResult(double value) { this.value = value; } diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/FilterExpressionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/FilterExpressionNode.java similarity index 91% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/FilterExpressionNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/FilterExpressionNode.java index 0c176d32e4..35f0b1b2bd 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/FilterExpressionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/FilterExpressionNode.java @@ -15,10 +15,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.utils.ExpressionUtils; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.utils.ExpressionUtils; import java.util.Map; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/HeadersAndPropertiesAccessNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java similarity index 91% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/HeadersAndPropertiesAccessNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java index cd2b514b72..31af957dfc 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/HeadersAndPropertiesAccessNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java @@ -16,11 +16,11 @@ * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import org.apache.synapse.SynapseConstants; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; /** * Represents a node in the abstract syntax tree that provides access to headers and properties. diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/LiteralNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/LiteralNode.java similarity index 96% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/LiteralNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/LiteralNode.java index bd7f54e677..644d533744 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/LiteralNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/LiteralNode.java @@ -15,11 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; /** * Represents a leaf node in the AST that holds a literal value. diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PayloadAccessNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PayloadAccessNode.java similarity index 91% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PayloadAccessNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PayloadAccessNode.java index f133198fa4..6db2f2d5ae 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PayloadAccessNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PayloadAccessNode.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; @@ -35,9 +35,9 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.synapse.SynapseConstants; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; -import org.apache.synapse.util.synapse_path.utils.ExpressionUtils; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.utils.ExpressionUtils; import java.io.IOException; import java.util.EnumSet; @@ -155,6 +155,7 @@ public ExpressionResult evaluate(EvaluationContext context) { throw new EvaluationException(e.getMessage()); } break; + case ARRAY: case OBJECT: expression = expression.startsWith(".") ? "$" + expression : "$." + expression; ExpressionResult objFuncResult = predefinedFunctionNode.evaluate(context); @@ -164,15 +165,6 @@ public ExpressionResult evaluate(EvaluationContext context) { throw new EvaluationException(e.getMessage()); } break; - case ARRAY: - expression = "[" + arguments.get(SynapseConstants.ARRAY).evaluate(context).asString() + "]"; - ExpressionResult arrFuncResult = predefinedFunctionNode.evaluate(context); - try { - result = JsonPath.parse(arrFuncResult.asJsonElement()).read(expression); - } catch (PathNotFoundException e) { - throw new EvaluationException(e.getMessage()); - } - break; default: throw new EvaluationException("Unsupported type: " + type); } @@ -183,6 +175,16 @@ public ExpressionResult evaluate(EvaluationContext context) { return null; } else if (result instanceof JsonElement) { return new ExpressionResult((JsonElement) result); + } else if (result instanceof String) { + return new ExpressionResult((String) result); + } else if (result instanceof Integer) { + return new ExpressionResult((Integer) result); + } else if (result instanceof Long) { + return new ExpressionResult((Long) result); + } else if (result instanceof Double) { + return new ExpressionResult((Double) result); + } else if (result instanceof Boolean) { + return new ExpressionResult((Boolean) result); } return null; } diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PredefinedFunctionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java similarity index 98% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PredefinedFunctionNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java index 48d752d98b..bb89d3236b 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/PredefinedFunctionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java @@ -15,14 +15,14 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import com.google.gson.JsonArray; import com.google.gson.JsonPrimitive; import org.apache.synapse.SynapseConstants; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; -import org.apache.synapse.util.synapse_path.utils.ExpressionUtils; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.utils.ExpressionUtils; import org.jaxen.JaxenException; import java.io.UnsupportedEncodingException; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/SignedExpressionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/SignedExpressionNode.java similarity index 93% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/SignedExpressionNode.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/SignedExpressionNode.java index e5f2ec50b7..47a71d3822 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/ast/SignedExpressionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/SignedExpressionNode.java @@ -15,12 +15,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.ast; +package org.apache.synapse.util.synapse.expression.ast; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; /** * Represents a node in the AST that holds a signed expression. ex: ( -var.num1 ) diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/context/EvaluationContext.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/context/EvaluationContext.java similarity index 97% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/context/EvaluationContext.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/context/EvaluationContext.java index 65224bc853..046af271b1 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/context/EvaluationContext.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/context/EvaluationContext.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.context; +package org.apache.synapse.util.synapse.expression.context; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMNode; @@ -42,7 +42,7 @@ import static org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS; /** - * Represents the evaluation context of the SIEL expressions. + * Represents the evaluation context of the Synapse Expressions. * Which provides payload and headers access. */ public class EvaluationContext { diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/EvaluationException.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/EvaluationException.java similarity index 91% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/EvaluationException.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/EvaluationException.java index 34f9530e9e..cb3caf0654 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/EvaluationException.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/EvaluationException.java @@ -15,10 +15,10 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.exception; +package org.apache.synapse.util.synapse.expression.exception; /** - * Represents an exception that occurs during the evaluation of SIEL expressions. + * Represents an exception that occurs during the evaluation of Synapse Expressions. */ public class EvaluationException extends RuntimeException { public EvaluationException(String message) { diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxError.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxError.java similarity index 93% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxError.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxError.java index 77296c7644..8bc6d73f84 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxError.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxError.java @@ -15,12 +15,11 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.exception; +package org.apache.synapse.util.synapse.expression.exception; import org.antlr.v4.runtime.RecognitionException; - /** - * Represents an exception that occurs during the parsing of SIEL expressions. + * Represents an exception that occurs during the parsing of Synapse Expressions. */ public class SyntaxError { private final int line; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxErrorListener.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxErrorListener.java similarity index 96% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxErrorListener.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxErrorListener.java index a9f837a1b3..9b17496ae1 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/exception/SyntaxErrorListener.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/exception/SyntaxErrorListener.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.exception; +package org.apache.synapse.util.synapse.expression.exception; import org.antlr.v4.runtime.BaseErrorListener; import org.antlr.v4.runtime.RecognitionException; @@ -28,7 +28,7 @@ import java.util.logging.Logger; /** - * Represents a listener that captures syntax errors during the parsing of SIEL expressions. + * Represents a listener that captures syntax errors during the parsing of Synapse Expressions. */ public class SyntaxErrorListener extends BaseErrorListener { private boolean hasErrors = false; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/utils/ExpressionUtils.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/utils/ExpressionUtils.java similarity index 97% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/utils/ExpressionUtils.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/utils/ExpressionUtils.java index 7b9af85357..12e6a6c3eb 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/utils/ExpressionUtils.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/utils/ExpressionUtils.java @@ -16,12 +16,12 @@ * under the License. */ -package org.apache.synapse.util.synapse_path.utils; +package org.apache.synapse.util.synapse.expression.utils; import java.nio.charset.Charset; /** - * Utility class for SIEL expressions. + * Utility class for Synapse Expressions. */ public class ExpressionUtils { public static String escapeSpecialCharacters(String input) { diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/visitor/ExpressionVisitor.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java similarity index 63% rename from modules/core/src/main/java/org/apache/synapse/util/synapse_path/visitor/ExpressionVisitor.java rename to modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java index 194748eba6..8bdeec5a47 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse_path/visitor/ExpressionVisitor.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java @@ -15,20 +15,21 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path.visitor; +package org.apache.synapse.util.synapse.expression.visitor; import org.apache.synapse.SynapseConstants; -import org.apache.synapse.util.synapse_path.ExpressionParser; -import org.apache.synapse.util.synapse_path.ExpressionParserBaseVisitor; -import org.apache.synapse.util.synapse_path.ExpressionParserVisitor; -import org.apache.synapse.util.synapse_path.ast.*; +import org.apache.synapse.util.synapse.expression.ast.*; +import org.apache.synapse.util.synapse_expression.ExpressionParser; +import org.apache.synapse.util.synapse_expression.ExpressionParserBaseVisitor; +import org.apache.synapse.util.synapse_expression.ExpressionParserVisitor; import java.util.HashMap; import java.util.List; import java.util.Map; /** - * Represents a visitor that traverses the parse tree and constructs the abstract syntax tree (AST) of the SIEL + * Represents a visitor that traverses the parse tree and constructs the abstract syntax tree (AST) + * of the Synapse Expression. */ public class ExpressionVisitor extends ExpressionParserBaseVisitor implements ExpressionParserVisitor { @@ -138,92 +139,109 @@ public ExpressionNode visitFunctionCall(ExpressionParser.FunctionCallContext ctx parameterList.addArgument(visit(expressionContext)); } } - if (ctx.LENGTH() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.LENGTH); - } else if (ctx.TOUPPER() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.TO_UPPER); - } else if (ctx.TOLOWER() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.TO_LOWER); - } else if (ctx.SUBSTRING() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.SUBSTRING); - } else if (ctx.STARTSWITH() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.STARTS_WITH); - } else if (ctx.ENDSWITH() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.ENDS_WITH); - } else if (ctx.CONTAINS() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.CONTAINS); - } else if (ctx.TRIM() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.TRIM); - } else if (ctx.REPLACE() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.REPLACE); - } else if (ctx.SPLIT() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.SPLIT); - } else if (ctx.ABS() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.ABS); - } else if (ctx.CEIL() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.CEIL); - } else if (ctx.FLOOR() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.FLOOR); - } else if (ctx.SQRT() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.SQRT); - } else if (ctx.LOG() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.LOG); - } else if (ctx.POW() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.POW); - } else if (ctx.BASE64ENCODE() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.B64ENCODE); - } else if (ctx.BASE64DECODE() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.B64DECODE); - } else if (ctx.URLENCODE() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.URL_ENCODE); - } else if (ctx.URLDECODE() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.URL_DECODE); - } else if (ctx.ISSTRING() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_STRING); - } else if (ctx.ISNUMBER() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_NUMBER); - } else if (ctx.ISARRAY() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_ARRAY); - } else if (ctx.ISOBJECT() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_OBJECT); - } else if (ctx.STRING() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.STRING); - } else if (ctx.FLOAT() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.FLOAT); - } else if (ctx.BOOLEAN() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.BOOLEAN); - } else if (ctx.INTEGER() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.INTEGER); - } else if (ctx.ROUND() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.ROUND); - } else if (ctx.REGISTRY() != null) { - if (ctx.jsonPathExpression() != null && ctx.jsonPathExpression().getChildCount() > 0) { - PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, SynapseConstants.REGISTRY); - return visitJsonPathAfterPayload(ctx.jsonPathExpression(), node, PayloadAccessNode.Type.REGISTRY); + if (ctx.ID() != null) { + String functionName = ctx.ID().getText(); + switch (functionName) { + case SynapseConstants.LENGTH: + return new PredefinedFunctionNode(parameterList, SynapseConstants.LENGTH); + case SynapseConstants.TO_UPPER: + return new PredefinedFunctionNode(parameterList, SynapseConstants.TO_UPPER); + case SynapseConstants.TO_LOWER: + return new PredefinedFunctionNode(parameterList, SynapseConstants.TO_LOWER); + case SynapseConstants.SUBSTRING: + return new PredefinedFunctionNode(parameterList, SynapseConstants.SUBSTRING); + case SynapseConstants.STARTS_WITH: + return new PredefinedFunctionNode(parameterList, SynapseConstants.STARTS_WITH); + case SynapseConstants.ENDS_WITH: + return new PredefinedFunctionNode(parameterList, SynapseConstants.ENDS_WITH); + case SynapseConstants.CONTAINS: + return new PredefinedFunctionNode(parameterList, SynapseConstants.CONTAINS); + case SynapseConstants.TRIM: + return new PredefinedFunctionNode(parameterList, SynapseConstants.TRIM); + case SynapseConstants.REPLACE: + return new PredefinedFunctionNode(parameterList, SynapseConstants.REPLACE); + case SynapseConstants.SPLIT: + return new PredefinedFunctionNode(parameterList, SynapseConstants.SPLIT); + case SynapseConstants.ABS: + return new PredefinedFunctionNode(parameterList, SynapseConstants.ABS); + case SynapseConstants.CEIL: + return new PredefinedFunctionNode(parameterList, SynapseConstants.CEIL); + case SynapseConstants.FLOOR: + return new PredefinedFunctionNode(parameterList, SynapseConstants.FLOOR); + case SynapseConstants.SQRT: + return new PredefinedFunctionNode(parameterList, SynapseConstants.SQRT); + case SynapseConstants.LOG: + return new PredefinedFunctionNode(parameterList, SynapseConstants.LOG); + case SynapseConstants.POW: + return new PredefinedFunctionNode(parameterList, SynapseConstants.POW); + case SynapseConstants.B64ENCODE: + return new PredefinedFunctionNode(parameterList, SynapseConstants.B64ENCODE); + case SynapseConstants.B64DECODE: + return new PredefinedFunctionNode(parameterList, SynapseConstants.B64DECODE); + case SynapseConstants.URL_ENCODE: + return new PredefinedFunctionNode(parameterList, SynapseConstants.URL_ENCODE); + case SynapseConstants.URL_DECODE: + return new PredefinedFunctionNode(parameterList, SynapseConstants.URL_DECODE); + case SynapseConstants.IS_STRING: + return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_STRING); + case SynapseConstants.IS_NUMBER: + return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_NUMBER); + case SynapseConstants.IS_ARRAY: + return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_ARRAY); + case SynapseConstants.IS_OBJECT: + return new PredefinedFunctionNode(parameterList, SynapseConstants.IS_OBJECT); + case SynapseConstants.STRING: + return new PredefinedFunctionNode(parameterList, SynapseConstants.STRING); + case SynapseConstants.FLOAT: + return new PredefinedFunctionNode(parameterList, SynapseConstants.FLOAT); + case SynapseConstants.BOOLEAN: + return new PredefinedFunctionNode(parameterList, SynapseConstants.BOOLEAN); + case SynapseConstants.INTEGER: + return new PredefinedFunctionNode(parameterList, SynapseConstants.INTEGER); + case SynapseConstants.ROUND: + return new PredefinedFunctionNode(parameterList, SynapseConstants.ROUND); + case SynapseConstants.EXISTS: + return new PredefinedFunctionNode(parameterList, SynapseConstants.EXISTS); + case SynapseConstants.XPATH: + return new PredefinedFunctionNode(parameterList, SynapseConstants.XPATH); + case SynapseConstants.SECRET: + return new PredefinedFunctionNode(parameterList, SynapseConstants.SECRET); + case SynapseConstants.NOT: + return new PredefinedFunctionNode(parameterList, SynapseConstants.NOT); + case SynapseConstants.REGISTRY: + if (ctx.functionCallSuffix() != null) { + if (ctx.functionCallSuffix().jsonPathExpression() != null) { + PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, + SynapseConstants.REGISTRY); + return visitJsonPathAfterPayload(ctx.functionCallSuffix().jsonPathExpression(), + node, PayloadAccessNode.Type.REGISTRY); + } + } else { + return new PredefinedFunctionNode(parameterList, SynapseConstants.REGISTRY); + } + case SynapseConstants.OBJECT: + if (ctx.functionCallSuffix() != null) { + if (ctx.functionCallSuffix().jsonPathExpression() != null) { + PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, + SynapseConstants.OBJECT); + return visitJsonPathAfterPayload(ctx.functionCallSuffix().jsonPathExpression(), + node, PayloadAccessNode.Type.OBJECT); + } + } else { + return new PredefinedFunctionNode(parameterList, SynapseConstants.OBJECT); + } + case SynapseConstants.ARRAY: + if (ctx.functionCallSuffix() != null) { + if (ctx.functionCallSuffix().jsonPathExpression() != null) { + PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, + SynapseConstants.ARRAY); + return visitJsonPathAfterPayload(ctx.functionCallSuffix().jsonPathExpression(), + node, PayloadAccessNode.Type.ARRAY); + } + } else { + return new PredefinedFunctionNode(parameterList, SynapseConstants.ARRAY); + } } - return new PredefinedFunctionNode(parameterList, SynapseConstants.REGISTRY); - } else if (ctx.EXISTS() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.EXISTS); - } else if (ctx.OBJECT() != null) { - if (ctx.jsonPathExpression() != null && ctx.jsonPathExpression().getChildCount() > 0) { - PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, SynapseConstants.OBJECT); - return visitJsonPathAfterPayload(ctx.jsonPathExpression(), node, PayloadAccessNode.Type.OBJECT); - } - return new PredefinedFunctionNode(parameterList, SynapseConstants.OBJECT); - } else if (ctx.ARRAY() != null) { - if (ctx.arrayIndex() != null) { - PredefinedFunctionNode node = new PredefinedFunctionNode(parameterList, SynapseConstants.ARRAY); - Map expressionNodeMap = new HashMap<>(); - expressionNodeMap.put(SynapseConstants.ARRAY, visit(ctx.arrayIndex())); - return new PayloadAccessNode("", expressionNodeMap, PayloadAccessNode.Type.ARRAY, node); - } - return new PredefinedFunctionNode(parameterList, SynapseConstants.ARRAY); - } else if (ctx.XPATH() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.XPATH); - } else if (ctx.SECRET() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.SECRET); - } else if (ctx.NOT() != null) { - return new PredefinedFunctionNode(parameterList, SynapseConstants.NOT); } return null; } @@ -285,7 +303,7 @@ public Map visitJsonPath(ExpressionParser.JsonPathExpres } public ExpressionNode visitJsonPathAfterPayload(ExpressionParser.JsonPathExpressionContext ctx, - PredefinedFunctionNode functionNode, PayloadAccessNode.Type type) { + PredefinedFunctionNode functionNode, PayloadAccessNode.Type type) { Map expressionNodeMap = new HashMap<>(); if (ctx.arrayIndex() != null) { for (ExpressionParser.ArrayIndexContext expressionContext : ctx.arrayIndex()) { @@ -401,9 +419,9 @@ public ExpressionNode visitHeaderAccess(ExpressionParser.HeaderAccessContext ctx @Override public ExpressionNode visitPropertyName(ExpressionParser.PropertyNameContext ctx) { - if(ctx.ID() != null){ + if (ctx.ID() != null) { return new LiteralNode(ctx.ID().getText(), LiteralNode.Type.STRING); - } else if(ctx.STRING_LITERAL() != null){ + } else if (ctx.STRING_LITERAL() != null) { return new LiteralNode(ctx.STRING_LITERAL().getText(), LiteralNode.Type.STRING); } return null; @@ -421,17 +439,19 @@ public ExpressionNode visitConfigAccess(ExpressionParser.ConfigAccessContext ctx @Override public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessContext ctx) { if (ctx.propertyName() != null) { - if (ctx.AXIS2() != null) { - return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.AXIS2); - } else if (ctx.SYNAPSE() != null) { - return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), - SynapseConstants.SYNAPSE); - } else if (ctx.QUERY_PARAM() != null) { - return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), - SynapseConstants.QUERY_PARAM); - } else if (ctx.URI_PARAM() != null) { - return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), - SynapseConstants.URI_PARAM); + if (ctx.ID() != null) { + String scope = ctx.ID().getText(); + switch (scope) { + case SynapseConstants.AXIS2: + return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.AXIS2); + case SynapseConstants.SYNAPSE: + return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.SYNAPSE); + case SynapseConstants.QUERY_PARAM: + return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), + SynapseConstants.QUERY_PARAM); + case SynapseConstants.URI_PARAM: + return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.URI_PARAM); + } } } return null; diff --git a/modules/core/src/main/java/org/apache/synapse/util/xpath/Synapse_Path.java b/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseExpression.java similarity index 75% rename from modules/core/src/main/java/org/apache/synapse/util/xpath/Synapse_Path.java rename to modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseExpression.java index b074d1ac56..2993880f72 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/xpath/Synapse_Path.java +++ b/modules/core/src/main/java/org/apache/synapse/util/xpath/SynapseExpression.java @@ -28,33 +28,33 @@ import org.apache.synapse.SynapseConstants; import org.apache.synapse.config.xml.SynapsePath; -import org.apache.synapse.util.synapse_path.ExpressionLexer; -import org.apache.synapse.util.synapse_path.ExpressionParser; -import org.apache.synapse.util.synapse_path.ast.ExpressionNode; -import org.apache.synapse.util.synapse_path.ast.ExpressionResult; -import org.apache.synapse.util.synapse_path.context.EvaluationContext; -import org.apache.synapse.util.synapse_path.exception.EvaluationException; -import org.apache.synapse.util.synapse_path.exception.SyntaxErrorListener; -import org.apache.synapse.util.synapse_path.visitor.ExpressionVisitor; +import org.apache.synapse.util.synapse_expression.ExpressionLexer; +import org.apache.synapse.util.synapse_expression.ExpressionParser; +import org.apache.synapse.util.synapse.expression.ast.ExpressionNode; +import org.apache.synapse.util.synapse.expression.ast.ExpressionResult; +import org.apache.synapse.util.synapse.expression.context.EvaluationContext; +import org.apache.synapse.util.synapse.expression.exception.EvaluationException; +import org.apache.synapse.util.synapse.expression.exception.SyntaxErrorListener; +import org.apache.synapse.util.synapse.expression.visitor.ExpressionVisitor; import org.jaxen.JaxenException; import java.util.HashMap; import java.util.Map; /** - * Represents a SIEL path in Synapse. - * Syntax #[ + expression + ] ex: expression="#[vars.test + 5]" + * Represents a Synapse Expression + * Syntax ${ + expression + } ex: expression="${vars.test + 5}" */ -public class Synapse_Path extends SynapsePath { - private static final Log log = LogFactory.getLog(Synapse_Path.class); +public class SynapseExpression extends SynapsePath { + private static final Log log = LogFactory.getLog(SynapseExpression.class); private final ExpressionNode expressionNode; private EvaluationContext context; private final SyntaxErrorListener errorListener; public Map namespaceMap = new HashMap<>(); private boolean isContentAware = false; - public Synapse_Path(String SIELExpression) throws JaxenException { - super(SIELExpression, org.apache.synapse.config.xml.SynapsePath.JSON_PATH, log); + public SynapseExpression(String synapseExpression) throws JaxenException { + super(synapseExpression, org.apache.synapse.config.xml.SynapsePath.JSON_PATH, log); CharStream input = CharStreams.fromString(expression); ExpressionLexer lexer = new ExpressionLexer(input); @@ -68,11 +68,11 @@ public Synapse_Path(String SIELExpression) throws JaxenException { ExpressionVisitor visitor = new ExpressionVisitor(); expressionNode = visitor.visit(tree); if (errorListener.hasErrors()) { - throw new JaxenException("Syntax error in expression: " + SIELExpression); + throw new JaxenException("Syntax error in expression: " + synapseExpression); } // TODO : Need to improve the content aware detection logic - if (SIELExpression.contains("xpath(") || SIELExpression.contains("payload.") || SIELExpression.contains("$.")) { + if (synapseExpression.contains("xpath(") || synapseExpression.contains("payload.") || synapseExpression.contains("$.")) { isContentAware = true; } } diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/ConditionalExpressionTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/ConditionalExpressionTest.java similarity index 98% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/ConditionalExpressionTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/ConditionalExpressionTest.java index 522642a5a9..0f6c00a8f5 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/ConditionalExpressionTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/ConditionalExpressionTest.java @@ -16,7 +16,7 @@ * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.apache.synapse.SynapseConstants; import org.junit.Assert; diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/HeaderAndPropertyAccessTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java similarity index 81% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/HeaderAndPropertyAccessTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java index 3f6237466f..20827da7cb 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/HeaderAndPropertyAccessTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java @@ -15,12 +15,12 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.apache.synapse.commons.json.JsonUtil; import org.apache.synapse.core.axis2.Axis2MessageContext; import org.apache.synapse.mediators.TestUtils; -import org.apache.synapse.util.xpath.Synapse_Path; +import org.apache.synapse.util.xpath.SynapseExpression; import org.junit.Assert; import org.junit.Before; import org.junit.Test; @@ -108,89 +108,89 @@ public void setUp() throws Exception { @Test public void testTransportHeader() throws Exception { - Synapse_Path testPath = new Synapse_Path("headers.test"); + SynapseExpression testPath = new SynapseExpression("headers.test"); Assert.assertEquals("Hello World", testPath.stringValueOf(synCtx)); } @Test public void testTransportHeaderWithReservedName() throws Exception { - Synapse_Path testPath = new Synapse_Path("toLower(headers.[\"toUpper\"])"); + SynapseExpression testPath = new SynapseExpression("toLower(headers.[\"toUpper\"])"); Assert.assertEquals("hello world", testPath.stringValueOf(synCtx)); } @Test public void testTransportHeaderInFilter() throws Exception { - Synapse_Path testPath = new Synapse_Path("$..book[?(@.price > integer(headers.price))].title"); + SynapseExpression testPath = new SynapseExpression("$..book[?(@.price > integer(headers.price))].title"); Assert.assertEquals("[\"The Lord of the Rings\",\"To Kill a Mockingbird\"]", testPath.stringValueOf(synCtx)); } @Test public void testTransportHeaderWithSpecialChar() throws Exception { - Synapse_Path testPath = new Synapse_Path("toLower(headers.[\"te st\"]) + \" World\""); + SynapseExpression testPath = new SynapseExpression("toLower(headers.[\"te st\"]) + \" World\""); Assert.assertEquals("hello World", testPath.stringValueOf(synCtx)); } @Test public void testTransportHeaderNotExist() throws Exception { - Synapse_Path testPath = new Synapse_Path("headers[\"toUpper2\"]"); + SynapseExpression testPath = new SynapseExpression("headers[\"toUpper2\"]"); Assert.assertEquals(null, testPath.stringValueOf(synCtx)); } @Test public void testTransportHeaderNumerical() throws Exception { - Synapse_Path testPath = new Synapse_Path("integer(headers.numerical)+ 4"); + SynapseExpression testPath = new SynapseExpression("integer(headers.numerical)+ 4"); Assert.assertEquals("404", testPath.stringValueOf(synCtx)); } @Test public void testAxis2Header() throws Exception { - Synapse_Path testPath = new Synapse_Path("attr.axis2.test"); + SynapseExpression testPath = new SynapseExpression("attr.axis2.test"); Assert.assertEquals("Sic Mundus", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderWithExpression() throws Exception { - Synapse_Path testPath = new Synapse_Path("attributes.axis2.test + \" \" " + + SynapseExpression testPath = new SynapseExpression("attributes.axis2.test + \" \" " + "+ attributes.axis2.test2"); Assert.assertEquals("Sic Mundus Creatus Est", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderInFilter() throws Exception { - Synapse_Path testPath = new Synapse_Path("$..book[?(@.category == attributes.axis2.category)].title"); + SynapseExpression testPath = new SynapseExpression("$..book[?(@.category == attributes.axis2.category)].title"); Assert.assertEquals("[\"The Diary of a Young Girl\"]", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderWithReservedName() throws Exception { - Synapse_Path testPath = new Synapse_Path("attributes.axis2.[\"empty\"]"); + SynapseExpression testPath = new SynapseExpression("attributes.axis2.[\"empty\"]"); Assert.assertEquals("Thus the world was created", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeader() throws Exception { - Synapse_Path testPath = new Synapse_Path("attributes.synapse.phrase"); + SynapseExpression testPath = new SynapseExpression("attributes.synapse.phrase"); Assert.assertEquals("Now I Am Become Death, the Destroyer of Worlds", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeaderWithFunction() throws Exception { - Synapse_Path testPath = new Synapse_Path("length(split(attributes.synapse.phrase, \" \"))"); + SynapseExpression testPath = new SynapseExpression("length(split(attributes.synapse.phrase, \" \"))"); Assert.assertEquals("9", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeaderInFilter() throws Exception { - Synapse_Path testPath = new Synapse_Path("$..book[?(@.title == attributes.synapse.[\"selected book\"])].price"); + SynapseExpression testPath = new SynapseExpression("$..book[?(@.title == attributes.synapse.[\"selected book\"])].price"); Assert.assertEquals("[7.99]", testPath.stringValueOf(synCtx)); } @Test public void testNonExistingEmptyAndNull() throws Exception { - Synapse_Path testPath = new Synapse_Path("attributes.synapse.nonExisting"); + SynapseExpression testPath = new SynapseExpression("attributes.synapse.nonExisting"); Assert.assertEquals(null, testPath.stringValueOf(synCtx)); - testPath = new Synapse_Path("attributes.synapse.[\"null\"]"); + testPath = new SynapseExpression("attributes.synapse.[\"null\"]"); Assert.assertEquals(null, testPath.stringValueOf(synCtx)); - testPath = new Synapse_Path("attributes.synapse[\"empty\"]"); + testPath = new SynapseExpression("attributes.synapse[\"empty\"]"); Assert.assertEquals("", testPath.stringValueOf(synCtx)); } } diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PayloadAndVariableAccessTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PayloadAndVariableAccessTest.java similarity index 87% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/PayloadAndVariableAccessTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PayloadAndVariableAccessTest.java index 83dbe1f751..c4f78aa417 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PayloadAndVariableAccessTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PayloadAndVariableAccessTest.java @@ -16,7 +16,7 @@ * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.apache.synapse.SynapseConstants; import org.junit.Assert; import org.junit.Test; @@ -91,6 +91,25 @@ public void testJSONPath() { Assert.assertEquals("[\"John\",30,[\"Ford\",\"BMW\",\"Fiat\",\"Honda\",\"Lexus\",\"KIA\"],1," + "\" Hello World \",null,\"Ford\",\"BMW\",\"Fiat\",\"Honda\",\"Lexus\",\"KIA\"]", TestUtils.evaluateExpressionWithPayload("$..*", 1)); + // jsonPath functions + Assert.assertEquals("6", + TestUtils.evaluateExpressionWithPayload("$.store.book.length()", 2)); + Assert.assertEquals("6", + TestUtils.evaluateExpressionWithPayload("$.store.book.size()", 2)); + Assert.assertEquals("6.99", + TestUtils.evaluateExpressionWithPayload("$..price.min()", 2)); + Assert.assertEquals("22.99", + TestUtils.evaluateExpressionWithPayload("$..price.max()", 2)); + Assert.assertEquals("12", + TestUtils.evaluateExpressionWithPayload("round($..price.avg())", 2)); + Assert.assertEquals("6", + TestUtils.evaluateExpressionWithPayload("round($..price.stddev())", 2)); + Assert.assertEquals("Sayings of the Century", + TestUtils.evaluateExpressionWithPayload("object($.store.book.first()).title", 2)); + Assert.assertEquals("The Diary of a Young Girl", + TestUtils.evaluateExpressionWithPayload("object($.store.book.last()).title", 2)); + Assert.assertEquals("[\"category\",\"author\",\"title\",\"price\"]", + TestUtils.evaluateExpressionWithPayload("$.store.book.[0].keys()", 2)); } @Test diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PreDefinedFunctionsTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PreDefinedFunctionsTest.java similarity index 99% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/PreDefinedFunctionsTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PreDefinedFunctionsTest.java index b6a7cbed68..4fc1a0ddc7 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PreDefinedFunctionsTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PreDefinedFunctionsTest.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.apache.synapse.SynapseConstants; import org.junit.Assert; diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PrimitiveExpressionsTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PrimitiveExpressionsTest.java similarity index 99% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/PrimitiveExpressionsTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PrimitiveExpressionsTest.java index d003417b44..96cbea2989 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/PrimitiveExpressionsTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/PrimitiveExpressionsTest.java @@ -15,7 +15,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.apache.synapse.SynapseConstants; import org.junit.Assert; diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/SyntaxErrorsTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/SyntaxErrorsTest.java similarity index 86% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/SyntaxErrorsTest.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/SyntaxErrorsTest.java index fd4b161162..10184ee364 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/SyntaxErrorsTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/SyntaxErrorsTest.java @@ -15,17 +15,17 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; -import org.apache.synapse.util.synapse_path.exception.SyntaxError; -import org.apache.synapse.util.synapse_path.exception.SyntaxErrorListener; +import org.apache.synapse.util.synapse.expression.exception.SyntaxError; +import org.apache.synapse.util.synapse.expression.exception.SyntaxErrorListener; import org.junit.Assert; import org.junit.Test; import java.util.List; /** - * Test class for syntax errors in the SIEL language. + * Test class for syntax errors in the Synapse Expressions. */ public class SyntaxErrorsTest { diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/TestUtils.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/TestUtils.java similarity index 93% rename from modules/core/src/test/java/org/apache/synapse/util/synapse_path/TestUtils.java rename to modules/core/src/test/java/org/apache/synapse/util/synapse/expression/TestUtils.java index fd34628621..1e3a890d67 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse_path/TestUtils.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/TestUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package org.apache.synapse.util.synapse_path; +package org.apache.synapse.util.synapse.expression; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CharStreams; @@ -25,9 +25,11 @@ import org.apache.axis2.AxisFault; import org.apache.synapse.commons.json.JsonUtil; import org.apache.synapse.core.axis2.Axis2MessageContext; -import org.apache.synapse.util.synapse_path.exception.SyntaxErrorListener; -import org.apache.synapse.util.synapse_path.visitor.ExpressionVisitor; -import org.apache.synapse.util.xpath.Synapse_Path; +import org.apache.synapse.util.synapse.expression.exception.SyntaxErrorListener; +import org.apache.synapse.util.synapse.expression.visitor.ExpressionVisitor; +import org.apache.synapse.util.synapse_expression.ExpressionLexer; +import org.apache.synapse.util.synapse_expression.ExpressionParser; +import org.apache.synapse.util.xpath.SynapseExpression; import org.jaxen.JaxenException; @@ -35,7 +37,7 @@ import java.util.Map; /** - * Utility class for testing SIEL expressions. + * Utility class for testing Synapse Expressions. */ public class TestUtils { @@ -149,7 +151,7 @@ public static String evaluateExpressionWithPayloadAndVariables(String expression synCtx.setVariable(entry.getKey(), entry.getValue()); } } - Synapse_Path synapsePath = new Synapse_Path(expression); + SynapseExpression synapsePath = new SynapseExpression(expression); return synapsePath.stringValueOf(synCtx); } catch (JaxenException | AxisFault e) { throw new RuntimeException(e);