Skip to Content
avatar image
Former Member

Base64 Encoding using UDF

Hi,

I have a File to SOAP scenario.  I am getting a csv file and would like to send that file as base encoded 64.

I am thinking of concatenating all fields of source file in the message mapping and convert it as base64 and map it to soap envelope.

Can anyone let me know any UDF which can be used for this.  What are the java classes that needs to be uploaded for this?

Please do let me know the same.

Regards

Anandh.B

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

6 Answers

  • avatar image
    Former Member
    Jan 08, 2013 at 08:08 PM

    I know this thread is old but it comes up as result number 1 when searching for "base64 udf"

    My system could not import the class mentioned by Baskar so I'm posting what worked for me:

    Create UDF named b64encode with one input called myInput

    include sun.misc.BASE64Encoder

    public String b64encode(String myInput, Container container) throws StreamTransformationException{

         BASE64Encoder encoder = new BASE64Encoder();

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

         return encoded;

    }

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi Aaron,

      I've tried to use the udf you've posted but i get an error while validating:

      • Function b64encode, Line 1: cannot find symbol
        symbol : class BASE64Encoder
        location: class keter.erp.GlobalFunctions.GlobalFunctions
          BASE64Encoder encoder = new BASE64Encoder();

      I've imported the sun.misc.BASE64Decoder.jar.

      can u help ?

  • Jan 21, 2015 at 07:48 AM

    Hello,

    Oracle recommend against the use of 'sun' packages, although I wouldn't expect you to experience any problems.

    http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html

    An alternative would be to use the Apache Commons Codec jar.

    regards

    Steve

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 17, 2012 at 05:06 PM

    >Can anyone let me know any UDF which can be used for this.  What are the java classes that needs to be uploaded for this?

    You need to write import statement for this class

    com.sap.aii.utilxi.base64.api.Base64

    and this class contains two static methods namely encode and decode.  Refer more about knowing this in the thread

    http://scn.sap.com/thread/1079238

    Add comment
    10|10000 characters needed characters exceeded

  • Oct 17, 2012 at 07:27 PM

    Hi,

    Java mapping code in this wiki will help u:

    http://wiki.sdn.sap.com/wiki/display/XI/How+to+Send+Binary+Data+to+RFC+from+XI(or)PI

    Thanks

    Amit Srivastava

    Add comment
    10|10000 characters needed characters exceeded

  • Jan 11, 2015 at 01:26 PM

    sun.misc.BASE64Encoder 

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Jan 20, 2015 at 01:42 PM

    Hi,

    Can i use the same class for Decoding a base64 field ? does anyone have a UDF ready  ?

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      Well, maybe answered my question but here is a solution which works for me:

      BASE64Decoder decoder = new BASE64Decoder();

      try {

      byte[] decoded = decoder.decodeBuffer(myInput);

      String myOutput = new String(decoded, "UTF-8");

      return myOutput;

      }

      catch (IOException e) {

      return e.toString();

      }