You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ofbiz.apache.org by "Nicolas Malin (Jira)" <ji...@apache.org> on 2021/12/07 20:59:00 UTC

[jira] [Created] (OFBIZ-12437) Resolve local xsd on UtilXml class

Nicolas Malin created OFBIZ-12437:
-------------------------------------

             Summary: Resolve local xsd on UtilXml class
                 Key: OFBIZ-12437
                 URL: https://issues.apache.org/jira/browse/OFBIZ-12437
             Project: OFBiz
          Issue Type: Bug
          Components: framework/base
    Affects Versions: 18.12.02, 17.12.08, Trunk
            Reporter: Nicolas Malin
            Assignee: Nicolas Malin


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 :
{code:java}
    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);{code}
The validating function call a local resolver that try to resolve through UtilURL.java the xsd file extrat form the schema location, with :
{code:java}
schemaLocation="http://ofbiz.apache.org/Widget-Theme http://ofbiz.apache.org/dtds/widget-theme.xsd"{code}
ofbiz try to resolve :
{code:java}
 widget-theme.xsd{code}
However, this resolution failed, the code present on UtilURL.java:82
{code:java}
     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);
            }
        } [...]{code}
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 :
{code:java}
 resources {
             srcDirs = getDirectoryInActiveComponentsIfExists('src/main/java')
             srcDirs += getDirectoryInActiveComponentsIfExists('config')
            srcDirs += "${rootDir}/framework/base/dtd"

{code}
I propose to load all dtd present on all active component as this works for config directory.
{code:java}
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

{code}
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.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)