on 02-28-2008 8:33 AM
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try to delete the line feed between the xml declaration and the root node in your input xml.
Regards,
Henrique.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You need to return the InputStream to OutputStream,
Maybe you try just:
outputStream = inputStream;
Regards
Stefan
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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);
}
User | Count |
---|---|
88 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.