Prerequisites.
WSO2 ESB.
In this post I'm
going to demonstrate how to use the ESB property mediator.
The property
mediator can use as a variable in programming language. We can set a
value in the property mediator and we can use it by property name in
other operations of the code.
In the following
example proxy , I added a property called “CompanyName” and used
it inside the log mediator .
Steps to add a
Property Mediator.
Go to design view of
your created proxy service.
Then click on Add
Child → Core → Property
Then you will get a
property mediator setting console as shown in below figure.
Name : A name for the property.
Action :
Using this we can set or remove a property from the message context.
Set Action as : If
you are setting a static value for the property then you need select
the Value option . If you are setting a dynamic
value for the property then you need to select Expression
option.
Type: Data
type of the property. (String,
Boolean, Integer, float, long etc.)
Value
: value of the
property. If you are setting a dynamic value for the property then
you need to use the Xpath expression here.
Ex:
If you need to set the Id as a property from following XML
response,
<project>
<id>10</id>
<name>WSO2
Governance Registry</name>
</project>
then
you need to set the
following Xpath as the
value.
//project/id
Pattern:
We can use regular expression here to evaluate value or expression of
the property.
After
adding the property then you can use it by property name in other
operations.
You
can retrieve the property value by using 'get-property('Name
of the Property')'.
In
the following example proxy I used the above property (CompanyName)
inside the log mediator.
Then the output is
as shown below.
<proxy name="Demo" startonload="true" statistics="disable" trace="disable" transports="https,http" xmlns="http://ws.apache.org/ns/synapse">
<target>
<insequence>
<property name="CompanyName" scope="default" type="STRING" value="WSO2">
<log>
<property expression="get-property('CompanyName')" name="Value_Of_Property">
</property></log>
</property></insequence>
</target>
<description>
</description></proxy>
References
[1].https://docs.wso2.com/display/ESB481/Property+Mediator
No comments:
Post a Comment