on 01-02-2014 3:06 PM
Hi Folks,
I have an IDOC to Soap Scenario, where the IDOC data will be mapped to an intermediate structure and then the entire output XML will be sent as a single field value in one of the fields in Soap Body. and this XML needs to be in Base 64 format. So I am looking for Java code which converts the entire XML into base 64 format. Any help in this regard is highly appreciated.
Thanks,
Ramesh
Hi Ramesh - Below blog should be helpful
check for Aaron's reply in the below thread for a UDF code.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To be more clear on my requirement, I am already using a java mapping to get the SOAP envelope format and also the XML data from Message mapping (intermediate structure) is read character by character in the java mapping with some additional custom details added to it.
Now all this data will be fed to one of the fields in the SOAP Body..
The SOAP body has 10 more fields apart from the XML Data field, and those fields are hard coded.
Hello,
>>The SOAP body has 10 more fields apart from the XML Data field, and those fields are hard coded.
I don't see any problem in that, in ur java mapping code which is actually creating target in soap envelope format u can easily read output of first message mapping convert it into base64 format (as shown below) and add it inside soap body with other hardcoded fields.
Thanks
Amit Srivastava
Hi Hareesh,
Part of my Jave code is shown below :
ediFilename,ediFile,binFile are 3 fields in the SOAP Body and the Actual Base64 conversion is needed for ediFile field.
whatever data coming in ediFile field needs to be converted into Base64 format.
Presently I am getting the proper output without base64 format, using the below code.
Code :
buffer.append( "<dig:ediFileName>");
buffer.append( "vabcf" );
buffer.append( "</dig:ediFileName>");
buffer.append( "<dig:ediFile>");
//Get header string and escape chars
buffer.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>");
String headerStr = INVOICE_HEADER ;
headerStr = headerStr.replaceAll("<", "<");
headerStr = headerStr.replaceAll(">", ">");
buffer.append(headerStr );
String strAfterTag = payloadStr.substring( startIndex );
// Adding invoice header so that that portions a
// Remove name spaces from tags
// Remove dig CreditNote from end tag
strAfterTag = strAfterTag.replaceAll("ns0:Invoice", "Invoice:Invoice");
//Replace name space prefixes..
strAfterTag = strAfterTag.replaceAll("ns0:", "dig:");
strAfterTag = strAfterTag.replaceAll("ns2:", "cbc:");
strAfterTag = strAfterTag.replaceAll("ns3:", "cac:");
//Replace Special characters
strAfterTag = strAfterTag.replaceAll("&", "&");
strAfterTag = strAfterTag.replaceAll("<", "<");
strAfterTag = strAfterTag.replaceAll(">", ">");
buffer.append( strAfterTag );
// Web Service Header Ending Portion
buffer.append( "</dig:ediFile>");
//return (String)
buffer.append( "<dig:binFileName>");
buffer.append( "per auras" );
buffer.append( "</dig:binFileName>");
Hi Ramesh - It comes along with the JRE.
You can download the jdk1.5.0_06 from below link and you'll be able find the jar under \jre\lib.
Hi Hareesh,,
We have added below code
String encoded = new sun.misc.BASE64Encoder().encode(strAfterTag.getBytes());
buffer.append(encoded);
and we have used import sun.misc.BASE64Encoder.*; in javamapping
But in the code it is showing an error as The Constructor BASE64Encoder().is not accesable due to restriction on the required library c:\java\jre6\lib\rt.jar
But we already have rt.jar file in the eclipse package...
You can find the fix @
http://stackoverflow.com/questions/5549464/import-sun-misc-base64encoder-got-error-in-eclipse
Go to Window-->Preferences-->Java-->Compiler-->Error/Warnings.
Select Deprecated and Restricted API. Change it to warning.
Change forbidden and Discouraged Reference and change it to warning. (or as your need.)
Ramesh, my java code helps ?
How can I help ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ricardo,
we are getting below error while using in UDF
Check Result for Object MM_File_Test
Source text of object Message Mapping: MM_File_Test | urn errors: |
Hi Ramesh,
You must use java mapping or UDF and into java code use:
public class Base64EncodingExample{
public static void main(String args[]) throws IOException {
String orig = "original String before base64 encoding in Java";
//encoding byte array into base 64
byte[] encoded = Base64.encodeBase64(orig.getBytes());
System.out.println("Original String: " + orig );
System.out.println("Base64 Encoded String : " + new String(encoded));
//decoding byte array into base64
byte[] decoded = Base64.decodeBase64(encoded);
System.out.println("Base 64 Decoded String : " + new String(decoded));
}
}K
ind regatrds,
Kind regards,
BR.
Ricardo Viana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello,
I would suggest you to use java mapping (just after message mapping in OM)and convert intermediate XML into base64:
Adjust below code as per ur structure
import java.io.*;
import java.util.*;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import com.sap.aii.mapping.api.AbstractTransformation;
import com.sap.aii.mapping.api.DynamicConfiguration;
import com.sap.aii.mapping.api.DynamicConfigurationKey;
import com.sap.aii.mapping.api.StreamTransformationConstants;
import com.sap.aii.mapping.api.StreamTransformationException;
import com.sap.aii.mapping.api.TransformationInput;
import com.sap.aii.mapping.api.TransformationOutput;
import com.sap.aii.utilxi.base64.api.Base64;
import java.util.Map;
public class Base64Conversion extends AbstractTransformation {
;
String StartMessage="";
String EndMessage="";
String TargetMessage ="";
public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput)
throws StreamTransformationException
{
//Converting Transformation Input to Input Stream
InputStream inputstream = transformationInput.getInputPayload().getInputStream();
OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
//Defining Byte Array Output Stream
byte[] buffer = new byte[1024*5000];
ByteArrayOutputStream baos = new ByteArrayOutputStream();
int len;
//Creating Target Message
StartMessage = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:MT xmlns:ns0=\"http://test\">";
EndMessage = "</ns0:MT>";
try
{
while ((len = inputstream.read(buffer)) > 0)
baos.write(buffer, 0, len);
String encode = Base64.encode(baos.toByteArray());
TargetMessage = StartMessage + "<Base64> " + encode + "</Base64>" + EndMessage;
outputstream.write(TargetMessage.getBytes());
}
catch(Exception exception)
{
throw new StreamTransformationException(exception.toString());
}
}
}
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.
User | Count |
---|---|
82 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
6 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.