Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
17.12.08, 18.12.02
Description
Since we migrate OFBiz to gradle, some xsd are resolved during the xml validation process directly on internet.
But in the code base, by default we tried to resolve it before on the local code base and only if nothing is found we call on external.
On UtilXml.java:423 :
public static Document readXmlDocument(InputStream is, boolean validate, String docDescription)[...] /* Standard JAXP (mostly), but doesn't seem to be doing XML Schema validation, so making sure that is on... */ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setValidating(validate); [...] DocumentBuilder builder = factory.newDocumentBuilder(); if (validate) { LocalResolver lr = new LocalResolver(new DefaultHandler()); ErrorHandler eh = new LocalErrorHandler(docDescription, lr); builder.setEntityResolver(lr); builder.setErrorHandler(eh); } document = builder.parse(is);
The validating function call a local resolver that try to resolve through UtilURL.java the xsd file extrat form the schema location, with :
schemaLocation="http://ofbiz.apache.org/Widget-Theme http://ofbiz.apache.org/dtds/widget-theme.xsd"
ofbiz try to resolve :
widget-theme.xsd
However, this resolution failed, the code present on UtilURL.java:82
public static URL fromResource(String resourceName, ClassLoader loader) { URL url = urlMap.get(resourceName); if (url != null) { try { return new URL(url.toString()); } catch (MalformedURLException e) { Debug.logWarning(e, "Exception thrown while copying URL: ", module); } } [...]
Execute different scan through the classLoader.
If we check what is loaded on the ofbiz start with gradle we can see that only one xsd directory is present :
resources { srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java') srcDirs += getDirectoryInActiveComponentsIfExists('config') srcDirs += "${rootDir}/framework/base/dtd"
I propose to load all dtd present on all active component as this works for config directory.
diff --git a/build.gradle b/build.gradle index 1bc148e636..4c256c74d8 100644 --- a/build.gradle +++ b/build.gradle @@ -292,7 +292,7 @@ sourceSets { resources { srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java') srcDirs += getDirectoryInActiveComponentsIfExists('config') - srcDirs += "${rootDir}/framework/base/dtd" + srcDirs += getDirectoryInActiveComponentsIfExists('dtd') exclude excludedJavaSources exclude excludedConfigFiles // Below are necessary for unit tests run by Gradle and integration tests
This solve any connection issue to resolve xsd on ofbiz.apache.org (because it use file present on the code base) and the OFBiz start failed linked.