The Property Mediator has no direct impact on the message, but rather on the message context flowing through Synapse. You can retrieve the properties set on a message later through the Synapse XPath Variables or the
get-property() extension function. A property can have a defined scope for which it is valid. If a property has no defined scope, it defaults to the Synapse message context scope. Using the property element with the action specified as
remove, you can remove any existing message context properties.
See Properties Reference for a list of various types of properties supported by WSO2 ESB with descriptions and use cases.
The Property mediator is a conditionally content aware mediator.
The parameters available for configuring the Property mediator are as follows:
|Name||A name for the property.|
The action to be performed for the property.
|Set Action As|
The possible values for this parameter are as follows:
The data type for the property. Property mediator will handle the property as a property of selected type. Available values are as follows.
String is the default type.
|Value||If the Value option is selected for the Set Action As parameter, the property value should be entered as a constant in this parameter.|
|Expression||If the Expression option is selected for the Set Action As parameter, the expression which determines the property value should be entered in this parameter. This expression can be an XPath expression or a JSONPath expression. |
When specifying a JSONPath, use the format
You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression.
|Pattern||This parameter is used to enter a regular expression that will be evaluated against the value of the property or result of the XPath/JSON Path expression.|
|Group||The number (index) of the matching item evaluated using the regular expression entered in the Pattern parameter.|
The scope at which the property will be set or removed from. Possible values are as follows.
See XPath Extension Functions for a detailed explanation of each scope.
You can configure the mediator using XML. Click switch to source view in the Mediator window.
Example 1: Setting and logging and property
In this example, we are setting the property symbol and later we can log it using the Log Mediator.
Example 2: Sending a fault message based on the Accept http header
In this configuration, a response is sent to the client based on the
Accept header. The PayloadFactory mediator transforms the message contents. Then a Property mediator sets the message type based on the
Accept header using the
$ctx:accept expression. The message is then sent back to the client via the Respond mediator.
There are predefined XPath variables (such as
$ctx) that you can directly use in the Synapse configuration, instead of using the synapse:get-property() function. These XPath variables get properties of various scopes and have better performance than the get-property() function, which can have much lower performance because it does a registry lookup. These XPath variables get properties of various scopes. For more information on these XPath variables, see Synapse XPath Variables.