Base64DecodeConverter – Base64 decoding made easy!
Update 4 Sep 2018: Now available in CPI as well.
Introduction
Base64 is an encoding scheme to represent binary data in a textual format. In the area of integration, occasionally there are requirements to handle content that are encoded in Base64. Below are some example usage of Base64:-
- Store binary data (PDF, image) in text format
- Embed binary data in an XML
- Compress data for efficient transfer over text-based transmission medium
Currently, there is no standard feature in PI/PO to handle Base64 content. It is normally handled through custom development of UDFs or Java mappings. Unfortunately, although there is an idea submission at Idea Place by Aaron Myers for a Base64 standard adapter module (in the likes of PayloapZipBean, etc), the status of the submission has not changed in the past two years since the submission
Enter Base64DecodeConverter, the latest addition to the family of FormatConversionBean converters It is a reusable and reconfigurable converter that handles decoding of Base64 content in plain text file or embedded in an XML payload.
Source Code and Deployment Archive
Refer to following blog on location of source code and/or EAR deployment file.
FormatConversionBean – One Bean to rule them all!
Usage of Module in Communication Channel
Module Processing Sequence
Number | Module Name | Type | Module Key |
---|---|---|---|
<Depending on position of module in chain> 1) Asynchronous scenario, Normally before the last module in channels 2) Synchronous scenario, Before last module to convert request payload After last module to convert response payload |
Custom_AF_Modules/FormatConversionBean | Local Enterprise Bean | <Any Arbitrary Value> |
Module Parameter Reference
Below are the parameters for configuration of the module for Base64 decoding. Certain parameters will automatically inherit the default values if it is not configured.
Parameter Name | Allowed values | Default value | Remarks |
---|---|---|---|
converterClass |
PI – com.equalize.xpi.af.modules.base64.Base64DecodeConverter CPI – com.equalize.converter.core.Base64DecodeConverter |
Required field. Determines conversion class | |
inputType | plain, xml | Required field. Indicates type of input data
|
|
xpath |
Required field when inputType = ‘xml’. XPath expression to location of XML element containing Base64 string |
||
zippedContent | Y,N | N | Indicates that content was compressed before encoding into Base64 string |
contentType | Specifies the MIME content type of the output after decoding. Available only in PI | ||
messageLog | pre, post | Saves a log version of the message that is viewable in Message Monitor
Available only in PI |
|
logLocation | Name of log version when messageLog is populated. Location defaulted to value in messageLog if logLocation not populated. Available only in PI |
Example Scenarios
Here are some example scenarios of the behavior of the conversion based on different configuration options.
Scenario 1
- Base64 string in plain input text
- Content was compressed before encoding into Base64, therefore decompression is required after decoding
Module parameters
Parameter Name | Parameter Value |
---|---|
converterClass | com.equalize.xpi.af.modules.base64.Base64DecodeConverter |
inputType | plain |
zippedContent | Y |
Result
Scenario 2
Screenshot of actual configuration and testing are shown below.
- Base64 string embedded in XML payload
- XPath expression to location of field containing Base64 content provided
- Output MIME content type specified
The test data is created by using Base64 Encode – Online to produce the Base64 string as shown below, and embedding it in an XML.
Module configuration on an SFTP receiver channel.
The XML input payload is sent via the Send Test message function.
The log version ‘post’ shows the content after decoding. The decoded content matches the original content as expected.
The audit log shows the trace of steps being executed by the module.
Conclusion
With this new addition to FormatConversionBean, decoding of Base64 content can now be easily handled without additional custom development
Thanks so much for working on this and sharing it Eng!
Thanks a lot for your efforts Eng...really useful.
Hi Eng Swee Yeoh ,
First and foremost thanks for the wonderful blog and introducing this bean to the family.I must tell it has eased lot of our efforts.
We are trying to use this Custom Adapter Module as per your blog wherein we are trying to decode an field level Base 64 encrypted file.
Consider there are 4 fields in an XML file wherein the 3rd field is coming encoded. Now in the output I need an XML format wherein I am trying to capture all the 4 fields and the 3rd field should be decoded.
I am using the below configuration in the Module Parameter of Sender Channel:
Now when I am doing an end to end test. The file is getting picked up and but I am getting an error during processing:
Transmitting the message to endpoint <local> using connection File_http://sap.com/xi/XI/System failed, due to: com.sap.aii.af.service.mapping.MappingException: Mapping failed in runtimeRuntime Exception when executing application mapping program com/sap/xi/tf/_Encode_to_Decode_; Details: com.sap.aii.utilxi.misc.api.BaseRuntimeException; Content is not allowed in prolog.
And strange part is when I check the payload only the XPATH mentioned field is getting generated with the decoded value and the rest of the field is not visible at all.Also I am not getting the output in the XML format. Is it something I am missing in here where in you could help us out?
Regards
Nitin
Hi Nitin
Thank you for your comments. Regarding your issue, I've replied directly in the thread you opened:-
Field Level Base 64 Decoding
Regards
Eng Swee
Hi Eng Swee Yeoh ,
is it possible to put the encoded string as attachment, e.g. when you get an pdf as base64 encoded string in a xml message and want to add the decoded PDF als attachment to pi message?
Thx,
Thorsten
Hi Thorsten!
You can use UDF in graphical mapping or java mapping to add attachment to your message from Base64-encoded string.
Regards, Evgeniy.
Hi Thorsten
The functionality as-is do not have that capability. Due to work commitments, I don't have the time to enhance it currently. The project is available on GitHub for anyone to fork and enhance as required.
Regards
Eng Swee
It's perfect. Works perfectly in my PI 7.5. Very nice work Eng, You're my hero.
Thanks for the feedback Jovane. Always good to know that this is actually being used "out there" and that it works 🙂
Eng Swee
Eng, I receive the filename into XML payload. I'm trying change filename using "Variable Substitution" but don't have success using FormatConversionBean. I also trying Dynamic Configuration with Message Mapping and also without success. If I remove FormatConversionBean the Variable Substituition works fine. Do you know how rename the output with filename in payload?
Thanks,
Jovane Marques
Hi Eng,
if input request message having multiple base64 occurrence can I generate same number of pdfs with the help of this module ?
Br
Amit
Hi Eng,
Thanks for your post,
I have one requirement,
i.e
Sender Ariba cxml payload the attachment (“cid:1735239107.1592222922946@cxml.org”)
document is coming in above format need to extract this content and send to base64 with third party… could you please suggest me with your inputs, that how we can extract the content.
It’s very helpful.
Thank you.