Skip to Content
Product Information
Author's profile photo Ricardo Viana

SAP PI/PO – Download Dowjones quotation rates – JavaMapping solution

Hello Folks on-premise,

Everything is good here or it’s time to fly (cloud) – SAP CPI !!!! ? πŸ˜€

I just would like to post one solution for a project that the requirement to download the list from DowJones in general used for quotation process and others related with financial aspects.


*IMPORTANT, you should require user and password to access the DowJones API with DowJones team.*



  1. Introduction

  2. Integration Diagram

  3. Integration Development Steps
    1. Process steps – Repository

      1. DJSPListResponse java – Outbound – First interface

      2. StreamToZipAttachment java – Inbound – Second interface

    2. Process steps – Directory

  4. SAP PI Testing first interface

  5. SAP PI Testing second interface

  6. Conclusion



Basically the integration is using API Rest ( HTTPS ) to download the list of files that can be used for financial aspects.

There are two API’s, one to download the list and another to download the ZIP file valid for that specific filename.

Integration Diagram:

I decide design the integration in SAP PI breaking in two times, first time download the list and add via java mapping inside one tag in the XML custom payload generated via java mapping and add those values as string.


The abaper should separate the values using the parameter ” ; ” for each file, stored and trigger the second time of integration, where a proxy generate will stimulate SAP PI with name of file that should download go for the second API to download the ZIP file.

The second interface is responsable to read the input stream and create the main documento payload as XML and the attachment of ZIP downloaded from the API and response to backend system.

The abap program should recive the data, extract the attachment from the second proxy and open zip file to be processed the details inside the file.


Clear for you?Β 

Let’s rock!

Integration Development Steps:

I will just high light with the picture and mention the steps of java mapping import.

  1. Repository:

    • Imported Archives – JavaMapping
  2. Directory:

    • ICO Receiver Interface
    • ICO Outbound Processing SFTP Channels

Process steps – Repository:

  • Repository: Imported Archives – JavaMapping

DJSPListResponse java – Outbound – First interface:

This first java mapping is responsable in the response of the first API, to push the list of files available, use the inputstream and add inside one XML tag <String>.

From this list the abap program will store, split and many table entry to call the second interface to download the zip files.




