You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by sc...@apache.org on 2009/06/17 18:43:23 UTC

svn commit: r785712 - /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java

Author: scheu
Date: Wed Jun 17 16:43:23 2009
New Revision: 785712

URL: http://svn.apache.org/viewvc?rev=785712&view=rev
Log:
Contributor: Rich Scheuerle
Summary:
Added some additional logic to tolerate missing DTD text if XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES
is specified.

Modified:
    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java

Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=785712&r1=785711&r2=785712&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Wed Jun 17 16:43:23 2009
@@ -35,6 +35,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 
+import javax.xml.stream.XMLInputFactory;
 import javax.xml.stream.XMLStreamConstants;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
@@ -498,9 +499,42 @@
         if (!parser.hasText()) {
             return null;
         }
-        lastNode = omfactory.createOMDocType(document, parser.getText());
+        String dtdText = getDTDText();
+        lastNode = omfactory.createOMDocType(document, dtdText);
         return lastNode;
     }
+    
+    /**
+     * The getText() method for a DOCTYPE returns the 
+     * subset of the DOCTYPE (not the direct infoset).
+     * This may force the parser to get information from 
+     * the network.
+     * @return doctype subset
+     * @throws OMException
+     */
+    private String getDTDText() throws OMException { 
+        String text = null;
+        try {
+            text = parser.getText();
+        } catch (RuntimeException e) {
+            // Woodstox (and perhaps other parsers)
+            // attempts to load the external subset even if
+            // external enties is false.  So ignore this error
+            // if external entity support is explicitly disabled.
+            Boolean b = (Boolean) parser.getProperty(
+                   XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
+            if (b == null || b == Boolean.TRUE) {
+                throw e;
+            }
+            if (log.isDebugEnabled()) {
+                log.debug("An exception occurred while calling getText() for a DOCTYPE.  " +
+                                "The exception is ignored because external " +
+                                "entites support is disabled.  " +
+                                "The ignored exception is " + e);
+            }
+        }
+        return text;
+    }
 
     /**
      * Method createPI.



Re: svn commit: r785712 - /webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java

Posted by Andreas Veithen <an...@gmail.com>.
Rich,

Silently ignoring exceptions from the underlying parser may have
drastic consequences as shown in WSCOMMONS-372. Are you sure that we
will not run into that issue? Also, why is this still necessary if we
have StAXutils#createNetworkDetachedXMLStreamReader?

Andreas

On Wed, Jun 17, 2009 at 18:43, <sc...@apache.org> wrote:
> Author: scheu
> Date: Wed Jun 17 16:43:23 2009
> New Revision: 785712
>
> URL: http://svn.apache.org/viewvc?rev=785712&view=rev
> Log:
> Contributor: Rich Scheuerle
> Summary:
> Added some additional logic to tolerate missing DTD text if XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES
> is specified.
>
> Modified:
>    webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
>
> Modified: webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java
> URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java?rev=785712&r1=785711&r2=785712&view=diff
> ==============================================================================
> --- webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java (original)
> +++ webservices/commons/trunk/modules/axiom/modules/axiom-api/src/main/java/org/apache/axiom/om/impl/builder/StAXOMBuilder.java Wed Jun 17 16:43:23 2009
> @@ -35,6 +35,7 @@
>  import org.apache.commons.logging.Log;
>  import org.apache.commons.logging.LogFactory;
>
> +import javax.xml.stream.XMLInputFactory;
>  import javax.xml.stream.XMLStreamConstants;
>  import javax.xml.stream.XMLStreamException;
>  import javax.xml.stream.XMLStreamReader;
> @@ -498,9 +499,42 @@
>         if (!parser.hasText()) {
>             return null;
>         }
> -        lastNode = omfactory.createOMDocType(document, parser.getText());
> +        String dtdText = getDTDText();
> +        lastNode = omfactory.createOMDocType(document, dtdText);
>         return lastNode;
>     }
> +
> +    /**
> +     * The getText() method for a DOCTYPE returns the
> +     * subset of the DOCTYPE (not the direct infoset).
> +     * This may force the parser to get information from
> +     * the network.
> +     * @return doctype subset
> +     * @throws OMException
> +     */
> +    private String getDTDText() throws OMException {
> +        String text = null;
> +        try {
> +            text = parser.getText();
> +        } catch (RuntimeException e) {
> +            // Woodstox (and perhaps other parsers)
> +            // attempts to load the external subset even if
> +            // external enties is false.  So ignore this error
> +            // if external entity support is explicitly disabled.
> +            Boolean b = (Boolean) parser.getProperty(
> +                   XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES);
> +            if (b == null || b == Boolean.TRUE) {
> +                throw e;
> +            }
> +            if (log.isDebugEnabled()) {
> +                log.debug("An exception occurred while calling getText() for a DOCTYPE.  " +
> +                                "The exception is ignored because external " +
> +                                "entites support is disabled.  " +
> +                                "The ignored exception is " + e);
> +            }
> +        }
> +        return text;
> +    }
>
>     /**
>      * Method createPI.
>
>
>