diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java index 42fc3d944a..5c20445b56 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/HeadersAndPropertiesAccessNode.java @@ -25,6 +25,8 @@ import org.apache.synapse.util.synapse.expression.context.EvaluationContext; import org.apache.synapse.util.synapse.expression.exception.EvaluationException; +import java.math.BigDecimal; + /** * Represents a node in the abstract syntax tree that provides access to headers and properties. */ @@ -80,11 +82,31 @@ public ExpressionResult evaluate(EvaluationContext context, boolean isObjectValu } } if (value != null) { - return new ExpressionResult(value.toString()); + return tryParseNumber(value.toString()); } else { throw new EvaluationException("Could not fetch the value of the key: " + name); } } throw new EvaluationException("Key cannot be null when accessing headers or properties"); } + + + private ExpressionResult tryParseNumber(String value) { + try { + return new ExpressionResult(Integer.parseInt(value)); + } catch (NumberFormatException e1) { + try { + return new ExpressionResult(Long.parseLong(value)); + } catch (NumberFormatException e2) { + try { + Double.parseDouble(value); + // if double stored as big decimal, for accurate calculations + return new ExpressionResult(new BigDecimal(value)); + } catch (NumberFormatException e3) { + return new ExpressionResult(value); + } + } + } + } + } diff --git a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java index 60b8a5b0ac..03855c3dc6 100644 --- a/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java +++ b/modules/core/src/main/java/org/apache/synapse/util/synapse/expression/ast/PredefinedFunctionNode.java @@ -529,8 +529,12 @@ private ExpressionResult handleBase64EncodeFunction(ExpressionResult source, Exp private ExpressionResult handleUrlEncodeFunction(ExpressionResult source, ExpressionResult argument1) { if (source.isString() && argument1.isString()) { try { - return new ExpressionResult(URLEncoder.encode(source.asString(), ExpressionUtils.getCharset( - argument1.asString())).replace("+", "%20").replace("*", "%2A")); + String result = URLEncoder.encode(source.asString(), ExpressionUtils.getCharset(argument1.asString())); + if (argument1.asString().equals("UTF-8")) { + return new ExpressionResult(result.replace("+", "%20").replace("*", "%2A")); + } else { + return new ExpressionResult(result); + } } catch (UnsupportedCharsetException e) { throw new EvaluationException("Invalid charset provided for urlEncode function. Charset: " + argument1.asString());