Additional Blogs by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
Former Member

Many times we have requirements to decode the “base64 encoded message” in XI/PI so it can be used in IE for message processing. In this blog I tried to demostrate about the steps that will help us to decode the data using Java Mapping

Actual source XML

 

After Base64 Encoding: (incoming message to XI/PI)

 

 

!https://weblogs.sdn.sap.com/weblogs/images/251803663/P2.JPG|height=94|alt=Payload after Base64 Encoding|width=593|src=https://weblogs.sdn.sap.com/weblogs/images/251803663/P2.JPG|border=0

 

 

+Help: For prototype purpose use the URL http://ostermiller.org/calc/encode.html  (http://ostermiller.org/calc/encode.html) to encode your actual payload. +

 

 

There are two ways to handle such scenarios 

 

  • Java Mapping : Easy to design, develop and able to test using Java IDE externally. Also possible to test it in Interface Mapping without executing/testing the whole interface.

So each of the above has there own advantages and disadvantages. Here with the help of Java mapping we will look how it is possible to implement such scenario. In the next blog I will demostrate the same using Custom Adapter Module.

*Step 1: Convert the input.txt information into and XML format (XML template) using File Content Conversion in the Sender File Adapter. <Details> node contains the actual encoded Information/XML payload. </p><p>!https://weblogs.sdn.sap.com/weblogs/images/251803663/P3.JPG|height=99|alt=Template XML generated by using FCC.|width=647|src=https://weblogs.sdn.sap.com/weblogs/images/251803663/P3.JPG|border=0!</p><p>Step 2: Java code for Base64 decoding, this is simply lines of Java language just to demostrate about Base64 decoding in XI. You can uses other API's in order to achieve Base64 decoding/Encoding.</p><p> </p><p>package domDemo;</p><p>import java.io.ByteArrayInputStream;<br />import java.io.InputStream;<br />import java.io.OutputStream;<br />import java.util.Map;</p><p>import javax.xml.parsers.DocumentBuilder;<br />import javax.xml.parsers.DocumentBuilderFactory;<br />import javax.xml.transform.Transformer;<br />import javax.xml.transform.TransformerFactory;<br />import javax.xml.transform.dom.DOMSource;<br />import javax.xml.transform.stream.StreamResult;</p><p>import org.w3c.dom.Document;<br />import org.w3c.dom.NodeList;</p><p>import sun.misc.BASE64Decoder;<br />import com.sap.aii.mapping.api.StreamTransformation;</p><p>public class JMDecodeDetails implements StreamTransformation {<br /> private Map param=null;<br /> public void setParameter(Map param){<br />  this.param=param;<br /> }<br /> public void execute(InputStream in, OutputStream out){<br />  try{<br />      <br />   DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();<br />   DocumentBuilder builder = factory.newDocumentBuilder();<br />   Document docOld = builder.parse(in);<br />   //Get the node name Details that contains the Based64 Encoded information.. <br />   NodeList details = docOld.getElementsByTagName("Details");<br />   //Get the Text of Node.<br />   String data = details.item(0).getChildNodes().item(0).getNodeValue();<br />   //Instantiate an object of BASE64Decoder...<br />   BASE64Decoder decoder =  new BASE64Decoder();<br />   //Decode the encoded information....<br />   byte b[] = decoder.decodeBuffer(data);<br />   //Parse the decoded data i.e. nothing but the real payload....<br />   Document docNew = builder.parse(new ByteArrayInputStream(b));<br />   <br />   TransformerFactory transformerFactory = TransformerFactory.newInstance();<br />   Transformer transformer =  transformerFactory.newTransformer();<br />   DOMSource source = new DOMSource(docNew);<br />   StreamResult result = new StreamResult(out);<br />   transformer.transform(source,result);<br />  }<br />  catch (Exception e){<br />   System.out.println(e);<br />  }  <br /> }<br />}<br /> </p><p>Step 3: Create the jar file, import it into IR and assign it in Interface Mapping</p><p>!https://weblogs.sdn.sap.com/weblogs/images/251803663/P5.JPG|height=197|alt=Assign Java Class in Interface Mapping|width=692|src=https://weblogs.sdn.sap.com/weblogs/images/251803663/P5.JPG|border=0!</p><p> </p><p>Step 4: *Test you Interface Mapping

!https://weblogs.sdn.sap.com/weblogs/images/251803663/P6.JPG|height=122|alt=Test your Interface mapping|width=700|src=https://weblogs.sdn.sap.com/weblogs/images/251803663/P6.JPG|border=0!</body>

13 Comments