Base64 Decoding Using Java Mapping Example

This article provides a sample Java mapping code to decode Base64 string in SAP PI/PO. You can decode Base64 string in SAP PI/PO with User-Defined Function (UDF), Java Mapping and Adapter Modules. In this example, we will discuss how to achieve Base64 conversion using Java Mapping. Feel free to read my previous article on Base64 encoding and decoding methods in SAP ABAP. Additionally, you can refer to my SAP blog on the same subject.

Base64 Decoding Example Scenario:

Let’s assume, a sender message contains Base64 string and we need to assign the decoded string to the target message.

Source message xml node <Base64EncodedString> contains the encoded message. Decoded string should be mapped to node <Base64DecodedString> of the target message.

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

Expected Functionality of Java Mapping:

Final result with input message and desired output message are as below.

Source and target messages of Base64 decoding example in ESR operation  mapping test.
Source and target messages of Base64 decoding example.

The first function of Java Mapping is to convert Base64 encoded string in ‘Base64EncodedString’.

Encoded string ‘U0FQSW50ZWdyYXRpb25IdWIuY29t’ translates to ‘SAPIntegrationHub.com’.

Desired message mapping from base64 java mapping in XML format in ESR.
Desired message mapping from base64 java mapping in xml format.

Next, Java Mapping should form the output or target xml message.

Input Message:

 

Output Message:

 


Steps to Implement Base64 Message Mapping in Enterprise Service Repository:

  1. Create Data Types, Message Types, and Service Interfaces.
  2. Create Base64 Java Mapping in Netweaver Development Studio (NWDS).
  3. Implement Operation Mapping (OM).

Step 1: Create Data Types, Message Types and Service Interfaces.

Create these ESR objects to match the scenario. We have two Data types and two Message types each for sender and receiver.

Data types and Message types are defined to reflect the input and output xmls mentioned above.

Sender Data Type and Message Type:

sender data type for base64 input message esr
Sender Data Type.
Sender Message Type for base64 input message.
Sender Message Type

Receiver Data Type and Message Type:

Receiver data type for base64 target message
Receiver Data Type
Receiver Message Type for base64 target message
Receiver Message Type

In this example we’ll use one outbound service interface for sender and one inbound service interface for receiver.

Outbound Service Interface:

Outbound Service Interface for base64 decode scenario in SAP PI ESR.
Outbound Service Interface

Inbound Service Interface:

Inbound Service Interface for base64 decode scenario example
Inbound Service Interface

Step 2: Create Base64 Decoding Java Mapping in NWDS.

If you have not created Java Mappings in NWDS before, read my article on how to implement Java Mappings.

Implement the code snippet and export it as a .jar. Then import the .jar file as an Imported Archive to ESR.

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

Create Imported Archive by uploading Java Mapping class defined in step 2 as a .jar to ESR. Then configure the Operation Mapping with the Imported Archive.

base64 object list in ESR. SWCV, namespace, imported archives and operation mapping.
base64 object list in ESR.
Operation mapping for base64 decoding in ESR.
Operation mapping for base64 decoding.

Test Base64 Decoding Java Mapping:

You can test Java Mapping using Operation Mapping test tool in ESR.

Base64 encoded string is ‘VGVzdGluZyBkZWNvZGVyLg==’.

Java mapping test using Operation Mapping test tool in ESR.
Java mapping test using Operation Mapping test tool in ESR.

Hopefully, you will be able to reuse the structure of this Base64 decoding Java Mapping class for integration scenarios. Please, leave a comment below if you have any questions about Base64 decoding or Java Mappings.

One Comment

Add a Comment

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