cancel
Showing results for 
Search instead for 
Did you mean: 

Getting Error in java mapping: Parsing empty source. Root element expected!

gopalkrishna_baliga
Participant
0 Kudos

Hi Experts,

I am using java mapping for schema validation of input message. I have followed all the standard procedures and implemented the java class in the interface mapping.

My interface mapping is like this:

OrderData --->Java Class ---SchemaValidate

Mesg Map ---OrderData_to_BAP --->BAPI Msg

So first I want to validate the schema of the input message. If the input message is invalid then XI should throw an exception. Then I use the actual message mapping to map the input order data to the BAPI input parameters.

In the java code I am using xerces parser.

The java code works fine when I run it as a standalone application.

The interface mapping also works fine if I don't include the java mapping. Ofcourse schema validation does not happen.

But when I test the interface mapping by including the java mapping then I am getting the error:

Call method execute of the application Java mapping SchemaValidate

Java mapping SchemaValidate completed. (execute() of SchemaValidate

com.sap.aii.utilxi.misc.api.BaseRuntimeException: Parsing an empty source. Root element expected!

What am I doing wrong? Why it is not getting the root element?

My Java code is as follows:

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

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

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

import java.io.*;

import java.util.Map;

import javax.xml.parsers.*;

import org.xml.sax.helpers.*;

import org.xml.sax.*;

import org.apache.xerces.jaxp.*;

/**

  • Sample mapper for SAP-XI

  • @author Gopal

*/

public class SchemaValidate implements StreamTransformation {

//Constants when using XML Schema for SAX parsing.

static final String JAXP_SCHEMA_LANGUAGE =

"http://java.sun.com/xml/jaxp/properties/schemaLanguage";

static final String W3C_XML_SCHEMA =

"http://www.w3.org/2001/XMLSchema";

static final String JAXP_SCHEMA_SOURCE =

"http://java.sun.com/xml/jaxp/properties/schemaSource";

/**

  • Injection of mapping parameters

  • from integration engine

*

  • @param map Map with configuration data

*/

public void setParameter(Map map) {

}

/**

  • Mapping implementation

*

  • @param inputStream Input data from integration engine

  • @param outputStream Output data to integration engine

*/

public void execute(InputStream inputStream,

OutputStream outputStream)

throws StreamTransformationException {

try {

// obtain an object of class javax.xml.parsers.SAXParser,

SAXParserFactory spf = SAXParserFactoryImpl.newInstance();

spf.setNamespaceAware(true);

spf.setValidating(true);

SAXParser sp = spf.newSAXParser();

// setup the schema file

sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);

sp.setProperty(JAXP_SCHEMA_SOURCE, new File("IOReqMsgSchema.xsd"));

//parse the input xml using the given schema

sp.parse(inputStream, new ParseErrorHandler());

}

catch(SAXException se) {

se.printStackTrace();

}

catch ( Exception e ) {

throw new StreamTransformationException( e.getMessage() );

}

}

}

My input message is :

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

<ns0:OrderCreate_request xmlns:ns0="mynamespace">

<ORDER>HTEST1234567</ORDER>

<ORDER_TYPE>z001</ORDER_TYPE>

<ORDER_NAME>Test Order</ORDER_NAME>

<CO_AREA>INTC</CO_AREA>

<CCTR_POSTED>1234567890888888888</CCTR_POSTED>

<CURRENCY>USD</CURRENCY>

<PERSON_RESP>12345679</PERSON_RESP>

</ns0:OrderCreate_request>

Kindly help! please this is urgent!!!!!!

Thanks

Gopal

Edited by: gopalkrishna baliga on Feb 28, 2008 9:34 AM

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Gopal,

This Blog helps you with the schema validation using java mapping.Please check it out.

/people/ranjit.deshmukh/blog/2008/01/22/the-hitchhikers-guide-to-validation

Thanks,

Bhargav

Note:Award points if found useful.

gopalkrishna_baliga
Participant
0 Kudos

Hi Bhargav,

The code given in your link does not work for me.

Please help!

-Gopal

Former Member
0 Kudos

Hi,

Where you able to fix this problem with parsing. If so please let me know how you have fixed this error.

thanks,

Joe.P

henrique_pinto
Active Contributor
0 Kudos

