on 06-21-2016 5:25 PM
Hi,
I am doing 'Soap to Soap ' synchronous scenario.The file that we are sending needs to be in Base64 Encoded format and the response would be in encoded format which we have to decode in order to do the mapping in PI.
we are using PI 7.4 Dual stack.
I have already gone through the below blog but that is for Asynchronous scenario and not very explanatory.
Could you please suggest how to achieve the above requirement.
It is an urgent requirement and would very much appreciate your help.
Thanks & Regards,
Srinivas
Hi,
I had also to decode a Base64 PDF file and searched for a solution. Some solutions using non-standard Java libaries (e.g. from sun) or the latest Java version that have a encoder/decoder inclusive. Unfortunately our PI didn't use the latest Java version.
So I finally used javax.xml.bind.DatatypeConverter
I could use it without additional deployment of libaries and it was simple.
...
byte[] decoded = null;
decoded = DatatypeConverter.parseBase64Binary(codedText);
...
After decoding, I added the PDF file as attachment.
Regards
Chris
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas,
If your full payload is coming back as an encoded string, I would suggest to use a Java mapping and perform the decoding in it. Output of Java Mapping will be a well formed XML, so you can either:
Blog that you have mentioned uses a bean to perform decoding.
Regards,
Sanjeev
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Srinivas,
Here is the code that I had used:
package somepackage;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import com.oschrenk.io.Base64;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
public class ConvertBase64toXMl extends AbstractTransformation {
public void transform(TransformationInput arg0, TransformationOutput arg1) throws StreamTransformationException {
// TODO Auto-generated method stub
this.execute(arg0.getInputPayload().getInputStream(), arg1.getOutputPayload().getOutputStream());
}
public void execute(InputStream arg0, OutputStream arg1) throws StreamTransformationException {
try {
//String output = "";
String fileContent = "";
BufferedReader reader = new BufferedReader(new InputStreamReader(arg0));
StringBuilder out = new StringBuilder();
String line = reader.readLine();
while(line != null)
{
out.append(line + "\n");
line = reader.readLine();
}
fileContent = out.toString();
byte[] decoded = Base64.decode(fileContent);
String result = new String(decoded, "UTF-8");
arg1.write(result.getBytes());
}
catch(Exception e){
throw new StreamTransformationException(e.toString());
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
InputStream in = new FileInputStream(new File("C:\\Desktop\\in_Base64Converter.txt"));
OutputStream out = new FileOutputStream(new File("C:\\Desktop\\out_XMLOutput_Base64Converter.xml"));
ConvertBase64toXMl myMapping = new ConvertBase64toXMl();
myMapping.execute(in , out);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Please note that this will just convert the data to XML format. Any further processing will need to be done using further java code or message mapping as I had mentioned earlier.
Also, note that I had imported this jar: java-util-1.3.1.jar from here
Regards,
Sanjeev.
Message was edited by: Sanjeev Shekhar Singh
Hi,
import the com.sap.aii.utilicore jar and used in UDF.
Code of encode you will get in Sritharan link.
Thanks,
Sreenivasa
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
25 | |
12 | |
9 | |
6 | |
6 | |
5 | |
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.