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 2017/12/20 21:00:32 UTC

svn commit: r1818855 - in /webservices/axiom/trunk: aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/ components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/ testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/...

Author: veithen
Date: Wed Dec 20 21:00:31 2017
New Revision: 1818855

URL: http://svn.apache.org/viewvc?rev=1818855&view=rev
Log:
Ensure that exceptions thrown by an OMDataSource are correctly propagated by the SAXSource returned by getSAXSource.

Added:
    webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java   (with props)
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java   (with props)
Modified:
    webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/XMLReaderImpl.java
    webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java

Modified: webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/XMLReaderImpl.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/XMLReaderImpl.java?rev=1818855&r1=1818854&r2=1818855&view=diff
==============================================================================
--- webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/XMLReaderImpl.java (original)
+++ webservices/axiom/trunk/aspects/om-aspects/src/main/java/org/apache/axiom/om/impl/stream/sax/XMLReaderImpl.java Wed Dec 20 21:00:31 2017
@@ -61,7 +61,14 @@ public class XMLReaderImpl extends Abstr
         } catch (CoreModelException ex) {
             throw new SAXException(ex);
         } catch (StreamException ex) {
-            throw (SAXException)ex.getCause();
+            Throwable cause = ex.getCause();
+            if (cause instanceof SAXException) {
+                throw (SAXException)cause;
+            } else if (cause instanceof Exception){
+                throw new SAXException((Exception)cause);
+            } else {
+                throw new SAXException(ex);
+            }
         }
     }
 }

Added: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java?rev=1818855&view=auto
==============================================================================
--- webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java (added)
+++ webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java Wed Dec 20 21:00:31 2017
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.core.stream.sax;
+
+import org.apache.axiom.core.stream.NullXmlHandler;
+import org.xml.sax.ContentHandler;
+
+public final class SAX {
+    private SAX() {}
+
+    public static ContentHandler createNullContentHandler() {
+        return new XmlHandlerContentHandler(NullXmlHandler.INSTANCE, false);
+    }
+}

Propchange: webservices/axiom/trunk/components/core-streams/src/main/java/org/apache/axiom/core/stream/sax/SAX.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java?rev=1818855&r1=1818854&r2=1818855&view=diff
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java (original)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/OMTestSuiteBuilder.java Wed Dec 20 21:00:31 2017
@@ -582,6 +582,7 @@ public class OMTestSuiteBuilder extends
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetSAXSourceWithPushOMDataSource(metaFactory, scenario, false));
             addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetSAXSourceWithPushOMDataSource(metaFactory, scenario, true));
         }
+        addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetSAXSourceWithPushOMDataSourceThrowingException(metaFactory));
         addTest(new org.apache.axiom.ts.om.sourcedelement.TestGetTextAsStreamWithNonDestructiveOMDataSource(metaFactory));
         addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1DefaultPrefix(metaFactory));
         addTest(new org.apache.axiom.ts.om.sourcedelement.TestName1QualifiedPrefix(metaFactory));

Added: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java
URL: http://svn.apache.org/viewvc/webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java?rev=1818855&view=auto
==============================================================================
--- webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java (added)
+++ webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java Wed Dec 20 21:00:31 2017
@@ -0,0 +1,66 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.axiom.ts.om.sourcedelement;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.sax.SAXSource;
+
+import org.apache.axiom.core.stream.sax.SAX;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.om.ds.AbstractPushOMDataSource;
+import org.apache.axiom.ts.AxiomTestCase;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+
+public class TestGetSAXSourceWithPushOMDataSourceThrowingException extends AxiomTestCase {
+    public TestGetSAXSourceWithPushOMDataSourceThrowingException(OMMetaFactory metaFactory) {
+        super(metaFactory);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        OMElement element = metaFactory.getOMFactory().createOMElement(new AbstractPushOMDataSource() {
+            
+            @Override
+            public void serialize(XMLStreamWriter xmlWriter) throws XMLStreamException {
+                throw new XMLStreamException("TEST");
+            }
+            
+            @Override
+            public boolean isDestructiveWrite() {
+                return false;
+            }
+        });
+        SAXSource saxSource = element.getSAXSource(true);
+        XMLReader reader = saxSource.getXMLReader();
+        reader.setContentHandler(SAX.createNullContentHandler());
+        try {
+            reader.parse(saxSource.getInputSource());
+            fail("Expected SAXException");
+        } catch (SAXException ex) {
+            Throwable cause = ex.getCause();
+            assertThat(cause).isInstanceOf(XMLStreamException.class);
+            assertThat(cause.getMessage()).isEqualTo("TEST");
+        }
+    }
+}

Propchange: webservices/axiom/trunk/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/om/sourcedelement/TestGetSAXSourceWithPushOMDataSourceThrowingException.java
------------------------------------------------------------------------------
    svn:eol-style = native