I get TimeoutException while validating XML over XSD schema, and the thread associated with checker is hung.
Why is it so? How to avoid this?
Stack trace:
TimeoutManage I WTRN0124I: When the timeout occurred the thread with which the transaction is, or was most recently, associated was Thread[WebContainer : 3,5,main]. The stack trace of this thread when the timeout occurred was:
java.net.SocketInputStream.socketRead0(Native Method)
java.net.SocketInputStream.read(SocketInputStream.java:140)
java.io.BufferedInputStream.fill(BufferedInputStream.java:229)
java.io.BufferedInputStream.read1(BufferedInputStream.java:269)
java.io.BufferedInputStream.read(BufferedInputStream.java:328)
sun.net.www.http.HttpClient.parseHTTPHeader(HttpClient.java:700)
sun.net.www.http.HttpClient.parseHTTP(HttpClient.java:645)
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1205)
org.apache.xerces.impl.XMLEntityManager.setupCurrentEntity(Unknown Source)
org.apache.xerces.impl.XMLVersionDetector.determineDocVersion(Unknown Source)
org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
org.apache.xerces.impl.xs.opti.SchemaParsingConfig.parse(Unknown Source)
org.apache.xerces.impl.xs.opti.SchemaDOMParser.parse(Unknown Source)
org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(Unknown Source)
org.apache.xerces.impl.xs.traversers.XSDHandler.resolveSchema(Unknown Source)
org.apache.xerces.impl.xs.traversers.XSDHandler.constructTrees(Unknown Source)
org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(Unknown Source)
org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(Unknown Source)
org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(Unknown Source)
org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(Unknown Source)
javax.xml.validation.SchemaFactory.newSchema(Unknown Source)
my.utils.XmlUtils.validate(XmlUtils.java:38)
The code snippet used for validation:
SchemaFactory schemaFactory =
SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
try {
Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));
Validator validator = schema.newValidator();
...
Exception occurs at line:
Schema schema = schemaFactory.newSchema(new StreamSource(new StringReader(xsd)));
Hard to be sure without seeing the actual XSD, but most likely your schema isn’t self contained but contains one or more include statements that reference external URLs. The schemaFactory may try to fetch them to build a complete XSD.
What points to this is among other things the call to
getSchemaDocument()in your stack trace which is trying to get a schema document over HTTP in the middle of executingparseSchema()on the xsd you’re passing in.