You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ws.apache.org by ve...@apache.org on 2016/02/13 20:39:02 UTC

svn commit: r1730261 - in /webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom: locator/ImplementationFactory.java om/OMAbstractFactory.java

Author: veithen
Date: Sat Feb 13 19:39:02 2016
New Revision: 1730261

URL: http://svn.apache.org/viewvc?rev=1730261&view=rev
Log:
Improve the OMMetaFactory locator code.

Modified:
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java
    webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java?rev=1730261&r1=1730260&r2=1730261&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/locator/ImplementationFactory.java Sat Feb 13 19:39:02 2016
@@ -19,6 +19,7 @@
 package org.apache.axiom.locator;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.List;
@@ -82,28 +83,35 @@ final class ImplementationFactory {
             // Since this code is used to discover Axiom implementations, we have to use DOM here.
             DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
             dbf.setNamespaceAware(true);
-            Element root = dbf.newDocumentBuilder().parse(url.toString()).getDocumentElement();
-            QName rootQName = getQName(root);
-            if (rootQName.equals(QNAME_IMPLEMENTATIONS)) {
-                Node child = root.getFirstChild();
-                while (child != null) {
-                    if (child instanceof Element) {
-                        QName childQName = getQName(child);
-                        if (childQName.equals(QNAME_IMPLEMENTATION)) {
-                            Implementation implementation = parseImplementation(loader, (Element)child);
-                            if (implementation != null) {
-                                implementations.add(implementation);
+            // Use URL#openStream() (instead of converting the URL to a String and passing it to the
+            // parser) to avoid situations where the parser can't reconstruct/interpret the URL.
+            InputStream in = url.openStream();
+            try {
+                Element root = dbf.newDocumentBuilder().parse(in).getDocumentElement();
+                QName rootQName = getQName(root);
+                if (rootQName.equals(QNAME_IMPLEMENTATIONS)) {
+                    Node child = root.getFirstChild();
+                    while (child != null) {
+                        if (child instanceof Element) {
+                            QName childQName = getQName(child);
+                            if (childQName.equals(QNAME_IMPLEMENTATION)) {
+                                Implementation implementation = parseImplementation(loader, (Element)child);
+                                if (implementation != null) {
+                                    implementations.add(implementation);
+                                }
+                            } else {
+                                log.warn("Skipping unexpected element " + childQName + "; only "
+                                        + QNAME_IMPLEMENTATION + " is expected");
                             }
-                        } else {
-                            log.warn("Skipping unexpected element " + childQName + "; only "
-                                    + QNAME_IMPLEMENTATION + " is expected");
                         }
+                        child = child.getNextSibling();
                     }
-                    child = child.getNextSibling();
+                } else {
+                    log.error(url + " is not a valid implementation descriptor: unexpected root element "
+                            + rootQName + "; expected " + QNAME_IMPLEMENTATIONS);
                 }
-            } else {
-                log.error(url + " is not a valid implementation descriptor: unexpected root element "
-                        + rootQName + "; expected " + QNAME_IMPLEMENTATIONS);
+            } finally {
+                in.close();
             }
         } catch (ParserConfigurationException ex) {
             // If we get here, something went badly wrong

Modified: webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java?rev=1730261&r1=1730260&r2=1730261&view=diff
==============================================================================
--- webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java (original)
+++ webservices/axiom/trunk/axiom-api/src/main/java/org/apache/axiom/om/OMAbstractFactory.java Sat Feb 13 19:39:02 2016
@@ -174,7 +174,8 @@ public class OMAbstractFactory {
             StringBuilder buffer = new StringBuilder();
             buffer.append("No meta factory found for feature '").append(feature).append("'");
             if (jarHint != null) {
-                buffer.append("; this usually means that ").append(jarHint).append(" is not in the classpath");
+                buffer.append("; this usually means that ").append(jarHint)
+                      .append(" is not in the classpath or that the META-INF/axiom.xml resource can't be read");
             }
             throw new OMException(buffer.toString());
         } else {