Skip to Content

Decode Base64 Incoming Encoded information in SAP XI/PI using Java Mapping

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

Actual Payload Before Encoding


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



!|height=94|alt=Payload after Base64 Encoding|width=593|src=|border=0



+Help: For prototype purpose use the URL  ( 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>!|height=99|alt=Template XML generated by using FCC.|width=647|src=|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;<br />import;<br />import;<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;</p><p>import org.w3c.dom.Document;<br />import org.w3c.dom.NodeList;</p><p>import sun.misc.BASE64Decoder;<br />import;</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>!|height=197|alt=Assign Java Class in Interface Mapping|width=692|src=|border=0!</p><p> </p><p>Step 4: *Test you Interface Mapping

!|height=122|alt=Test your Interface mapping|width=700|src=|border=0!</body>

You must be Logged on to comment or reply to a post.
  • Hi,

    Why do you convert the Base64 document to XML in the file adapter. If you place a java mapping you would be able to convert the docment directly to the target XML document.
    The best solution would probably be to convert the Base64 in an adapter module.

    • Hi Daniel,

      If I directly send Encoded data i.e. series of character’s directly to the IE then how it will execute the JM, because the incoming Message type will not fit for it…so I create first Dummy MT and send XML from Adapter to IE.

      Right, AM is the best way to handle it. but as I mentioned in the both JM and Custom AM has there advantages and disadvantages…


      • >>because the incoming Message type will not fit for it…

        No. In case of Java mappings the incoming/outgoing messages are not validated against the Message types. So you can pass the whole encoded message and let the Java mapping handle it.


    • Hi Amol,

      As I mentioned in the Blog we can use others API also…I took sun.misc.BASE64Decoder just to depicts the scenario…we can achieve the same with also.


    • Hi Amol,

      As I mentioned in the Blog we can use others API also…I took sun.misc.BASE64Decoder just to depicts the scenario…we can achieve the same with also.


  • If I’m not mistaken, the Java Mapping approach will only work if there are no receiver determination conditions set as it needs to inspect the payload to determine appropriate receivers. In this respect, Adapter Module development is the ONLY option as the payload will be decrypted already when is goes into the Receiver Determination stage.
  • Hi Everybody!

    I’m testing the code, But I have problems right in this line:

    Document docNew = builder.parse (new ByteArrayInputStream(b));

    It looks like if can’t put the binaty table in the new document. Can anyone helpme?

    Thanks a lot!!