public class DJSPLListResponse extends AbstractTransformation {
	public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException
		try {
			//Info message is added to trace. 
			getTrace().addInfo("JAVA Mapping Called");
			InputStream inputstream = transformationInput.getInputPayload().getInputStream();
            OutputStream outputstream = transformationOutput.getOutputPayload().getOutputStream();
          //Getting input payload into strInContent.              
            byte[] b = new byte[inputstream.available()];
            String strInContent = new String(b);
            String tagdiv = strInContent.substring(strInContent.indexOf("<div>") + 5, strInContent.indexOf("</div>")).trim();
            String prefix = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:MT_Dowjones_SplListResponse xmlns:ns0=\"\">";
            String suffix = "</ns0:MT_Dowjones_SplListResponse>";
            String xmlPayload= "";
            xmlPayload = prefix + "<SPL><String>" + tagdiv + "</String></SPL>" + suffix;

		catch(Exception exception)
			//If exception occurs it is written to mapping trace.
			//stopping the mapping by throwing exception.
			throw new StreamTransformationException(exception.getMessage());


StreamToZipAttachment java – Inbound – Second interface:

This java mapping also you can use the generate a local files in your machine, so a completly generic code that you should adapt for your case but you can test locally before upload in the SAP PI via SAP Netweaver developer studio.

Another point, if you use local, there is no possibility to see the attachment but only the output Main Document payload.


package <your_package>;


import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;


public class StreamToZipAttachment extends AbstractTransformation {

	  /*public static void main(String[] args) throws Exception {
	  FileInputStream inFile = new FileInputStream(
	  "C:\\Users\\ricardo.viana\\Desktop\\MainDocument.txt"); FileOutputStream
	  outFile = new FileOutputStream(
	  "C:\\Users\\ricardo.viana\\Desktop\\Payload2.xml"); new
	  StreamToZipAttachment().local(inFile, outFile); }
	  private void local(FileInputStream inFile, FileOutputStream outFile)
	 throws Exception {
	  String xmlPayload = "";
	  xmlPayload="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"; xmlPayload =
	  "<ns1:MT_ECC_SplFileResponse xmlns:ns1=\"\">"
	  ); xmlPayload = xmlPayload.concat("<SPL_FILE>"); xmlPayload =
	  xmlPayload.concat("<Value>"); xmlPayload = xmlPayload.concat("asdsadada");
	  xmlPayload = xmlPayload.concat("</Value>"); xmlPayload =
	  xmlPayload.concat("</SPL_FILE>"); xmlPayload =
	  Document doc = toXmlDocument(xmlPayload);
	  String str = toXmlString(doc);

	public void transform(TransformationInput in, TransformationOutput out)
			throws StreamTransformationException {
		try {

			// AuditLogHelper logger =
			// AuditLogHelper.getInstance(in.getInputHeader().getMessageId());
			// logger.log("**** Java Mapping Starting ******",AuditLogStatus.SUCCESS);
			InputStream inputstream = in.getInputPayload().getInputStream();
			OutputStream outputstream = out.getOutputPayload()
			// logger.log("Static name of ZIP Attachment: " +
			// fileName,AuditLogStatus.SUCCESS);
			String xmlPayload = "";
			xmlPayload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
			xmlPayload = xmlPayload
					.concat("<ns1:MT_ECC_SplFileResponse xmlns:ns1=\"\">");
			xmlPayload = xmlPayload.concat("<SPL_FILE>");
			xmlPayload = xmlPayload.concat("<Value>");
		    xmlPayload = xmlPayload.concat("");
			xmlPayload = xmlPayload.concat("</Value>");
			xmlPayload = xmlPayload.concat("</SPL_FILE>");
			xmlPayload = xmlPayload.concat("</ns1:MT_ECC_SplFileResponse>");
			// Writing the output XML Payload from the concatenation above to
			// string xmlPayload
			Document doc = toXmlDocument(xmlPayload);
			String str = toXmlString(doc);
			// Instance of create attachment in the outputPayload
			OutputAttachments outputAttachments = out.getOutputAttachments();
			// Check the bytes of inputstream message
			byte[] b = new byte[inputstream.available()];
			// Instance a new attachment
			// Instance of variable type Byte B if there is inputstream
			// available
			try {
				// Check the lenght of inputstream if is bigger than zero (0)
				if (b.length != 0) {
					// Read the inputstream bytes.;
					// Creating a new attachment in the Main Document Payload as
					// a Content-Type application/zip with fix value name
					Attachment newAttachment = outputAttachments.create(
							"", "application/zip", b);
					// Set the new attachment in the Main Document Payload
			} catch (Exception e) {
				// logger.log("**** Exception ******" +
				// e.getMessage(),AuditLogStatus.SUCCESS);


		catch (Exception e) {
			throw new StreamTransformationException("Error: " + e.getMessage());


	private static Document toXmlDocument(String str)
			throws ParserConfigurationException, SAXException, IOException {

		DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory
		DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
		Document document = (Document) docBuilder.parse(new InputSource(
				new StringReader(str)));

		return document;

	private static String toXmlString(Document document)
			throws TransformerException {
		TransformerFactory transformerFactory = TransformerFactory
		Transformer transformer = transformerFactory.newTransformer();
		DOMSource source = new DOMSource((Node) document);
		StringWriter strWriter = new StringWriter();
		StreamResult result = new StreamResult(strWriter);

		transformer.transform(source, result);

		return strWriter.getBuffer().toString();



Process steps – Directory:

I will not present the step by step the developer should know, but nothing special, just in the receiver REST adapter there is a custom setup to extract the name of file to complete the end url address extract as custom parameter in the adapter setup

  • ICO First Interface and ICO Second Interface

First download list and second file.

First Adapter receiver REST:

Second adapter receiver setup:


As you can see in the picture above, the end address:{Input}

The value of {input}Β  will be replace from the value that comes in the Main Document Payload into tag <value>


SAP PI Testing first interface:

This part of code above is responsible to extract all the value from the tag <div>Β  html version from the replay call API list of files available:

String tagdiv = strInContent.substring(strInContent.indexOf(“<div>”) + 5, strInContent.indexOf(“</div>”)).trim();

Request dummy XML:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">

    <form method="post" action="" id="form1">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="no-longer-used" />

<input type="hidden" name="__VIEWSTATEGENERATOR" id="__VIEWSTATEGENERATOR" value="10250408" />

The java mapping extract whole list from tag <div> and create a main document payload response as you can see below with the list inside tag <String>:

Response XML:

<?xml version="1.0" encoding="UTF-8"?>

In the abap side the program is responsable to slipt name of file based on comma ‘, ‘ store what is FULL file and DELTA FILE.

Difference of full and delta is the name of file, contains f or contains d.


SAP PI Testing second interface:

The second interface contains the XML with name of file that should be download:

<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_ECC_SplFileRequest xmlns:ns0="">



Main Payload response.


I didn’t add dynamic configuration because the abap contains the control of each file that has been request so the name of <Value>Β  or the attachment doesn’t matter.

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

Attachment with fix value name in the main payload response above with content-type – Application/zip



This is a interface architecture, designer and development to integrate with DowJones to download files for rates that can be used for finance stream and others.

I hope you learn a new approach or design of interface and hope to see you in the next blog.





Assigned Tags

      Be the first to leave a comment
      You must be Logged on to comment or reply to a post.