Base64 Encoding Java Mapping Example for SAP PI/PO

This article provides a Java mapping which encodes Base64 in SAP PI/PO. I will implement a simple interface to demonstrate the use of the Java mapping. It’s part of a series of posts about Base64 encoding and decoding and you can check the Base64 decoding Java Mapping example in my previous article.

Similarly, you can also use User Defined Functions (UDF) to encode and decode Base64 in SAP PI/PO. But in this article, I’ll show you how to use Java mapping for encoding.

Base64 Encoding Java Mapping Scenario:

Source message node ‘TextMessage’ contains a string value that should be encoded. Base64 encoded string should be mapped to target message node ‘Base64EncodedString’.

Example overview and expected result with base64 encoded string and input string
Example overview and expected result

String ‘Welcome!’ translates to ‘V2VsY29tZSE=’ in Base64 schema.

System Detail Example was Implemented:

This example will be implemented in an SAP Process Integration (PI) system version 7.50 single stack.

Functionality of Java Mapping:

First functionality of Java mapping is to encode the text in Base64 schema. String value in sender message node ‘TextMessage’ should be encoded and included in target message element ‘Base64EncodedString’.

Then, Java mapping should create a complete target message xml with other elements, namespaces, etc.

If the target system is an SAP system, you can decode a Base64 string using ABAP Function Modules (FM) or ABAP class CL_HTTP_UTILITY. You can read more about how to encode or decode Base64 in SAP in my previous post.

Input Message:

 

Output Message:

 


How to Implement Java Mapping in Enterprise Resource Repository (ESR):

Follow these steps to implement the Base64 encoding Java mapping.

  1. Create Data Types, Message Types and Inbound/Outbound Interfaces.
  2. Implement Base64 Encoder Java Class in Netweaver Developer Studio (NWDS).
  3. Define the Imported Archives and Operations Mapping (OM) in ESR.

Step 1: Create Data Types, Message Types and Inbound/Outbound Service Interfaces:

Create sender message and target message Data types and Message Types. Then, create inbound and outbound service interfaces.

Sender Message, Data Type and Message Type:

Sender message Data Type for base64 java mapping illustration in SAP Pi PO
Sender message Data Type
Sender message Message Type for base64 java mapping implementation SAP PI in ESR
Sender message Message Type

Target Message, Data Type and Message Type:

Output Data Type for base65 java mapping
Output Data Type
Output Message Type for base65 java mapping
Output Message Type

Inbound Service Interface:

Inbound Service Interface for target for base64 java mapping example SAP PI PO
Inbound Service Interface for target

Outbound Service Interface:

Output Service Interface for sender for base64 java mapping example SAP PI PO
Output Service Interface for sender

Step 2: Implement Base64 Encoder Java Class in NWDS:

We will use java.util.Base64 class to implement this mapping program.

Create the Encoder Java mapping class in NWDS. Export the implemented Java class as a .jar file.

 

Step 3: Create Imported Archive and Operation Mapping (OM):

Upload Java mapping as an Imported Archive (.jar) to ESR. Next, create Operation Mapping including the Imported Archive.

Imported Archive from Base64 java class in SAP PI ESR
Imported Archive from Base64 Java class

Configure Operation Mapping with Java class.

Operation Mapping with imported archive java class for base64 encoding sap pi po
Operation Mapping
Imported Archive and Operation Mapping for base64 conversion using java mapping in sap pi po
Imported Archive and Operation Mapping

Test Base64 Encoder Java Mapping:

Test the Java Mapping program via Operation Mapping test tool.

Test Java Class using Operation Mapping test tool
Test Java Class

You can reuse Base64 encoding Java class with minor adjustments to suite your scenario. If you have any questions, please leave a comment below.

Get the latest tips and tricks on SAP!

One Comment

Add a Comment

Your email address will not be published. Required fields are marked *