Select configuration values at runtime

A selector is a special syntax that enables API Gateway configuration settings to be evaluated and expanded at runtime based on metadata values (for example, from message attributes, a Key Property Store (KPS), or environment variables).

5 minute read

The selector syntax uses the Java Unified Expression Language (JUEL) to evaluate and expand the specified values. Selectors provide a powerful feature when integrating with other systems or when customizing and extending the API Gateway.

When you press the Shift key and open a filter, you can edit all filter settings using text values in the advanced filter view. This means that you can specify all filter fields using the API Gateway selector syntax. For more details on the advanced view, see Advanced options.

Selector syntax

The API Gateway selector syntax uses JUEL to evaluate and expand the following types of values at runtime:

Message attribute properties configured in message filters, for example:


Environment variables specified in envSettings.props and files, for example:


Values stored in a KPS table, for example:


Access selector fields

A message attribute selector can refer to a field of that message (for example certificate), and you can use . characters to access subfields. For example, the following selector expands to the username field of the object stored in the profile attribute in the message:


You can also access fields indirectly using square brackets ([and ]). For example, the following selector is equivalent to the previous example:


You can specify literal strings as follows:

${profile["a field name with spaces"]}

For example, the following selector uses the key value to look up the User table in the KPS, and returns the value of the age property:


Special selector keys

The following top-level keys have a special meaning:

kps: Subfields of the kps key reflect the alias names of KPS tables in the API Gateway group. Further indexes represent properties of an object in a table (for example, ${kps.User[""].age}).

env, system: In previous versions, fields from the envSettings.props and files had restrictions on prefixes. The selector syntax does not require the envand system prefixes in these files. For example, ${env. selects settings from envSettings.props, and the rest of the selector chooses any properties in it. However, for compatibility, if a setting in either file starts with this prefix, it is stripped away so the selectors still behave correctly with previous versions.

Resolve selectors

Each ${...} selector string is resolved step-by-step, passing an initial context object (for example, Message). The top-level key is offered to the context object, and if it resolves the field (for example, the message contains the named attribute), the resolved object is indexed with the next level of key. At each step, the following rules apply:

  1. At the top level, test the key for the global values (for example, kps, system, and env) and resolve those specially.
  2. If the object being indexed is a Dictionary, KPS, or Map, use the index as a key for the item’s normal indexing mechanism, and return the resulting lookup.
  3. If all else fails, attempt Java reflection on the indexed object.

Example selector expressions

This section lists some example selectors that use expressions to evaluate and expand their values at runtime.

Message attribute

The following message attribute selector returns the HTTP User-Agent header:


For example, this might expand to the following value:

Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.7 (KHTML, like Gecko) Chrome/16.0.912.77 Safari/535.7

Environment variable

In a default configuration, the following environment variable selector returns port 8091:


Key Property Store

The following selector looks up a KPS table with an alias of User:


This selector retrieves the object whose Policy Studio key value is specified by the id query parameter in the incoming HTTP request, and returns the value of the firstName property in that object.

The following selector explicitly provides the key value, and returns the value of the age property:


In this example, the ASCII " character is used to delimit the key string.

The following selector looks up a KPS table with a composite secondary key of firstName,lastName:


In this example, the key values are received as query parameters in the incoming HTTP request. The selector returns the value of the email property from the resulting object.

Examples using reflection

The following message attribute selector returns the CGI argument from an HTTP URL (for example, returns bar for http://localhost/request.cgi?foo=bar):


This returns the name of the top-level element in an XML document:


This returns true if the HTTP response code lies between 200 and 299:

${http.response.status >= 200 && http.response.status <= 299}

Extract message attributes

There are a number of API Gateway filters that extract message attribute values (for example, Extract Certificate Attributes and Retrieve from HTTP Header). Using selectors to extract message attributes offers a more flexible alternative to using such filters. For more details on using selectors instead of these filters, contact Axway Support.