cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in Java mapping

Former Member
0 Kudos

Hi,

I have developed java mapping. I am able to generate the target xml file properly in external tool, where as when I tried to use same thing in XI IR. It is throwing an exception.

Please help me to find out whats wrong in the below code:

While loading into XI i removed the main method.

/*

  • Created on May 26, 2006

*

  • To change the template for this generated file go to

  • Window - Preferences - Java - Code Generation - Code and Comments

*/

package JavaMapTest;

import java.io.InputStream;

import java.io.OutputStream;

import java.io.FileInputStream;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.util.Hashtable;

import java.util.Map;

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.parsers.ParserConfigurationException;

import javax.xml.transform.Transformer;

import javax.xml.transform.TransformerFactory;

import javax.xml.transform.dom.DOMSource;

import javax.xml.transform.stream.StreamResult;

import org.w3c.dom.Document;

import org.w3c.dom.Element;

import org.w3c.dom.NodeList;

import org.w3c.dom.Text;

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.StreamTransformationException;

/**

  • @author yaseenm

*

  • To change the template for this generated type comment go to

  • Window - Preferences - Java - Code Generation - Code and Comments

*/

public class TransformXML implements StreamTransformation{

private Map map;

private Document sourceDocument = null;

private Document docOut = null;

private Element root;

private String field1 = "";

public void setParameter(Map param) {

map = param;

}

public void execute(InputStream in, OutputStream out)

throws StreamTransformationException {

Element elm ;

Text tagValue;

DOMSource domS = null;

DocumentBuilder documentBuilder = null;

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

factory.setValidating(true);

factory.setNamespaceAware(true);

try {

documentBuilder = factory.newDocumentBuilder();

documentBuilder.setErrorHandler(null);

} catch (ParserConfigurationException e) {

e.printStackTrace();

}

try {

// write XML

TransformerFactory transformerFactory = TransformerFactory.newInstance();

Transformer transformer = transformerFactory.newTransformer();

// System.out.println("b4 parsing");

sourceDocument = documentBuilder.parse(in);

// System.out.println("b4 document builder");

docOut = documentBuilder.newDocument();

NodeList nodeList = sourceDocument

.getElementsByTagName("Source_MT");

root = docOut.createElement("Target_MI");

docOut.appendChild(root);

Element temp = (Element) nodeList.item(0);

NodeList N1 = temp.getElementsByTagName("field1");

field1 = N1.item(0).getFirstChild().getNodeValue();

elm = docOut.createElement("Tarfield1");

docOut.createDocumentFragment();

root.appendChild(elm);

tagValue = docOut.createTextNode(field1);

elm.appendChild(tagValue);

domS = new DOMSource(docOut);

transformer.transform(domS, new StreamResult(out));

}catch (Exception e) {

e.printStackTrace();

}

}

public static void main(String[] args) {

System.out.println("Start Of Application1");

TransformXML convertIDOC = new TransformXML();

convertIDOC.setParameter(new Hashtable());

try {

convertIDOC.execute(new FileInputStream("C:/anilx.xml"),new FileOutputStream("C:/output123.xml"));

}catch (FileNotFoundException e) {

e.printStackTrace();

} catch (StreamTransformationException e) {

e.printStackTrace();

}

System.out.println("Done");

}

}

Thanks In Advance.

Yaseen

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Krishna,

I have removed Mian method while uploading to IR. I followed the links what you have sent to develop this code. Please let me know if you can point out the problem in code?

Thanks,

Yaseen

Former Member
0 Kudos

Hi Yaseen,

AFAIK Keeping main method in the mapping program while importing and executing the the same will not create any problems in Runtime. Because XI calls only the <b>execute()</b> method and ignores rest of the methods if they are not called from <b>execute()</b>.

I think your problem is you are trying to generate the Target message with Root node as <b>Target_MI</b>,Instead of this you have to use <b>Target_MT</b>.

Hope this solves your problem.

Regards,

Ananth

moorthy
Active Contributor
0 Kudos

Hi,

Given code shows Main Method here.. just check the code once again with the help of following links

http://help.sap.com/saphelp_nw2004s/helpdata/en/e2/e13fcd80fe47768df001a558ed10b6/content.htm

But following blog uses SAX Parser-

/people/prasad.ulagappan2/blog/2005/06/29/java-mapping-part-ii

https://www.sdn.sap.com/irj/sdn/elearning?class=/sdntv/main.asp?mediaId=109

Thanks,

Moorthy