Skip to content

Commit

Permalink
Add path and query param support
Browse files Browse the repository at this point in the history
Add path and query param support
  • Loading branch information
GDLMadushanka committed Nov 7, 2024
1 parent 01a7992 commit e33a6e7
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ CONFIG: 'config';
ATTRIBUTES: 'attributes' | 'attr';
AXIS2: 'axis2';
SYNAPSE: 'synapse';
QUERY_PARAM: 'queryParams';
URI_PARAM: 'uriParams';
REGISTRY: 'registry';
SECRET: 'secret';
BASE64ENCODE: 'base64encode';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ headerName
;

attributeAccess
: ATTRIBUTES (DOT AXIS2 DOT propertyName // Access syntax for attributes.axis2.property
| DOT SYNAPSE DOT propertyName) // Access syntax for attributes.synapse.property
: ATTRIBUTES (DOT AXIS2 DOT propertyName
| DOT SYNAPSE DOT propertyName
| DOT QUERY_PARAM DOT propertyName
| DOT URI_PARAM DOT propertyName)
;

propertyName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,8 @@ public enum ENDPOINT_TIMEOUT_TYPE { ENDPOINT_TIMEOUT, GLOBAL_TIMEOUT, HTTP_CONNE
public static final String SIEL_IDENTIFIER_START = "#[";
public static final String SIEL_IDENTIFIER_END = "]";
public static final String AXIS2 = "axis2";
public static final String QUERY_PARAM = "queryParams";
public static final String URI_PARAM = "uriParams";

public static final String UNKNOWN = "unknown";
public static final String VAULT_LOOKUP = "wso2:vault-lookup('";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ private boolean isDouble(JsonPrimitive jsonPrimitive) {
Number number = jsonPrimitive.getAsNumber();
// Check if the number is an instance of floating-point types (float, double)
boolean initialCheck = number instanceof Float || number instanceof Double;
if (!initialCheck && number instanceof LazilyParsedNumber) {
if (initialCheck) {
return true;
}
if (number instanceof LazilyParsedNumber) {
// Check if the number is an instance of integer types (int, long, short)
String numberString = number.toString();
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

package org.apache.synapse.util.synapse_path.ast;

import org.apache.synapse.SynapseConstants;
import org.apache.synapse.util.synapse_path.context.EvaluationContext;
import org.apache.synapse.util.synapse_path.exception.EvaluationException;

Expand All @@ -30,7 +31,9 @@ public class HeadersAndPropertiesAccessNode implements ExpressionNode {
public enum Type {
HEADER,
PROPERTY,
CONFIG
CONFIG,
QUERY_PARAM,
PATH_PARAM
}

private final Type type;
Expand All @@ -55,10 +58,16 @@ public ExpressionResult evaluate(EvaluationContext context) {
if (key != null) {
String name = key.evaluate(context).asString();
Object value;
if (type.equals(Type.HEADER)) {
if (Type.HEADER.equals(type)) {
value = context.getHeader(name);
} else {
value = context.getProperty(name, scope);
if (SynapseConstants.URI_PARAM.equals(scope)) {
value = context.getProperty("uri.var." + name, SynapseConstants.SYNAPSE);
} else if (SynapseConstants.QUERY_PARAM.equals(scope)) {
value = context.getProperty("query.param." + name, SynapseConstants.SYNAPSE);
} else {
value = context.getProperty(name, scope);
}
}
return new ExpressionResult(value != null ? value.toString() : null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,12 @@ public ExpressionNode visitAttributeAccess(ExpressionParser.AttributeAccessConte
} 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);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ public void testOr() {

@Test
public void testAdd() {
Assert.assertEquals("8.5", TestUtils.evaluateExpression("5.5 + 3"));
Assert.assertEquals("7", TestUtils.evaluateExpression("5 + 3 + -1"));
Assert.assertEquals("8.5", TestUtils.evaluateExpression("5.5 + 3"));
Assert.assertEquals("9.0", TestUtils.evaluateExpression("5.5 + 3.5"));
Expand Down

0 comments on commit e33a6e7

Please sign in to comment.