构建服务器上的java XML验证速度较慢
我们转移到一个新的构建服务器,现在XML验证比以前慢了几个数量级,导致我的构建超时。我可以通过注释验证逻辑来恢复以前的构建性能,验证逻辑的编码如下:
public static void validate(File xsd, final File xmlSample) {
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false); //disable DTD validation
factory.setNamespaceAware(true);
SchemaFactory schemaFactory = SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema");
factory.setSchema(schemaFactory.newSchema(new Source[]{new StreamSource(xsd)}));
SAXParser parser = factory.newSAXParser();
XMLReader reader = parser.getXMLReader();
reader.setErrorHandler(new ErrorHandler() {
@Override
public void warning(SAXParseException exception) {
message("An XSD validation warning occurred: " + exception.getMessage(), true, exception);
exception.printStackTrace();
}
@Override
public void error(SAXParseException exception) {
message("An XSD validation error occurred: " + exception.getMessage(), true, exception);
exception.printStackTrace();
}
@Override
public void fatalError(SAXParseException exception) {
message("An XSD validation fatal error occurred: " + exception.getMessage() + "; " + xmlSample.getName(), true, exception);
exception.printStackTrace();
}
});
reader.parse(new InputSource(new FileInputStream(xmlSample)));
} catch (SAXException e) {
message("ERROR: An XSD validation error occurred.", true, e);
} catch (ParserConfigurationException e) {
message("ERROR: A parser configuration error occurred.", true, e);
} catch (IOException e) {
message("ERROR: An input/output exception occurred.", true, e);
}
}
新的构建服务器运行Java 7和64位Linux 2.6.32
有人建议在验证期间进行某种网络访问,从而导致此问题,但模式和XML文档作为本地文件传入
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://********/ddgen/indadm_xsd_gso_3"
targetNamespace="http://********/ddgen/indadm_xsd_gso_3"
elementFormDefault="qualified">
<!--Schema generator version: 3.5.3-->
<xsd:element name="indadm" type="indadm"/>
....
编辑:用于从w3导入XML模式的模式。组织;删除import语句(这是一个bug)使测试运行时间更加稳定(每个测试1分钟),而不是在旧服务器上运行10秒以下的时间,旧服务器当然有要从w3导入的bug代码。组织。所以我会说w3。组织导入是问题之一,但不是唯一的问题
共 (0) 个答案