Wednesday, July 19, 2017

Mule ESB - payload base64-encoding and base64-decoding

In this blog, I'm going to explain how to make our payload encoding and decoding.

You can use base64-encoder-transformer to encode the payload
<base64-encoder-transformer xmlns="http://www.mulesoft.org/schema/mule/core" encoding="utf-8"></base64-encoder-transformer>

You can use base64-decoder-transformer to decode the payload
<base64-decoder-transformer xmlns="http://www.mulesoft.org/schema/mule/core" encoding="utf-8"></base64-decoder-transformer>

Find the below sample flow to check the encoding and decoding mechanism.
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
 xmlns:spring="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8089" doc:name="HTTP Listener Configuration"/>
    <flow name="demo-encode-decodeFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/sample" doc:name="HTTP" allowedMethods="POST"/>
        <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
        <base64-encoder-transformer xmlns="http://www.mulesoft.org/schema/mule/core" encoding="utf-8"></base64-encoder-transformer>
        <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
        <base64-decoder-transformer xmlns="http://www.mulesoft.org/schema/mule/core" encoding="utf-8"></base64-decoder-transformer>
        <logger message="#[message.payloadAs(java.lang.String)]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>

Note: I used the logger component to print the encode and decode messages.

After making the POST request with a payload, we can see the below logs in the console:
INFO  2017-07-20 05:26:33,031 [[demo-encode-decode].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: Original Payload: ,{
  "id": "mule001",
  "name": "Mule course",
  "description": "Mule course Description"
}
INFO  2017-07-20 05:26:33,032 [[demo-encode-decode].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: base64-encoded message: ,ewogICJpZCI6ICJtdWxlMDAxIiwKICAibmFtZSI6ICJNdWxlIGNvdXJzZSIsCiAgImRlc2NyaXB0aW9uIjogIk11bGUgY291cnNlIERlc2NyaXB0aW9uIgp9
INFO  2017-07-20 05:26:33,032 [[demo-encode-decode].HTTP_Listener_Configuration.worker.01] org.mule.api.processor.LoggerMessageProcessor: base64-decoded message: ,{
  "id": "mule001",
  "name": "Mule course",
  "description": "Mule course Description"
}

Enjoy..!!

17 comments:

  1. the blog is about Mule ESB - payload base64-encoding and base64-decoding it is useful for students and Mulesoft Developers for more updates on Mulesoft follow the link

    mulesoft Online Training

    For more info on other technologies go with below links

    Python Online Training

    tableau online training hyderabad

    ServiceNow Online Training

    ReplyDelete
  2. Hi There,

    Love it absolutely! So crystalline. No mambo jumbo. No non-sense. Straight and simple. You guys need a standing ovation for your good work.
    Enterprises are adopting more agile, cost-effective, business technologies to keep pace with rapidly-changing expectations and requirements
    According to Gartner more than 60% of midsize and large organizations will deploy Managed File Transfer (MFT) technologies to support a growing number of digital business.


    But nice Article Mate! Great Information! Keep up the good work!


    MuchasGracias,
    Anasy

    ReplyDelete
  3. Hello There,

    Love it absolutely! So crystalline. No mumbo jumbo. No non-sense. Straight and simple. You guys need a standing ovation for your good work.


    Enterprises are adopting more agile, cost-effective, business technologies to keep pace with rapidly-changing expectations and requirements. According to Gartner more than 60% of midsize and large organizations will deploy Managed File Transfer (MFT) technologies to support a growing number of digital business.

    But nice Article Mate! Great Information! Keep up the good work!
    MuchasGracias,
    Morgan

    ReplyDelete
  4. Your blog is really awesome thanks for sharing most valuable information with us, Mulesoft Online Training

    ReplyDelete
  5. Hello There,

    Gratitude for putting up this prolific article! You truly make everything a cake walk. Genuinely good stuff, saving time and energy.
    In the previous blog post of this series on C4E, I discussed using an API-led approach to build software applications. The C4E practice encourages reuse of resources, collaboration with third-party developers and frequent direct interaction with business owners.

    During the initial discovery phase, the team recognizes the opportunity to develop a System API that provides an endpoint for retrieving data from a lookup list. The System API also allows for the list to be replaced and updated.
    By the way do you have any YouTube videos, would love to watch it. I would like to connect you on LinkedIn, great to have experts like you in my connection (In case, if you don’t have any issues).
    Please keep providing such valuable information.

    Thank you,

    ReplyDelete
  6. Hello There,


    Allow me to show my gratitude bloggers. You guys are like unicorns. Never seen but always spreading magic. Your content is yummy. So satisfied.


    I started using Mulesoft Training blog for my training practice.

    Harnessing the power of APIs is the key to competing in the new era of software. APIs provide the agility developers and businesses need to iterate and innovate quickly, and they’re everywhere. Businesses all over the world are looking to roll out or even acquire APIs, but if they don’t succeed at winning over developers

    Thanks a lot. This was a perfect step-by-step guide. Don’t think it could have been done better.


    Kind Regards,
    Morgan

    ReplyDelete
  7. Your blog saved plenty of time of mine.

    ReplyDelete
  8. Hi,In mule 3 we have decode and encode transformers but in mule 4 i haven't seen any transformers. Can you please explain how it works in mule 4 if we send the data as XML file through payload.

    ReplyDelete
  9. For Mulesoft ESB Real Time Training Contact Me at muleesbtrainer@gmail.com and 9985333565

    I will provide real time online training at low price for demo videos visit my youtube channel.
    http://youtube.com/channel/UC1lFGEh4xAPJnIm4FWmQBfA

    ReplyDelete
  10. Hi Please tell me Mule Soft online training with project oriented

    ReplyDelete
  11. Thanks for sharing valuable information and very well explained. Keep posting.

    mulesoft online training in Hyderabad
    mulesoft online training hyderabad

    ReplyDelete

  12. Thank you for sharing wonderful information with us to get some idea about it.
    Mulesoft Self Learning
    Mulesoft Online Training in India

    ReplyDelete