Try to delete the line feed between the xml declaration and the root node in your input xml.

Regards,

Henrique.

Former Member
0 Kudos

Hi,

your problem is almost 100% certain to be with the parser engine version you are using standalone vs the one in XI / PI. You did not mention which version of XI / PI you are using but in any case do the following ot verify this. Find the parser library from your XI / PI server (ends in .jar and might still be something like inqmyxml.jar or alike). After you find it you can use it in your local environment.

Alternatively upload the standalone parser library with your mapping and depending on which order the classpath is built you might be able to use your standalone libary instead. Whatever you do: DO NOT REPLACE the XI/PI's own XSL library with your own (have seen this done, not pretty).

Cheers

Kalle

VijayKonam
Active Contributor
0 Kudos

I beleive,

After the name space node, you might have to have a root node. Without a root node, the XML would be invalid.

VJ

henrique_pinto
Active Contributor
0 Kudos

> I beleive,

> After the name space node, you might have to have a root node. Without a root node, the XML would be invalid.

>

There's no such thing as a "namespace node".

The wrapper node is the root node, whether it declares namespaces or not.

Henrique.

gopalkrishna_baliga
Participant
0 Kudos

Hi Kalle,

I am using XI7.0.

-Gopal

stefan_grube
Active Contributor
0 Kudos

You need to return the InputStream to OutputStream,

Maybe you try just:

outputStream = inputStream;

Regards

Stefan

gopalkrishna_baliga
Participant
0 Kudos

Hi Stefan,

OutputStream = InputStream

does not work.

Do you have any sample code to convert imputstream to outputstream? Kindly help!

I will be greatful to you.

Regards

Gopal

stefan_grube
Active Contributor
0 Kudos
int c;
while ((c = inputStream.read()) != -1)
outputStream.write(c);

not the best, but the easiest solution.

Stefan

gopalkrishna_baliga
Participant
0 Kudos

Hi Stefan,

I did the code changes to return output stream and the java code works perfectly in standalone mode in my PC.

But when I use the same in the Java mapping with XI then It throws an error "Getting Error in java mapping: Parsing empty source. Root element expected!".

My XI J2EE server has JDK1.4.3.11.

Is there any limitation of using SAX parser in XI? If Yes, then which parser should be used for schema validation in XI?

I have included the XSD file for schema validation along with class files in the .jar file. This jar file is then imported in XI repository. Is the XI engine not able to read the XSD file?

Do I have to handle reading XSD file differently? Any suggession how?

Is this parser error due to some security access?

Kindly help me! I have been struggling with this problem since 2 weeks. I will be greatfull to you if you can help me.

Thanks

Gopal

stefan_grube
Active Contributor
0 Kudos

You cannot use xerxes in Java Mapping.

Use the methods of the library sapxmltoolkit.jar. There is a SAX parser included as well.

Regards

Stefan

Former Member
0 Kudos

Hi,

I'm not using a xerxes parser I'm using DOM parser I'm still getting the same error. here is the code that I'm using.

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder = null;

factory.setNamespaceAware(true);

factory.setValidating(false);

builder = factory.newDocumentBuilder();

Document docRsp = null;

try {

File file = new File("H:
user_data
test.xml");

docRsp = builder.parse(file);

} catch (Exception e) {

trace.addWarning("Error when parsing RFC Response - " + e.getMessage());

}

trace.addInfo("RFC Response XML: " + docRsp.toString());

String res = "";

try {

res = docRsp.getElementsByTagName(TAG_RES).item(0).getFirstChild().getNodeValue();

} catch (Exception e) {

trace.addWarning("Result value not found in DOM - " + e);

}

stefan_grube
Active Contributor
0 Kudos

>

File file = new File("H:\\user_data\\test.xml");

Do you really expect, that this would work on the XI server?

Edited by: Stefan Grube on Apr 9, 2008 11:33 PM

Former Member
0 Kudos

Hi,

That's my file location on my XI server. and Yes it does works.

thanks,

Joe.P

stefan_grube
Active Contributor
0 Kudos

But it does not make any sense to read a file in the XI server within Java mapping.

You have the method

public void execute(InputStream inputStream,
OutputStream outputStream)

You get the data in inputStream and provide the result in outputStream.

That is how Java Mapping works.