I am going to explain you a typical scenario where you have to manipulate the incoming message
into WSO2 ESB proxy service.
Proxy service is going to receive the following message as a soap request.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<proxy xmlns="http://ws.apache.org/ns/synapse" | |
name="studentrecordservice" | |
transports="https,http" | |
statistics="disable" | |
trace="disable" | |
startOnLoad="true"> | |
<target> | |
<inSequence> | |
<log level="full"/> | |
<enrich> | |
<source type="envelope" clone="true"/> | |
<target type="property" property="SOAP_ENVELOPE"/> | |
</enrich> | |
<property name="PAYMENT" expression="//Payment"/> | |
<payloadFactory media-type="xml"> | |
<format> | |
<dat:finance xmlns:dat="http://ws.wso2.org/dataservice"> | |
$1 | |
</dat:finance> | |
</format> | |
<args> | |
<arg evaluator="xml" expression="get-property('PAYMENT')"/> | |
</args> | |
</payloadFactory> | |
<call> | |
<endpoint> | |
<address uri="https://uni.finance"/> | |
</endpoint> | |
</call> | |
<property name="Status" expression="get-property('axis2', 'HTTP_SC')"/> | |
</then> | |
<else/> | |
</filter> | |
<filter source="get-property('axis2', 'HTTP_SC')" regex="200"> | |
<then> | |
<enrich> | |
<source type="property" clone="true" property="SOAP_ENVELOPE"/> | |
<target type="envelope"/> | |
</enrich> | |
<xslt key="gov:/xslt/realtimeinsert.xslt"/> | |
<log level="full"/> | |
<property name="Content-Type" | |
value="text/xml" | |
scope="default" | |
type="STRING"/> | |
<send> | |
<endpoint> | |
<address uri="https://uni.student.record"/> | |
</endpoint> | |
</send> | |
<respond/> | |
</inSequence> | |
<outSequence> | |
<send/> | |
</outSequence> | |
</target> | |
<description/> | |
</proxy> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<soap:envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | |
<soap:header> | |
<wsse:Security xmlns:wsse="http://schemas.xmlsoap.org/ws/2003/06/secext"> | |
<wsse:UsernameToken wsu:Id="sample" | |
xmlns:wsu="http://schemas.xmlsoap.org/ws/2003/06/utility"> | |
<wsse:Username>wso2</wsse:Username> | |
<wsse:Password Type="wsse:PasswordText">wso2</wsse:Password> | |
<wsu:Created>2015-05-11T08:44:51Z</wsu:Created> | |
</wsse:UsernameToken> | |
</wsse:Security> | |
</soap:header> | |
<soap:body> | |
<student> | |
<Name></Name> | |
<Records> | |
<Academic-Marks> | |
<param subject="OOP" value="75"/> | |
<param key="CS" value="75"/> | |
<param key="Signals" value="80"/> | |
</Academic-Marks> | |
<Payment> | |
</Payment> | |
</student> | |
<soap:body> | |
</soap:envelope> |
This message should be send to two endpoints. Those are
- Student Record department - The entire request message should be send to this endpoint.
- Finance Department - Only interested with contents inside the "Payment" element.
Initially the proxy service is expected to perform the following operation.
Extract the
Lately remove the
This proxy service performs following operations
- Uses Enrich mediator to copy the complete envelope of incoming soap message.
- Property mediator extracts the PAYMENT element and child elements.
- Extracted Payment element can be used to create a new soap payload by using payload factory.
- If this operation is successful we can use the enrich mediator to recreate the payload
- On top of this enriched message XSLT mediator can be used to remove the Payment element.
- This message now can be send to the endpoint.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:output method="xml" indent="yes"/> | |
<xsl:strip-space elements="*" /> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="Payment" /> | |
</xsl:stylesheet> |
The xslt script, that used to remove the Payment can be found here. I have uploaded it to the registry.
Therefore, the proxy can reference to it by using key.