This example will be implemented in an SAP Process Orchestration (PO) system version SAP PO7.50 single stack.
Design of the Base64 Encoding and Decoding UDFs:
We will implement two UDFs, one to encode Base64 and another one to decode Base64.
We will name,
Encoding UDF as Base64Encoder and
Decoding UDF ad Base64Decoder.
Both UDFs have an Execution Type of “Single Value“. That means the UDF accepts only one argument as input and outputs one value. For example, Base64 decoding UDF accepts Base64 encoded string as the input and returns the encoded string.
Both encoding and decoding will be carried out using standard methods of Java utility class java.util.Base64. This class contains two nested classes: Base64.Decoder decodes byte data and Base64.Encoder implements the encoder for encoding byte data.
Base64 Encoding UDF: Base64Encoder
Encoding UDF has one input variable “PlainString”. Input value is assigned from the source message element “PlainString”. UDF converts this value to Base64 format.
Encoding can be broken down to two steps,
Step 1: Convert String to Byte Array
First, input string value is converted to byte array using String method getBytes().
Step 2: Encode Byte Array to Base64 Format
Next, the static method encodeToString of nested class Base64.Encoder decodes the byte array to actual text.
Decoding UDF also contains only one input variable. UDF accepts Base64 encoded value using input variable “EncodedString”. Function of the UDF is to decode the encoded string value and return plain text.
Decoding can be broken down to two steps,
Step 1: Transform Encoded String to Encoded Byte Array
Decode method of nested class Base64.Decoder converts Base64-encoded string into encoded bytes array.
Method getDecoder() returns the Base64.Decoder class.
Let’s test the User Defined Functions and mapping using graphical message mapping test tool.
Input encoded value is “RGVjb2RlIHRoaXMgdGV4dCE=”. This translates to “Decode this text!”.
Input value which should be encoded to Base64 schema is “Encode this text!”. Base64 converted value of this is “RW5jb2RlIHRoaXMgdGV4dCE=”.
If you have any questions about Base64 encoding and decoding using User Defined Functions, Java Mapping, or ABAP applications, leave a comment below! Have you used any other methods to convert Base64 schema in SAP integration scenarios?