on 10-17-2012 4:56 PM
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
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;
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Aaron,
I've tried to use the udf you've posted but i get an error while validating:
I've imported the sun.misc.BASE64Decoder.jar.
can u help ?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Steve is right, Oracle discourages the usage of the Sun library.
The Apache Commons codec can to be downloaded from the link below
Other options for a Base64 encoder/decoder are below:-
Hello Aaron
An example of Base64-encoding a string using Commons Codec :
String usernamePassword = username + ":" + password;
byte[] usernamePasswordBytes = usernamePassword.getBytes();
byte[] encodedUsernamePasswordBytes = Base64.encodeBase64( usernamePasswordBytes );
String encodedUsernamePassword = new String( encodedUsernamePasswordBytes );
But I think javax.xml.bind.DatatypeConverter is a better suggestion. I'd use that as it requires less code and you wouldn't have to import an extra jar into PI.
regards
Steve
Thanks Eng!
When I tried with SAP's version it says:
When I tried with javax it says:
Doesn't it seem like PI should have this feature built into a library? I mean do we really need to download new software into the system for this?
Hi Aaron,
You don't need to download the library for the DatatypeConverter.
If you try copying the transform() method from my answer in the following thread.
And use it in a message mapping in ESR, entering all the necessary imports, including javax.xml.bind.*.
As you see below, the object check goes fine and it can be compiled.
Even if you do this in NWDS, the library is already part of the standard JRE system library.
I'm not sure what environment you are developing in, and where do you get the not exists error. Probably if you can provide some further details or screenshot, then we can try and resolve the mystery
Rgds
Eng Swee
PS: In the code you can also see how easily DatatypeConverter method can be used for parsing base64.
Hi,
Can i use the same class for Decoding a base64 field ? does anyone have a UDF ready ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I gave it a try, and I surprised myself with an error haa haa.
Anyone know how to make this sun decoder work? Input is a long base64 string.
import sun.misc.BASE64Decoder
public String b64decode(String myInput, Container container) throws StreamTransformationException{
BASE64Decoder decoder = new BASE64Decoder();
byte[] decoded = decoder.decodeBuffer(myInput);
String myOutput = new String(decoded, "UTF-8");
return myOutput;
}
I get error:
Function b64decode, Line 3:
unreported exception java.io.IOException;
must be caught or declared to be thrown byte[] decoded = decoder.decodeBuffer(myInput);
There is a caret/hat/^ pointing at string inside decodeBuffer(myInput)
sun.misc.BASE64Encoder
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
>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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.