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 com.equalize.xpi.af.modules.base64.Base64DecodeConverter Required field. Determines conversion class
inputType plain, xml

Required field. Indicates type of input data

  • plain = Base64 string provided as plain input text
  • xml = Base64 string embedded in XML element of XML payload
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
messageLog

pre, post

Saves a log version of the message that is viewable in Message Monitor

  • pre = saves payload before conversion
  • post = saves payload after conversion
logLocation Name of log version when messageLog is populated. Location defaulted to value in messageLog if logLocation not populated

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

Input /wp-content/uploads/2015/04/in1_695515.png
Output /wp-content/uploads/2015/04/out1_695514.png

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.

/wp-content/uploads/2015/04/test2_706785.png

Module configuration on an SFTP receiver channel.

/wp-content/uploads/2015/04/module_695506.png

The XML input payload is sent via the Send Test message function.

/wp-content/uploads/2015/04/send_test2_695505.png

The log version ‘post’ shows the content after decoding. The decoded content matches the original content as expected.

/wp-content/uploads/2015/04/decoded_695504.png

The audit log shows the trace of steps being executed by the module.

/wp-content/uploads/2015/04/log_695470.png

Conclusion

With this new addition to FormatConversionBean, decoding of Base64 content can now be easily handled without additional custom development

To report this post you need to login first.

10 Comments

You must be Logged on to comment or reply to a post.

  1. Nitin Rao

    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:Module Parameter.jpg

    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

    (0) 
    1. Eng Swee Yeoh Post author

      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

      (0) 
    1. Eng Swee Yeoh Post author

      Thanks for the feedback Jovane. Always good to know that this is actually being used “out there” and that it works 🙂

       

      Eng Swee

      (1) 
      1. Jovane Marques

        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

        (0) 

Leave a Reply