diff --git a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 index 6e2a4030bc..5429268c0d 100644 --- a/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 +++ b/modules/core/src/main/antlr4/org/apache/synapse/util/synapse_expression/ExpressionLexer.g4 @@ -9,7 +9,8 @@ VAR: 'var'; PAYLOAD: 'payload' | '$'; HEADERS: 'headers'; CONFIG: 'config'; -ATTRIBUTES: 'attributes' | 'attr'; +PARAMS: 'params'; +PROPERTY: 'props' | 'properties'; AND: 'and' | '&&'; OR: 'or' | '||'; NOT: '!'; 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 index 38ae834964..17883993b2 100644 --- 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 @@ -38,7 +38,8 @@ factor | payloadAccess | headerAccess | configAccess - | attributeAccess + | parameterAccess + | propertyAccess | LPAREN expression RPAREN ; @@ -50,8 +51,12 @@ headerAccess : HEADERS propertyName ; -attributeAccess - : ATTRIBUTES (DOT ID propertyName) +parameterAccess + : PARAMS (DOT ID propertyName) + ; + +propertyAccess + : PROPERTY (DOT ID propertyName) ; propertyName @@ -126,7 +131,8 @@ filterComponent | payloadAccess | headerAccess | configAccess - | attributeAccess + | parameterAccess + | propertyAccess | functionCall | stringOrOperator ; @@ -144,4 +150,4 @@ functionCall functionCallSuffix : DOT ID LPAREN (expression (COMMA expression)*)? RPAREN // Method chaining | jsonPathExpression - ; \ No newline at end of file + ; diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java index f522e1cc2a..75cbd7c4d2 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/visitor/ExpressionVisitor.java @@ -125,8 +125,10 @@ public ExpressionNode visitFactor(ExpressionParser.FactorContext ctx) { return visit(ctx.headerAccess()); } else if (ctx.configAccess() != null) { return visit(ctx.configAccess()); - } else if (ctx.attributeAccess() != null) { - return visit(ctx.attributeAccess()); + } else if (ctx.propertyAccess() != null) { + return visit(ctx.propertyAccess()); + } else if (ctx.parameterAccess() != null) { + return visit(ctx.parameterAccess()); } return null; } @@ -410,8 +412,10 @@ public ExpressionNode visitFilterComponent(ExpressionParser.FilterComponentConte return visit(ctx.headerAccess()); } else if (ctx.configAccess() != null) { return visit(ctx.configAccess()); - } else if (ctx.attributeAccess() != null) { - return visit(ctx.attributeAccess()); + } else if (ctx.propertyAccess() != null) { + return visit(ctx.propertyAccess()); + } else if (ctx.parameterAccess() != null) { + return visit(ctx.parameterAccess()); } return null; } @@ -445,7 +449,7 @@ public ExpressionNode visitConfigAccess(ExpressionParser.ConfigAccessContext ctx } @Override - public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessContext ctx) { + public ExpressionNode visitPropertyAccess(ExpressionParser.PropertyAccessContext ctx) { if (ctx.propertyName() != null) { if (ctx.ID() != null) { String scope = ctx.ID().getText(); @@ -454,6 +458,18 @@ public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessConte return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), ExpressionConstants.AXIS2); case SynapseConstants.SYNAPSE: return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), SynapseConstants.SYNAPSE); + } + } + } + return null; + } + + @Override + public ExpressionNode visitParameterAccess(ExpressionParser.ParameterAccessContext ctx) { + if (ctx.propertyName() != null) { + if (ctx.ID() != null) { + String scope = ctx.ID().getText(); + switch (scope) { case ExpressionConstants.QUERY_PARAM: return new HeadersAndPropertiesAccessNode(visit(ctx.propertyName()), ExpressionConstants.QUERY_PARAM); @@ -468,6 +484,7 @@ public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessConte return null; } + @Override public ExpressionNode visitConditionalExpression(ExpressionParser.ConditionalExpressionContext ctx) { ExpressionNode condition = null; diff --git a/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java index feb53c1186..26c33b8557 100644 --- a/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java +++ b/modules/core/src/test/java/org/apache/synapse/util/synapse/expression/HeaderAndPropertyAccessTest.java @@ -144,53 +144,53 @@ public void testTransportHeaderNumerical() throws Exception { @Test public void testAxis2Header() throws Exception { - SynapseExpression testPath = new SynapseExpression("attr.axis2.test"); + SynapseExpression testPath = new SynapseExpression("props.axis2.test"); Assert.assertEquals("Sic Mundus", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderWithExpression() throws Exception { - SynapseExpression testPath = new SynapseExpression("attributes.axis2.test + \" \" " + - "+ attributes.axis2.test2"); + SynapseExpression testPath = new SynapseExpression("properties.axis2.test + \" \" " + + "+ props.axis2.test2"); Assert.assertEquals("Sic Mundus Creatus Est", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderInFilter() throws Exception { - SynapseExpression testPath = new SynapseExpression("$..book[?(@.category == attributes.axis2.category)].title"); + SynapseExpression testPath = new SynapseExpression("$..book[?(@.category == props.axis2.category)].title"); Assert.assertEquals("[\"The Diary of a Young Girl\"]", testPath.stringValueOf(synCtx)); } @Test public void testAxis2HeaderWithReservedName() throws Exception { - SynapseExpression testPath = new SynapseExpression("attributes.axis2.[\"empty\"]"); + SynapseExpression testPath = new SynapseExpression("props.axis2.[\"empty\"]"); Assert.assertEquals("Thus the world was created", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeader() throws Exception { - SynapseExpression testPath = new SynapseExpression("attributes.synapse.phrase"); + SynapseExpression testPath = new SynapseExpression("props.synapse.phrase"); Assert.assertEquals("Now I Am Become Death, the Destroyer of Worlds", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeaderWithFunction() throws Exception { - SynapseExpression testPath = new SynapseExpression("length(split(attributes.synapse.phrase, \" \"))"); + SynapseExpression testPath = new SynapseExpression("length(split(properties.synapse.phrase, \" \"))"); Assert.assertEquals("9", testPath.stringValueOf(synCtx)); } @Test public void testSynapseHeaderInFilter() throws Exception { - SynapseExpression testPath = new SynapseExpression("$..book[?(@.title == attributes.synapse.[\"selected book\"])].price"); + SynapseExpression testPath = new SynapseExpression("$..book[?(@.title == props.synapse.[\"selected book\"])].price"); Assert.assertEquals("[7.99]", testPath.stringValueOf(synCtx)); } @Test public void testNonExistingEmptyAndNull() throws Exception { - SynapseExpression testPath = new SynapseExpression("attributes.synapse.nonExisting"); + SynapseExpression testPath = new SynapseExpression("props.synapse.nonExisting"); Assert.assertNull(testPath.stringValueOf(synCtx)); - testPath = new SynapseExpression("attributes.synapse.[\"null\"]"); + testPath = new SynapseExpression("props.synapse.[\"null\"]"); Assert.assertNull(testPath.stringValueOf(synCtx)); - testPath = new SynapseExpression("attributes.synapse[\"empty\"]"); + testPath = new SynapseExpression("props.synapse[\"empty\"]"); Assert.assertEquals("", testPath.stringValueOf(synCtx)); } }