cancel
Showing results for 
Search instead for 
Did you mean: 

Java map in multimap IDOC as source and file as target

Former Member
0 Kudos

Hi All

I am doing a multimap 1:n IDOC to multiple files scenario using JAVA map

I am getting an error while executing the java map

Mapping "http://xxxxxxxxx" failed to execute: MappingException: Mapping failed in runtimeApplication mapping program com/certainteed/tms/jmap/ordermultimap/local/MapOrderIDOCToTMSFile throws a stream transformation exception: Mapping Exception: while trying to invoke the method org.w3c.dom.Node.getChildNodes() of a null object loaded from local variable 'node', ApplicationException: Application mapping program com/certainteed/tms/jmap/ordermultimap/local/MapOrderIDOCToTMSFile throws a stream transformation exception: Mapping Exception: while trying to invoke the method org.w3c.dom.Node.getChildNodes() of a null object loaded from local variable 'node', StreamTransformationException: Mapping Exception: while trying to invoke the method org.w3c.dom.Node.getChildNodes() of a null object loaded from local variable 'node', NullPointerException: while trying to invoke the method org.w3c.dom.Node.getChildNodes() of a null object loaded from local variable 'node'

The source IDOC XML has this format below in the mapping editor and it looks like the document is always coming as null in the java map code for some reason. Any idea?

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

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

   <ns0:Message1>

      <ORDERS05>

<IDOC>

--

---

---

</IDOC>

</ORDERS05>

this is my java map code excerpt

public void transform(TransformationInput in, TransformationOutput out)

  throws StreamTransformationException {

  AbstractTrace trace = null;

   try {

  // Initialise Trace

  trace = getTrace();

   DocumentBuilderFactory tfactory = DocumentBuilderFactory

   .newInstance();

   //tfactory.setNamespaceAware(true);

   DocumentBuilder tbuilder = tfactory.newDocumentBuilder();

   Document doc = tbuilder.parse(in.getInputPayload()

  .getInputStream());

   doc.getDocumentElement().normalize();

// Create new output document

  Document outDoc = tbuilder.newDocument();

Node idocNode = null;

            NodeList children = doc.getChildNodes();

            for(int i=0;i<children.getLength();i++)

            {

Node child = children.item(i);
short childType = child.getNodeType();
if(childType == Node.ELEMENT_NODE){
String nodeName = child.getNodeName();
if(nodeName.equals("ORDERS05")){
idocNode = child.getFirstChild();
break;
}
}

            }

And rest of the logic ..the error seems to be occuring at the statement "NodeList children = doc.getChildNodes();" It is not finding any value in doc to get the child nodes and throwing null exception. any help is really appreciated

thx

mike

Message was edited by: Agasthuri Doss

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Mike

Is your input IDoc-XML file in a single line, or pretty-printed and indented with each element on a separate line?

If it is the latter, normally I  collapse the data into a single line before passing it into the parse() method of the DocumentBuilder. Here is the logic for the method which I used.


private InputStream collapseIndentedXMLStream (InputStream inStream) throws IOException  {

  BufferedReader br = new BufferedReader(new InputStreamReader(inStream));

  StringBuilder sb = new StringBuilder();

  String lineContent;

  while ((lineContent = br.readLine()) != null) {

    sb.append(lineContent);

  }

  br.close();

  // Remove all whitespaces between > and  <

  String consolidatedLine = sb.toString().replaceAll(">\\W+<", "><");

  return new ByteArrayInputStream(consolidatedLine.getBytes());

}

Maybe you can try to see if it is helpful for your case.

Rgds

Eng Swee

Answers (0)