Name
Expressions — expression configuration parameter values
Description
Expressions are specified as configuration parameter values for a number of built-in objects. Such expressions conform to the Universal Expression Language as specified in JSR-245.
General Syntax
All expressions follow standard Universal Expression Language syntax:
${expression}. The expression can be a simple reference to
a value, a function call, and/or arbitrarily complex arithmetic, logical,
relational and conditional operations. When supplied within a configuration
parameter, an expression is always a string enclosed in quotation marks, for
example: "${exchange.request.method}".
Value Expressions
A value expression references a value relative to the scope supplied to
the expression. In the current version of the gateway, the supplied scope is
always the HTTP exchange object. For example
"${exchange.request.method}" references the method of an
incoming HTTP request in the exchange scope. A
lvalue-expression is a specific type of value
expression, which references a value to be written. For example,
"${exchange.session.gotoURL}" specifies a session
attribute named gotoURL to write a value to. Attempts to
write values to read-only values are ignored.
Indexed Properties
Properties of values are accessed using the . and
[] operators, and can be nested arbitrarily. The value
expressions "${exchange.request}" and
"${exchange['request']}" are equivalent. In the case of
arrays, the index of an element in the array is expressed as a number in
brackets, for example
"${exchange.request.headers['Content-Type'][0]}"
references the first Content-Type header value in a
request. If a property does not exist, then the index reference yields a
null (empty) value.
Operations
Universal Expression Language supports arbitrarily complex arithmetic, logical, relational and conditional operations. They are, in order of precedence:
-
Index property value:
[],. -
Change precedence of operation:
() -
Unary negative:
- -
Logical operations:
not,!,empty -
Arithmetic operations:
*,/,div,%,mod -
Binary arithmetic operations:
+,- -
Relational operations:
<,>,<=,>=,lt,gt,le,ge,==,!=,eq,ne -
Logical operations:
&&,and,||,or -
Conditional operations:
?,:
Functions
A number of built-in functions can be called within an expression. Syntax is
${function(param, ...)}, where zero or more parameters
are supplied to the function. For example,
"${toLowerCase(exchange.request.method)}" yields the
method of the request, converted to lower case. Functions can be operands
for operations, and can yield parameters for other function calls.
Examples
Lines are folded for readability in these example. In your JSON, keep the values on one line.
"${exchange.request.uri.path == '/wordpress/wp-login.php' and
exchange.request.form['action'][0] != 'logout'}"
"${exchange.request.uri.host 'wiki.example.com'}"
"${exchange.request.cookies[keyMatch(exchange.request.cookies,'^SESS.*')][0]
.value}"
"${toString(exchange.request.uri)}"
"${exchange.request.uri.value}"
"${exchange.request.method 'POST' and exchange.request.uri.path
'/wordpress/wp-login.php'}"
"${exchange.request.method 'GET'}"
"${exchange.request.headers['cookie'][0]}"
"${exchange.request.uri.scheme 'http'}"
"${not (exchange.response.status 302 and not empty exchange.session.gotoURL)}"
"${exchange.response.headers['Set-Cookie'][0]}"
"${exchange.request.headers['host'][0]}"
