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 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.
Info
The Property mediator is a conditionally content aware mediator.
Syntax¶
<property name="string" [action=set|remove] [type="string"] (value="literal" | expression="xpath") [scope=default|transport|axis2|axis2-client] [pattern="regex" [group="integer"]]>
<xml-element/>?
</property>
Configuration¶
The parameters available for configuring the Property mediator are as follows:
Parameter Name | Description |
---|---|
Name | A name for the property. You can provide a static value or a dynamic value for the property name. A dynamic property name can be retrieved by using an XPath function. You can use any of the XPath functions that you use for the property value or property expression. Note that the XPath function should be contained within curly brackets (
For names of the generic properties that come by default, see Generic Properties . You can select them from the drop-down list if you are adding the Property Mediator as shown below. |
Action | The action to be performed for the property.
|
Set Action As | The possible values for this parameter are as follows:
|
Type | 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. The |
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 |
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. |
Scope | The scope at which the property will be set or removed from. Possible values are as follows.
For a detailed explanation of each scope, see Accessing Properties with XPath. |
Note
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 Accessing Properties with XPath.
Examples¶
Setting and logging and property¶
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="$ctx:symbol"/>
</log>
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.
<payloadFactory media-type="xml">
<format>
<m:getQuote xmlns:m="http://services.samples">
<m:request>
<m:symbol>Error</m:symbol>
</m:request>
</m:getQuote>
</format>
</payloadFactory>
<property name="messageType" expression="$ctx:accept" scope="axis2" />
<respond/>
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')"/>
Info
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>')
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
).
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.
reg_xpath.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
Reading SOAP headers¶
SOAP headers provide information about the message, such as the To and From values. You can use the get-property()
function of the Property mediator to retrieve these headers. You can also add Custom SOAP Headers using the PayloadFactory mediator and the Script Mediator.
To¶
Property | Description |
---|---|
Header Name | To |
Possible Values | Any URI |
Description | The To header of the message. |
Example | get-property("To") |
From¶
Property | Description |
---|---|
Header Name | From |
Possible Values | Any URI |
Description | The From header of the message. |
Example | get-property("From") |
Action¶
Property | Description |
---|---|
Header Name | Action |
Possible Values | Any URI |
Description | The SOAPAction header of the message. |
Example | get-property("Action") |
ReplyTo¶
Property | Description |
---|---|
Header Name | ReplyTo |
Possible Values | Any URI |
Description | The ReplyTo header of the message. |
Example | <header name="ReplyTo" action="remove"/> |
MessageID¶
Property | Description |
---|---|
Header Name | MessageID |
Possible Values | UUID |
Description | The unique message ID of the message. It is not recommended to make alterations to this property of a message. |
Example | get-property("MessageID") |
RelatesTo¶
Property | Description |
---|---|
Header Name | RelatesTo |
Possible Values | UUID |
Description | The unique ID of the request to which the current message is related. It is not recommended to make changes. |
Example | get-property("RelatesTo") |
FaultTo¶
Property | Description |
---|---|
Header Name |
FaultTo |
Possible Values |
Any URI |
Description |
The FaultTo header of the message. |
Example |