Skip to Content
avatar image
Former Member

How to encode the xml into base64 format

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.

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Jul 07, 2017 at 09:31 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 07, 2017 at 07:36 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • Jul 07, 2017 at 07:56 AM

    Hi Vamsidhar!

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

    Regards, Evgeniy.

    Add comment
    10|10000 characters needed characters exceeded