Use of WSO2 Enterprise Service Bus (ESB) Enrich Mediators for message mediation along with WSO2 Developer Studio
Basically this performs the process based on a given 'source' configuration and performs the action on that particular message using 'target' configuration.
Following properties are available in source and target configuraiton
Source Configuration
- Clone- By setting the clone configuration to 'True' or 'False' the message can be cloned or used as a reference during enriching.
- Type- The type that the mediator uses from the original message to enrich the modified message that passes through the mediator.
- Custom - Custom XPath value.
- Envelope - Envelope of the original message used for enriching.
- Body - Body of the original message used for enriching.
- Property - Specifies a property.
- Inline - Specifies an inline XML value.
- XPath Expression
Target Configuration
- Action- The relevant action can be applied to outgoing messages by specifying the action.
- Replace - Replace is the default value of Action. It will be used if a specific value for Action is not given. This replaces the XML message based on the target type specified on the target configuration.
- Child - Adding as a child of the specified target type.
- Sibling - Adding as a sibling of the specified target type.
Scenario
Let's assume that you are going to send a SOAP message through a proxy to the back end service. Lets assume you want to send CustomerID, RequestID, BookName and NoOfCopies to the proxy service and via that message you want to get a response from the back end service.
This is the soap message:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:heal="http://bookRequest.com">
<soapenv:Body>
<heal:setRequest>
<heal:customerID>123</heal:customerID>
<heal:requestID>100</heal:requestID>
<heal:bookName>Harry Potter</heal:bookName>
<heal:noOfCopies>3</heal:noOfCopies>
</heal:setRequest>
</soapenv:Body>
</soapenv:Envelope>
Now we can use four Property Mediators to grab these SOAP message as follows.
<property xmlns:heal="http://bookRequest.com" name="customerID" expression="//heal:setRequest/heal:customerID/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="requestID" expression="//heal:setRequest/heal:requestID/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="bookName" expression="//heal:setRequest/heal:movieName/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="noOfCopies" expression="//heal:setRequest/heal:noOfCopies/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="customerID" expression="//heal:setRequest/heal:customerID/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="requestID" expression="//heal:setRequest/heal:requestID/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="bookName" expression="//heal:setRequest/heal:movieName/text()" scope="default" type="STRING"/>
<property xmlns:heal="http://bookRequest.com" name="noOfCopies" expression="//heal:setRequest/heal:noOfCopies/text()" scope="default" type="STRING"/>
Then we can use four Enrich Mediators to grab this request, and another fifth Enrich Mediator to send this request to the back end service in a format where back end service accepts the request.
Lets assume this is the format which back end service accepts the request.
<body>
<p:setCustomerRequest xmlns:p="http://bookRequest">
<!--0 to 1 occurrence-->
<xs:customerID xmlns:xs="http://bookRequest">?</xs:customerID>
<!--0 to 1 occurrence-->
<xs:requestID xmlns:xs="http://bookRequest">?</xs:requestID>
<!--0 to 1 occurrence-->
<xs:bookName xmlns:xs="http://bookRequest">?</xs:bookName>
<!--0 to 1 occurrence-->
<xs:noOfCopies xmlns:xs="http://bookRequest">?</xs:noOfCopies>
</p:setCustomerRequest>
</body>
Then in the fifth Enrich Mediator we have to set the source to match with this format as below. We can set the target as 'body'
<source type="inline" clone="true">
<p:setCustomerRequest xmlns:p="http://bookRequest">
<xs:customerID xmlns:xs="http://bookRequest">x</xs:customerID>
<xs:requestID xmlns:xs="http://bookRequest">y</xs:requestID>
<xs:bookName xmlns:xs="http://bookRequest">z</xs:bookName>
<xs:noOfCopies xmlns:xs="http://bookRequest">0</xs:noOfCopies>
</p:setCustomerRequest>
</source>
<target type="body"/>
</enrich>
Now we can use four different Enrich Mediators to grab the SOAP request (source) and set those values in target in such a way to match with the source defined in the previous Enrich Mediator.
<enrich>
<source type="property" clone="true" property="customerID"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:customerID/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="requestID"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:requestID/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="bookName"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:bookName/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="noOfCopies"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:noOfCopies/text()"/>
</enrich>
Here in these Enrich Mediators we have referred previously defined Property Mediators.
<p:setCustomerRequest xmlns:p="http://bookRequest">
<xs:customerID xmlns:xs="http://bookRequest">x</xs:customerID>
<xs:requestID xmlns:xs="http://bookRequest">y</xs:requestID>
<xs:bookName xmlns:xs="http://bookRequest">z</xs:bookName>
<xs:noOfCopies xmlns:xs="http://bookRequest">0</xs:noOfCopies>
</p:setCustomerRequest>
</source>
<target type="body"/>
</enrich>
Now we can use four different Enrich Mediators to grab the SOAP request (source) and set those values in target in such a way to match with the source defined in the previous Enrich Mediator.
<enrich>
<source type="property" clone="true" property="customerID"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:customerID/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="requestID"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:requestID/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="bookName"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:bookName/text()"/>
</enrich>
<enrich>
<source type="property" clone="true" property="noOfCopies"/>
<target xmlns:p="http://bookRequest" xpath="//p:setCustomerRequest/p:noOfCopies/text()"/>
</enrich>
Here in these Enrich Mediators we have referred previously defined Property Mediators.
No comments:
Post a Comment