Skip to Content
0

How to encode the xml into base64 format

Jul 07, 2017 at 06:51 AM

87

avatar image

Hi all,

I have a requirement where I need to encode the incoming xml into base64 format.

Could any one suggest on the java program which needs to be implemented in this case.

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Andrzej Filusz Jul 07, 2017 at 09:31 AM
3

Hi,

String encoded = encoder.encode(myInput.getBytes());

Please don't use getBytes method without a parameter cos it returns a sequence of bytes using the platform's default charset.

Always specify your required character set, in this case:

String encoded = encoder.encode(myInput.getBytes("UTF-8"));
or
String encoded = encoder.encode(myInput.getBytes(StandardCharsets.UTF_8));

Regards,

Andrzej

Share
10 |10000 characters needed characters left characters exceeded
Raghuraman S Jul 07, 2017 at 07:36 AM
1

Below UDF should help

BASE64Encoder encoder = new BASE64Encoder();

String encoded = encoder.encode(myInput.getBytes());

return encoded;

Pass the whole XML using "Return as XML"option in the mapping.


udf.png (15.8 kB)
Show 1 Share
10 |10000 characters needed characters left characters exceeded

if you are using sun.misc.BASE64Encoder then better to check Stefan Grube's reply in

https://archive.sap.com/discussions/thread/3791352

0
Evgeniy Kolmakov Jul 07, 2017 at 07:56 AM
0

Hi Vamsidhar!

You can also use standard javax.xml.bind.DatatypeConverter.printBase64Binary() method for Base64 encoding.

Regards, Evgeniy.

Share
10 |10000 characters needed characters left characters exceeded