Throughout Membrane, certain plugins like:
support expressions written in Javascript, Groovy or SpEL.
When using Membranes scripting capabilities, a set of pre-defined attributes and APIs are available to provide access to useful information about the current context:
Outcomes are enums that depict the current state of the request/response flow.
Next to the enum class itself Outcome, the individual enum states are available as well.
| Outcome | Description |
|---|---|
| RETURN | Changes the direction of flow. The request handling mechanisms of the active plugins get activated. |
| CONTINUE | Continues the flow. |
| ABORT | Aborts the current flow, the direction is changed and the abort handling mechanisms of the active plugins get activated. |
The exc keyword grants access to the current Exchange object, housing request and response information.
The message keyword is a shortcut to exc.getRequest()/exc.getResponse().
Depending on direction of flow, message can stand for a request or response object.
The params keyword can be used to access request query parameters.
If the body of a message is of type application/json, json is a parsed JSON object representation of the body's JSON document.
The flow keyword houses the Flow enum. Values are REQUEST and RESPONSE.
These stand for the direction of flow.
The properties keyword is a shortcut to exc.getProperties().
The spring keyword grants access to Membrane's Spring ApplicationContext.
The following variables are available in SpEL expressions:
| Variable | Type | Description |
|---|---|---|
exchange | Exchange | Current exchange. |
message | Message | Current message depending on flow (request/response). |
body | Body | Message body |
headers / header | Map<String, Object> | Header map |
cookies / cookie | Map<String, Object> | Cookie map |
properties / property | Map<String, Object> | Exchange properties. |
params / param | Map<String, Object> | Query parameters. |
pathParam | Map<String, Object> | Path parameters from URI templates. |
path | String | Request path |
method | String | HTTP method |
statusCode | int | Response status code (if response exists). |
request | Request | Request wrapper. |
response | Response | Response wrapper. |
json | Map<String,Object> | Parsed JSON body as map. |
scopes | String | List of authentication scopes (may be null). |
flow | Flow | REQUEST or RESPONSE. |
Aliases: header=headers, cookie=cookies, property=properties, param=params.
| Signature | Description |
|---|---|
jsonPath(String jsonPath) → Object |
Runs JSONPath on decoded body; returns null on errors.Example: jsonPath('$.user.id') |
weight(double percent) → boolean |
Random boolean with given true probability (0–100%).Example: weight(10) |
isLoggedIn(String beanName) → boolean |
Verified session present for given interceptor bean? Example: isLoggedIn('loginInterceptor') |
getDefaultSessionLifetime(String beanName) → long |
Default session lifetime in seconds; -1 if unavailable.Example: getDefaultSessionLifetime('loginInterceptor') |
isBearerAuthorization() → boolean |
Authorization header starts with Bearer?Example: isBearerAuthorization() |
scopes() → List<String> |
All scopes from available security schemes. Example: scopes() |
scopes(String scheme) → List<String> |
Scopes for a scheme (http, apiKey, oauth2).Example: scopes('oauth2') |
hasScope(String scope) → boolean |
Scope present? Example: hasScope('admin') |
hasScope() → boolean |
At least one scope present. Example: hasScope() |
hasScope(List<String> scopes) → boolean |
Contains all given scopes. Example: hasScope({'read','write'}) |
isJSON() → boolean |
Message body is JSON. Example: isJSON() |
isXML() → boolean |
Message body is XML. Example: isXML() |
base64Encode(String s) → String |
Base64 encodes the input string. Example: base64Encode('string') |