Friday, October 23, 2015

Base64 Encode Payload Body WSO2 ESB

In this tutorial, I have posted sample ESB API which encode the payload to Base64 and return it back. This has achieved through the xpath base64Encode function.

<api context="/test" name="test">
      <resource faultsequence="fault" methods="POST" url-mapping="/status">
         <insequence>
            <property expression="$body/*" name="messageBody" scope="default">
            <property expression="base64Encode(get-property('messageBody'))" name="EncodeBody" scope="default">
            <log level="custom">
               <property expression="get-property('messageBody')" name="Request Payload">
            </property></log>
            <enrich>
               <source clone="true" type="inline"></source>
                  <soapenv:envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                     <soapenv:body>
                        <encoded xmlns="">
                     </encoded></soapenv:body>
                  </soapenv:envelope>
               <target type="envelope">
            </target></enrich>
            <enrich>
               <source clone="true" xmlns:ns="http://org.apache.synapse/xsd" xpath="get-property('EncodeBody')"></source>
               <target type="body">
            </target></enrich>
            <property name="messageType" scope="axis2" type="STRING" value="application/xml">
            <respond>
         </respond></property></property></property></property></insequence>
      </resource>
</api>


Using a rest client post following xml content

<testencode><encode>abc</encode></testencode>

Result will be returning in following format
<encoded>{ENCODED_STRIN}</encoded>

No comments:

Post a Comment