From b8e4b806fa402f863d852c137f8e1b1826609f93 Mon Sep 17 00:00:00 2001 From: Tommy Winther Date: Mon, 20 Apr 2015 12:09:25 -0500 Subject: [PATCH] Fix bug in AxiomHandler --- .../ws/soap/axiom/AxiomHandler.java | 2 ++ .../ws/soap/axiom/AxiomHandlerTest.java | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java index aa7b247d..47b30ac7 100644 --- a/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java +++ b/spring-ws-core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java @@ -43,6 +43,7 @@ import org.springframework.xml.namespace.QNameUtils; * AXIOM OMElement to a specified parent element when {@code endDocument} is called. * Used for returing {@code SAXResult}s from Axiom elements. * @author Arjen Poutsma + * @author Tommy Winther * @since 1.0.0 */ class AxiomHandler implements ContentHandler, LexicalHandler { @@ -92,6 +93,7 @@ class AxiomHandler implements ContentHandler, LexicalHandler { @Override public void endPrefixMapping(String prefix) throws SAXException { + currentNamespaceMapping().remove(prefix); } @Override diff --git a/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java b/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java index 6612eade..96c0c7a8 100644 --- a/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java +++ b/spring-ws-core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java @@ -16,6 +16,11 @@ package org.springframework.ws.soap.axiom; +import static org.custommonkey.xmlunit.XMLAssert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.StringReader; @@ -34,9 +39,6 @@ import org.apache.axiom.om.OMDocument; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMFactory; import org.apache.axiom.om.OMNamespace; -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; import org.junit.Before; import org.junit.Test; import org.w3c.dom.Document; @@ -65,6 +67,8 @@ public class AxiomHandlerTest { private static final String XML_5_SNIPPET = "" + ""; + private static final String XML_6_SNIPPET = "" + ""; + private AxiomHandler handler; private OMDocument result; @@ -157,6 +161,32 @@ public class AxiomHandlerTest { assertEquals("namespace1", child.getQName().getNamespaceURI()); } + @Test + public void testContentHandlerSiblingPrefixMapping() throws Exception { + handler = new AxiomHandler(result, factory); + xmlReader.setContentHandler(handler); + xmlReader.parse(new InputSource(new StringReader(XML_6_SNIPPET))); + + Iterator it = result.getOMDocumentElement().getChildren(); + assertTrue(it.hasNext()); + OMElement firstSibling = (OMElement) it.next(); + assertEquals("first-sibling", firstSibling.getLocalName()); + Iterator firstSiblingNsIt = firstSibling.getAllDeclaredNamespaces(); + // Verify first sibling has a single namespace declaration (with child-namespace URI) + assertTrue(firstSiblingNsIt.hasNext()); + assertEquals("child-namespace", ((OMNamespace) firstSiblingNsIt.next()).getNamespaceURI()); + assertFalse(firstSiblingNsIt.hasNext()); + + assertTrue(it.hasNext()); + OMElement secondSibling = (OMElement) it.next(); + // Verify second sibling has no namespace declarations as it's covered by + // This also verifies the child-namespace from the element isn't copied to second-sibling + assertEquals("second-sibling", secondSibling.getLocalName()); + Iterator secondSiblingNsIt = secondSibling.getAllDeclaredNamespaces(); + assertFalse(secondSiblingNsIt.hasNext()); + + } + @Test public void testContentHandlerPredefinedEntityReference() throws Exception { handler = new AxiomHandler(result, factory);