diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java index 4cb34ffe..f742a2fd 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2012 the original author or authors. * * Licensed 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 + * 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, @@ -45,7 +45,6 @@ import org.xml.sax.ext.LexicalHandler; * @author Arjen Poutsma * @since 1.0.0 */ -@SuppressWarnings("Since15") class AxiomHandler implements ContentHandler, LexicalHandler { private final OMFactory factory; @@ -67,7 +66,7 @@ class AxiomHandler implements ContentHandler, LexicalHandler { private OMContainer getParent() { if (!elements.isEmpty()) { - return (OMContainer) elements.get(elements.size() - 1); + return elements.get(elements.size() - 1); } else { return container; @@ -84,7 +83,8 @@ class AxiomHandler implements ContentHandler, LexicalHandler { public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException { OMContainer parent = getParent(); - OMElement element = factory.createOMElement(localName, null, parent); + OMNamespace ns = factory.createOMNamespace(uri, QNameUtils.toQName(uri, qName).getPrefix()); + OMElement element = factory.createOMElement(localName, ns, parent); for (Map.Entry entry : namespaces.entrySet()) { String prefix = entry.getKey(); if (prefix.length() == 0) { @@ -94,9 +94,6 @@ class AxiomHandler implements ContentHandler, LexicalHandler { element.declareNamespace((String) entry.getValue(), prefix); } } - QName qname = QNameUtils.toQName(uri, qName); - element.setLocalName(qname.getLocalPart()); - element.setNamespace(element.findNamespace(qname.getNamespaceURI(), qname.getPrefix())); for (int i = 0; i < atts.getLength(); i++) { QName attrName = QNameUtils.toQName(atts.getURI(i), atts.getQName(i)); String value = atts.getValue(i); diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java index f00224ad..e5b0301d 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2012 the original author or authors. * * Licensed 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 + * 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, @@ -59,7 +59,6 @@ import org.w3c.dom.Document; * @see SOAPMessage * @since 1.0.0 */ -@SuppressWarnings("Since15") public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWebServiceMessage { private static final String EMPTY_SOAP_ACTION = "\"\""; @@ -97,7 +96,8 @@ public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWe public AxiomSoapMessage(SOAPFactory soapFactory, boolean payloadCaching, boolean langAttributeOnSoap11FaultString) { SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope(); axiomFactory = soapFactory; - axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope, soapEnvelope.getBuilder()); + axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope.getBuilder()); + axiomMessage.setSOAPEnvelope(soapEnvelope); attachments = new Attachments(); this.payloadCaching = payloadCaching; this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString; @@ -218,6 +218,9 @@ public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWe try { return MTOMConstants.MTOM_TYPE.equals(attachments.getAttachmentSpecType()); } + catch (OMException ex) { + return false; + } catch (NullPointerException ex) { // gotta love Axis2 return false; diff --git a/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java b/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java index 033a3ee8..3e61980e 100644 --- a/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java +++ b/core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2012 the original author or authors. * * Licensed 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 + * 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, @@ -34,7 +34,6 @@ import org.apache.axiom.om.OMContainer; import org.apache.axiom.om.OMElement; import org.apache.axiom.om.OMException; import org.apache.axiom.om.OMNamespace; -import org.apache.axiom.om.OMNode; import org.apache.axiom.soap.SOAPEnvelope; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import org.w3c.dom.DOMImplementation; @@ -105,8 +104,8 @@ public abstract class AxiomUtils { /** Removes the contents (i.e. children) of the container. */ public static void removeContents(OMContainer container) { for (Iterator iterator = container.getChildren(); iterator.hasNext();) { - OMNode child = (OMNode) iterator.next(); - child.detach(); + iterator.next(); + iterator.remove(); } } diff --git a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java index c38cd94f..b50f3099 100644 --- a/core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java +++ b/core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java @@ -1,11 +1,11 @@ /* - * Copyright 2005-2010 the original author or authors. + * Copyright 2005-2012 the original author or authors. * * Licensed 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 + * 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, @@ -18,6 +18,7 @@ package org.springframework.ws.soap.axiom; import java.io.ByteArrayOutputStream; import java.io.StringReader; +import java.util.Iterator; import org.apache.axiom.om.OMAbstractFactory; import org.apache.axiom.om.OMDocument; @@ -31,6 +32,8 @@ import org.xml.sax.XMLReader; import org.xml.sax.helpers.XMLReaderFactory; import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public class AxiomHandlerTest { @@ -49,6 +52,10 @@ public class AxiomHandlerTest { private static final String XML_3_ENTITY = "<>&"'"; + private static final String XML_4_SNIPPET = "" + ""; + + private static final String XML_5_SNIPPET = "" + ""; + private AxiomHandler handler; private OMDocument result; @@ -98,6 +105,48 @@ public class AxiomHandlerTest { result.serialize(bos); assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8")); } + + @Test + public void testContentHandlerElementWithSamePrefixAndDifferentNamespace() throws Exception { + OMNamespace namespace = factory.createOMNamespace("namespace1", ""); + OMElement rootElement = factory.createOMElement("root", namespace, result); + handler = new AxiomHandler(rootElement, factory); + xmlReader.setContentHandler(handler); + xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET))); + Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); + assertTrue(it.hasNext()); + OMElement child = (OMElement) it.next(); + assertEquals("", child.getQName().getPrefix()); + assertEquals("namespace2", child.getQName().getNamespaceURI()); + } + + @Test + public void testContentHandlerElementWithSameNamespacesAndPrefix() throws Exception { + OMNamespace namespace = factory.createOMNamespace("namespace1", ""); + OMElement rootElement = factory.createOMElement("root", namespace, result); + handler = new AxiomHandler(rootElement, factory); + xmlReader.setContentHandler(handler); + xmlReader.parse(new InputSource(new StringReader(XML_4_SNIPPET))); + Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); + assertTrue(it.hasNext()); + OMElement child = (OMElement) it.next(); + assertEquals("", child.getQName().getPrefix()); + assertEquals("namespace1", child.getQName().getNamespaceURI()); + } + + @Test + public void testContentHandlerElementWithSameNamespacesAndDifferentPrefix() throws Exception { + OMNamespace namespace = factory.createOMNamespace("namespace1", ""); + OMElement rootElement = factory.createOMElement("root", namespace, result); + handler = new AxiomHandler(rootElement, factory); + xmlReader.setContentHandler(handler); + xmlReader.parse(new InputSource(new StringReader(XML_5_SNIPPET))); + Iterator it = result.getOMDocumentElement().getChildrenWithLocalName("child"); + assertTrue(it.hasNext()); + OMElement child = (OMElement) it.next(); + assertEquals("x", child.getQName().getPrefix()); + assertEquals("namespace1", child.getQName().getNamespaceURI()); + } @Test public void testContentHandlerPredefinedEntityReference() throws Exception { @@ -109,4 +158,4 @@ public class AxiomHandlerTest { result.serialize(bos); assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8")); } -} \ No newline at end of file +} diff --git a/parent/pom.xml b/parent/pom.xml index 18d7e0e4..d433d084 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -464,7 +464,7 @@ org.apache.ws.commons.axiom axiom-api - 1.2.9 + 1.2.13 org.apache.geronimo.specs @@ -487,7 +487,7 @@ org.apache.ws.commons.axiom axiom-impl - 1.2.9 + 1.2.13 org.apache.geronimo.specs