on 04-12-2006 12:46 PM
Hi,
we have created a Java-Mapping prgram which has the task to validate incoming documents using a schema.
When we test this program, there would be thrown an exception, if the document is not valid. But if the document is valid the program kills the J2EE engine completley. All the services are stopped.
Does anybody know, why this happens?
We used the Blog "Validating messages in XI using XML-Schema" as template for our program.
Here our mapping class:
public class DocumentValidation implements StreamTransformation
{
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";
private Map param = null;
private AbstractTrace trace = null;
public void setParameter (Map param)
{
this.param = param;
if (param == null)
{
this.param = new HashMap();
}
}
public void execute(InputStream in, OutputStream out)
{
try
{
trace = (AbstractTrace)param.get(
StreamTransformationConstants.MAPPING_TRACE );
String messageID = (String)param.get(
StreamTransformationConstants.MESSAGE_ID);
trace.addInfo("Validating document with MessageID " + messageID + " ...");
DocumentValidation dv = new DocumentValidation();
InputStream schema = null;
String schemaName = new String("orders02.xsd");
schema = dv.getClass().getClassLoader().getResourceAsStream(schemaName);
SAXParserFactory spf = SAXParserFactory.newInstance();
spf.setNamespaceAware(true);
spf.setValidating(true);
SAXParser sp = spf.newSAXParser();
sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
sp.setProperty(JAXP_SCHEMA_SOURCE, schema);
sp.parse(in, new ParseErrorHandler());
// InputStream nach OutputStream kopieren
int readcount;
byte[] buffer = new byte[1024];
while ( (readcount = in.read(buffer)) > -1)
{
out.write(buffer, 0, readcount);
}
trace.addInfo("Stream was copied ... ");
out.flush();
}
catch(Exception ex)
{
throw new RuntimeException("Error in Validation: " + ex);
}
}
}
final class ParseErrorHandler extends DefaultHandler
{
public void error(SAXParseException ex) throws SAXException
{
throw ex;
}
}
I hope anybody can help us.
Regards
Thorsten
Hi,
Test your prg first
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
Regards
Suraj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Suraj,
I have tested my program.
The problem is the call of the function "parse".
There would be generated a Stackoverflow.
I tried to use the DOM-parser but I get the same effect.
Our schema file has a size of 160kB and I think that could be the problem. But the xsd-file of ORDERS02 has such a size.
Has anybody an idea how to solve this problem?
Regards
Thorsten
Are you sure the value
static final String JAXP_SCHEMA_LANGUAGE =
"http://java.sun.com/xml/jaxp/properties/schemaLanguage";
is correct?This is because I got an exception when tried running your code in NWDS..stacktrace below for your ref.
<i>org.xml.sax.SAXNotRecognizedException: Property: http://java.sun.com/xml/jaxp/properties/schemaLanguage
at org.apache.crimson.parser.XMLReaderImpl.setProperty(XMLReaderImpl.java:272)at org.apache.crimson.jaxp.SAXParserImpl.setPropertySAXParserImpl.java:190)at
DocumentValidation.execute(DocumentValidation.java:67)
at DocumentValidation.main(DocumentValidation.java:100)</i>
The statement at line number 67 in the code is
sp.setProperty(JAXP_SCHEMA_LANGUAGE, W3C_XML_SCHEMA);
~ Amol
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Amol,
thanks for your answer.
The error you describing appears if you use an earlier version than 1.2 of JAXP. In Eclipse 2.1 an earlier version of JAXP is integrated, so you can't test this program there.
In SAPHelp <a href="http://help.sap.com/saphelp_nw04/helpdata/de/c4/e1343e8c7f6329e10000000a114084/frameset.htm">http://help.sap.com/saphelp_nw04/helpdata/de/c4/e1343e8c7f6329e10000000a114084/frameset.htm</a> you can find the original code from SAP. In this code you can also find this string. XI supports version 1.2 of JAXP. That couldn't be the problem.
If the document isn't valid I get an error, that the document isn't valid. The problem only exists when the document is valid.
It's very strange.
Regards
Thorsten
User | Count |
---|---|
83 | |
10 | |
10 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.