Property mediator helps us to access various information of a message ,which passes through ESB. Within a sequence , we could use property mediator to get info about a message.
We can assign a value to a property as a string value or using xpath expression. Two actions are defined for property mediator.
We can use supported xpath functions,such as mathematical/logical operations and other predefined functions can be used to assign values in the property mediator.
eg:
<property xmlns:ns="http://org.apache.synapse/xsd" name="testProp"
expression="fn:concat('hello','world')" scope="default"/>
We can use built in get-property() xpath function to read properties,which are available in the synapse messagecontext.
Eg: If a property "SYSTEM_TIME" available in the synapse message context;
We can use property mediator to set values in different scopes, which can be accessed in those specific scope. There are 4 scopes,which are;
<property name="myProp" value="abc" scope="default" type="STRING"/>
<property name="myProp" value="abc" scope="transport" type="STRING"/>
<property name="myProp" value="abc" scope="axis2" type="STRING"/>
<property name="myProp" value="abc" scope="axis2-client" type="STRING"/>
When we retrieve properties from a specific scope;
eg:
There are some predefined xpath properties , which we can use directly to retrieve some common properties.
<property name="MessageType is" expression="$axis2:messageType"/>
<property name="axis2Prop" expression="$trp:Content-Type"/>
If we have a property named as "myProp" in synapse scope, which can be retrieved in the following manner;
<property name="testProp" expression="$ctx:myProp"/>
For a request url; http:// localhost:8280/getSimpleQuote?symbol=IBM
<property name="symbol" expression="$url:symbol"/>
The above will retrieve the symbol value; ie:IBM
We can assign a value to a property as a string value or using xpath expression. Two actions are defined for property mediator.
- Set
- Remove
<property name="MESSAGE" value="Executing in sequence"/>
<property xmlns:m="http://sample.com" name="test" expression="//m:getQuote/m:symbol"
scope="default" type="STRING"/>
<property xmlns:m="http://sample.com" name="test" expression="//m:getQuote/m:symbol"
scope="default" type="STRING"/>
We can use supported xpath functions,such as mathematical/logical operations and other predefined functions can be used to assign values in the property mediator.
eg:
<property xmlns:ns="http://org.apache.synapse/xsd" name="testProp"
expression="fn:concat('hello','world')" scope="default"/>
We can use built in get-property() xpath function to read properties,which are available in the synapse messagecontext.
Eg: If a property "SYSTEM_TIME" available in the synapse message context;
<property xmlns:ns="http://org.apache.synapse/xsd" name="systemtime"
expression="get-property('SYATEM_TIME')" scope="default"/>
expression="get-property('SYATEM_TIME')" scope="default"/>
We can use property mediator to set values in different scopes, which can be accessed in those specific scope. There are 4 scopes,which are;
- synapse/default : This property will be available in both insequence and outsequence.
- axis2 : This property will be available in the particular sequence. can be retrieved from Axsi2Messagecontext.
- transport: This scope is used to set a property in the transport header.
- axis2-client: Like "axis2" scope, but can be retrieved form the Axis2Messagecontext.options.
<property name="myProp" value="abc" scope="default" type="STRING"/>
<property name="myProp" value="abc" scope="transport" type="STRING"/>
<property name="myProp" value="abc" scope="axis2" type="STRING"/>
<property name="myProp" value="abc" scope="axis2-client" type="STRING"/>
When we retrieve properties from a specific scope;
eg:
<property xmlns:ns="http://org.apache.synapse/xsd" name="remotehost"
expression="get-property('axis2', 'REMOTE_HOST')"/>
expression="get-property('axis2', 'REMOTE_HOST')"/>
There are some predefined xpath properties , which we can use directly to retrieve some common properties.
- $axis2: Used to get the property at the axis2 scope.
<property name="MessageType is" expression="$axis2:messageType"/>
- $trp: Used to get transport header properties.
<property name="axis2Prop" expression="$trp:Content-Type"/>
- $ctx : Used to get synapse scope properties;
If we have a property named as "myProp" in synapse scope, which can be retrieved in the following manner;
<property name="testProp" expression="$ctx:myProp"/>
- $url : Used to retrieve parameters defined in the url
For a request url; http:// localhost:8280/getSimpleQuote?symbol=IBM
<property name="symbol" expression="$url:symbol"/>
The above will retrieve the symbol value; ie:IBM