This site contains the documentation that is relevant to older WSO2 product versions and offerings.
For the latest WSO2 documentation, visit https://wso2.com/documentation/.
Property Mediator
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 get-property(prop-name)
extension function. If a property has a defined scope, you can set it as a transport header property, an (underlying) Axis2 message context property, or as a Axis2 client option. 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.
The following topics introduce different types of properties and how to configure the property mediator:
Property mediator configuration
Follow the instructions below to configure the Property mediator.
1. In the ESB Management Console, click the Sequences sub menu under Service Bus, and then click the Edit link associated with the sequence you want to edit.
2. The Edit Sequence window opens.
3. Click the Add Child button. A popup menu appears. From that, select Core and then select Property to open the Property Mediator window. (You might have to scroll down to view the window)
You have the following configuration under the Property Mediator.
- Name - A name for the property.
- Action- The action to do. Possible values are:
- Set - Adds a new property.
- Remove - Removes the property with the given name.
- Set Action As- Specifies which type of value to store. Possible values are:
- Value - A static text value.
- Expression - XPath or JSONPath expression to evaluate. When specifying a JSONPath, use the format
json-eval(<JSON_PATH>)
, such asjson-eval(getQuote.request.symbol)
. In both XPath and JSONPath expressions, you can return the value of another property by callingget-property(property-name)
. For example, you might create a property called JSON_PATH whose value isjson-eval(pizza.toppings)
, and then you could create another property called JSON_PRINT whose value isget-property('JSON_PATH')
, allowing you to use the value of the JSON_PATH property in the JSON_PRINT property. For more information on using JSON with the ESB, see JSON Support.
You can click the Namespaces link to add namespaces if you are providing an expression. You will be provided another panel named "Namespace Editor," where you can provide any number of namespace prefixes and URL that you have used in the expression.
- Type- Specifies the type of the property (default is STRING). Property mediator will handle the property as a property of selected type. Possible values are:
- STRING
- INTEGER
- BOOLEAN
- DOUBLE
- FLOAT
- LONG
- SHORT
OM
- Value/Expression
- Pattern - Specifies a regular expression that will be evaluated against the value of the property or result of the XPath/JSON Path expression.
- Group - Number (Index) of the matching item evaluated using regular expression given in "Pattern."
- Scope- Specifies the scope the property is valid. Possible values are:
- Synapse
- Transport
- Axis2
- axis2-client
4. Without using the UI, you can also configure the Property mediator using XML. Click the switch to source view link in the Mediator window and provide your configuration code.
Given below is an example configuration of the Property mediator.
Example
In this example, we are setting the property symbol and later we can log it using the Log Mediator.
<property name="symbol" expression="fn:concat("Normal Stock - ', //m0:getQuote/m0:request/m0:symbol)" xmlns:m0="http://services.samples/xsd"/> <log level="custom"> <property name="symbol" expression="get-property('symbol')"/> </log>
Properties reference
For a list of various types of properties supported in WSO2 ESB, their descriptions and use cases, refer to our Properties Reference.
Example 3: Reading a property stored in the Registry
You can read a property that is stored in the Registry by using the get-property()
method in your Synapse configuration. For example, the following Synapse configuration retrieves the abc
property of the collection gov:/data/xml/collectionx
, and stores it in the regProperty
property.
<property name="regProperty" expression="get-property('registry', 'gov:/data/xml/collectionx@abc')"/>
You can use the following syntaxes to read properties or resources stored in the gov
or conf
Registries. When specifying the path to the resource, do not give the absolute path. Instead, use the gov
or conf
prefixes.
Reading a property stored under a collection
get-property('registry','gov:<path to resource from governance>@<propertyname>')
get-property('registry','conf:<path to resource from config>@<propertyname>')
Reading a property stored under a resource
get-property('registry','gov:<path to resource from governance>/@<propertyname>')
get-property('registry','conf:<path to resource from config>/@<propertyname>')
Reading an XML resource
get-property('registry','gov:<path to resource from governance>')
get-property('registry','conf:<path to resource from config>')
Example 4: Reading a file stored in the Registry
Following is an example, in which you read an XML file that is stored in the registry using XPath, to retrieve a value from it. Assume you have the following XML file stored in the Registry (i.e., gov:/test.xml
).
<root> <book>A Song of Ice and Fire</book> <author>George R. R. Martin</author> </root>
Your Synapse configuration should be as follows. This uses XPath to read XML.
<property name="xmlFile" expression="get-property('registry','gov:/test.xml')" scope="default" type="OM"></property> <log level="custom"> <property name="Book_Name" expression="$ctx:xmlFile//book"></property> </log>
Your output log will look like this.
[2015-09-21 16:01:28,750] INFO - LogMediator Book_Name = A Song of Ice and Fire