Skip to Content

Co-Author: Rajwinder Singh

 

Problem Statement – Encoder – Base64: Conversion results in Line Feed character at every 76th position

 

Example Process Flow to simulate the behavior:

 

 

1)     Following screenshot shows the Payload introduced via the first Content Modifier.

 

 

The payload consists of continuous text without any Line Feed.

 

2)     The following screenshot shows the Encoder settings to converts the text to Base64 format.

 

 

3)   After deploying the integration flow, the resultant text contains Base64 encoded output. However, there is also an additional line feed character present at every 76th position.

 

 

The reason for this behavior (as also highlighted in the WIKI pages below) is an old MIME format. Please refer the wiki page for more details.

https://en.wikipedia.org/wiki/Base64

 

 

 

Solution / Alternative:

Use groovy function encodeBase64() to convert to Base 64 which uses a more recent format and does not introduces a line feed character at every 76 position.

 

 

Output after Base64 conversion using groovy.

 

 

Sample Groovy:

import com.sap.gateway.ip.core.customdev.util.Message;

import java.util.HashMap;

 

def Message processData(Message message) {

 

//Body

def body = message.getBody(String.class);

 

String encoded = body.bytes.encodeBase64().toString();

message.setBody(encoded);

 

return message;

}

 

Please note: The purpose of the Blog is to share an alternative approach to the issue and does not suggest it as the only available alternative.

 

To report this post you need to login first.

1 Comment

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

Leave a Reply