Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Exception in Java Mapping

hi All,

I'm trying to validate the incoming XML against a given XSD using Java Mapping.. When i execute it i get the following error in the Mapping...

com.sap.engine.lib.xml.util.NestedException -> com.sap.engine.lib.xml.parser.ParserException -> java.io.IOException: Parsing an empty source. Root element expected!

Please do help me out..... I have given my java Code Below.....

Note:The XSD is attached in the same zip file which contains java class and the zip file is imported in the Imported ARchive Area....

package cts.com.XSD;

import java.io.*;

import java.util.Map;

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

import javax.xml.parsers.DocumentBuilder;

import javax.xml.parsers.DocumentBuilderFactory;

import javax.xml.transform.OutputKeys;

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;

public class TestJavaMapping implements StreamTransformation

{

Map param=null;

public void setParameter(Map arg0)

{

this.param=arg0;

}

public void execute(InputStream in, OutputStream out) throws StreamTransformationException

{

byte b[];

byte b1[];

try

{

b = new byte[in.available()];

in.read(b);

AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);

InputStream Schemainput= new

TestJavaMapping().getClass().getClassLoader().getResourceAsStream("cts/com/XSD/ShipmentDetails.xsd");

b1 = new byte[Schemainput.available()];

Schemainput.read(b1);

String XsdString =new String(b1);

trace.addInfo("XSD obtained");

DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();

docBuilderFactory.setNamespaceAware(true);

docBuilderFactory.setValidating(true);

trace.addInfo("After Setting True");

docBuilderFactory.setAttribute("http://java.sun.com/xml/jaxp/properties/schemaLanguage","http://www.w3.org/2001/XMLSchema");

docBuilderFactory.setAttribute( "http://java.sun.com/xml/jaxp/properties/schemaSource",XsdString);

trace.addInfo("After Setting ATtribute");

trace.addInfo("B4 Parsing");

DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();

Document validDoc = docBuilder.parse(in);

trace.addInfo("After Parsing");

out.write(b);

}

catch(Exception e)

{

AbstractTrace trace=(AbstractTrace)param.get(StreamTransformationConstants.MAPPING_TRACE);

trace.addInfo(e.getMessage());

}

}

}

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question