I was trying to do a POC to encode a json payload to base64 format in WSO2. I have used payload factory to form a json payload which looks like below:
{
"employee_id": 1012967,
"employe_name": "Tarun",
"employee_dept": "Finance",
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5UZG1aak00WkRrM05qWTBZemM1TW1abU9EZ3dNVEUzTVdZd05ERTVNV1JsWkRnNE56YzRaQT09In0.eyJhdWQiOiJodHRwOlwvXC9vcmcud3NvMi5hcGltZ3RcL2dhdGV3YXkiLCJzdWIiOiJhZG1pbkBjYXJib24uc3VwZXIiLCJhcHBsaWNhdGlvbiI6eyJvd25lciI6ImFkbWluIiwidGllclF1b3RhVHlwZSI6InJlcXVlc3RDb3VudCIsInRpZXIiOiJVbmxpbWl0ZWQiLCJuYW1lIjoiRGVmYXVsdEFwcGxpY2F0aW9uIiwiaWQiOjEsInV1aWQiOm51bGx9LCJzY29wZSI6ImFtX2FwcGxpY2F0aW9uX3Njb3BlIGRlZmF1bHQiLCJpc3MiOiJodHRwczpcL1wvbG9jYWxob3N0Ojk0NDNcL29hdXRoMlwvdG9rZW4iLCJ0aWVySW5mbyI6eyJQbGF0aW51bSI6eyJ0aWVyUXVvdGFUeXBlIjoicmVxdWVzdENvdW50Iiwic3RvcE9uUXVvdGFSZWFjaCI6dHJ1ZSwic3Bpa2VBcnJlc3RMaW1pdCI6NSwic3Bpa2VBcnJlc3RVbml0Ijoic2VjIn19LCJrZXl0eXBlIjoiUFJPRFVDVElPTiIsInN1YnNjcmliZWRBUElzIjpbeyJzdWJzY3JpYmVyVGVuYW50RG9tYWluIjoiY2FyYm9uLnN1cGVyIiwibmFtZSI6IlBpenphU2hhY2siLCJjb250ZXh0IjoiXC9waXp6YXNoYWNrXC8xLjAuMCIsInB1Ymxpc2hlciI6ImFkbWluIiwidmVyc2lvbiI6IjEuMC4wIiwic3Vic2NyaXB0aW9uVGllciI6IlBsYXRpbnVtIn1dLCJjb25zdW1lcktleSI6IlRFc3YyREZlYWlGbG5SdUp6dWMyTFp3cUN4d2EiLCJleHAiOjE1OTc2NjM5OTIsImlhdCI6MTU5NzY2MDM5MiwianRpIjoiNzRjOWVkZDMtZGUzYy00N2I0LTljNzctM2VhNTNkYzA1ZTVkIn0.GTtpRd3ke3jMF1Y7cSKRoLuR0nm-fTiubqh2OgFvVzalzRmWt8mNFb_cOjmkJc0fvoiP9nuylymDiHUEv6WpuWnYhjv_DSk7GQ6dDJWO23PUBduaEGUanfjWDvOcS9PjpDN6Ao5Zu2zkeePQwNYxLSarlmh38U4iSff0P0jVpxr7NDw31r_lPOeNkDyN0rG4k2qVoCRJGzYLbUYjlXQJoAJnIrgv7DYxqzOJpMxUiIOAi3uAMWyycnOxyR13CV9RsbYX5jt19C2Xc8_zz2EW76Hzp4mLoMLXaJ4HLe5DLo9wjPsGEcHwVJtzZ5-vUCNzwHecxZ7SxGfuFHpHCgiJew",
"scope": "am_application_scope default",
"token_type": "Bearer",
"expires_in": 3600
}
Now, i have used the below line to to do base64 encode of the above payload.
<property name="FinalEncodedResponse" scope="default" expression="base64Encode($body)"/>
The above line encodes the data but when i decode it appears as below (contains only values) and not the actual json that i specified above.
1012967TarunFinanceeyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6Ik5UZG1aak00WkRrM05qWTBZemM1TW1abU9EZ3dNVEUzTVdZd05ERTVNV1JsWkRnNE56YzRaQT09In0.eyJhdWQiOiJodHRwOlwvXC9vcmcud3NvMi5hcGltZ3RcL2dhdGV3YXkiLCJzdWIiOiJhZG1pbkBjYXJib24uc3VwZXIiLCJhcHBsaWNhdGlvbiI6eyJvd25lciI6ImFkbWluIiwidGllclF1b3RhVHlwZSI6InJlcXVlc3RDb3VudCIsInRpZXIiOiJVbmxpbWl0ZWQiLCJuYW1lIjoiRGVmYXVsdEFwcGxpY2F0aW9uIiwiaWQiOjEsInV1aWQiOm51bGx9LCJzY29wZSI6ImFtX2FwcGxpY2F0aW9uX3Njb3BlIGRlZmF1bHQiLCJpc3MiOiJodHRwczpcL1wvbG9jYWxob3N0Ojk0NDNcL29hdXRoMlwvdG9rZW4iLCJ0aWVySW5mbyI6eyJQbGF0aW51bSI6eyJ0aWVyUXVvdGFUeXBlIjoicmVxdWVzdENvdW50Iiwic3RvcE9uUXVvdGFSZWFjaCI6dHJ1ZSwic3Bpa2VBcnJlc3RMaW1pdCI6NSwic3Bpa2VBcnJlc3RVbml0Ijoic2VjIn19LCJrZXl0eXBlIjoiUFJPRFVDVElPTiIsInN1YnNjcmliZWRBUElzIjpbeyJzdWJzY3JpYmVyVGVuYW50RG9tYWluIjoiY2FyYm9uLnN1cGVyIiwibmFtZSI6IlBpenphU2hhY2siLCJjb250ZXh0IjoiXC9waXp6YXNoYWNrXC8xLjAuMCIsInB1Ymxpc2hlciI6ImFkbWluIiwidmVyc2lvbiI6IjEuMC4wIiwic3Vic2NyaXB0aW9uVGllciI6IlBsYXRpbnVtIn1dLCJjb25zdW1lcktleSI6IlRFc3YyREZlYWlGbG5SdUp6dWMyTFp3cUN4d2EiLCJleHAiOjE1OTc2ODgxNjAsImlhdCI6MTU5NzY4NDU2MCwianRpIjoiM2U5YjQ3YjUtY2I5ZC00MWVmLTgxMDktNWRhYjNiMzQxMjI4In0.fWzi4wWMeZjMGX92eczshPzRSA6v2lj47tpz69_u0MWuxhbQ0H4feJuDobwDqJCoQVE5lXmKMssprIgN4wZzeBEGxAzswJZZlnJD04QualzRhjXdBqyrLTFh01jnLKCzdowjhCDBokP5phHDfbSKqLZrLLHe5FpJw-wX0aGCe_rYpOcu9xwhYeV6UM0YLBK51Z3U-n3k6YvUwj9CZrPRqHfy1XWQiUnnGD7GyBiiN0I47ykuYYbT7jSh7cXX1N6lrSgc29oUcAZQtPr8w3LlTR-CipUrLfLgwh5Dn27M4Kh9mEeKhQddOlaFLeR4tyQmnIrtqPYmBjHSDH9vkR6ajgam_application_scope defaultBearer3600
I wanted to know how can we encode a json payload to base64 format as it is in WSO2? Need help with this.
Can you try the following approach?
<property expression="json-eval($)" name="messageBody" scope="default"/>
<property expression="base64Encode(get-property('messageBody'))"
name="FinalEncodedResponse"/>