Skip to content

Commit 0dd60b4

Browse files
committed
SWS-763 - Namespace problems after upgrading to Axiom 1.2.13
1 parent 93de7a8 commit 0dd60b4

File tree

5 files changed

+70
-22
lines changed

5 files changed

+70
-22
lines changed

core/src/main/java/org/springframework/ws/soap/axiom/AxiomHandler.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -45,7 +45,6 @@
4545
* @author Arjen Poutsma
4646
* @since 1.0.0
4747
*/
48-
@SuppressWarnings("Since15")
4948
class AxiomHandler implements ContentHandler, LexicalHandler {
5049

5150
private final OMFactory factory;
@@ -67,7 +66,7 @@ class AxiomHandler implements ContentHandler, LexicalHandler {
6766

6867
private OMContainer getParent() {
6968
if (!elements.isEmpty()) {
70-
return (OMContainer) elements.get(elements.size() - 1);
69+
return elements.get(elements.size() - 1);
7170
}
7271
else {
7372
return container;
@@ -84,7 +83,8 @@ public void endPrefixMapping(String prefix) throws SAXException {
8483

8584
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
8685
OMContainer parent = getParent();
87-
OMElement element = factory.createOMElement(localName, null, parent);
86+
OMNamespace ns = factory.createOMNamespace(uri, QNameUtils.toQName(uri, qName).getPrefix());
87+
OMElement element = factory.createOMElement(localName, ns, parent);
8888
for (Map.Entry<String, String> entry : namespaces.entrySet()) {
8989
String prefix = entry.getKey();
9090
if (prefix.length() == 0) {
@@ -94,9 +94,6 @@ public void startElement(String uri, String localName, String qName, Attributes
9494
element.declareNamespace((String) entry.getValue(), prefix);
9595
}
9696
}
97-
QName qname = QNameUtils.toQName(uri, qName);
98-
element.setLocalName(qname.getLocalPart());
99-
element.setNamespace(element.findNamespace(qname.getNamespaceURI(), qname.getPrefix()));
10097
for (int i = 0; i < atts.getLength(); i++) {
10198
QName attrName = QNameUtils.toQName(atts.getURI(i), atts.getQName(i));
10299
String value = atts.getValue(i);

core/src/main/java/org/springframework/ws/soap/axiom/AxiomSoapMessage.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -59,7 +59,6 @@
5959
* @see SOAPMessage
6060
* @since 1.0.0
6161
*/
62-
@SuppressWarnings("Since15")
6362
public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWebServiceMessage {
6463

6564
private static final String EMPTY_SOAP_ACTION = "\"\"";
@@ -97,7 +96,8 @@ public AxiomSoapMessage(SOAPFactory soapFactory) {
9796
public AxiomSoapMessage(SOAPFactory soapFactory, boolean payloadCaching, boolean langAttributeOnSoap11FaultString) {
9897
SOAPEnvelope soapEnvelope = soapFactory.getDefaultEnvelope();
9998
axiomFactory = soapFactory;
100-
axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope, soapEnvelope.getBuilder());
99+
axiomMessage = axiomFactory.createSOAPMessage(soapEnvelope.getBuilder());
100+
axiomMessage.setSOAPEnvelope(soapEnvelope);
101101
attachments = new Attachments();
102102
this.payloadCaching = payloadCaching;
103103
this.langAttributeOnSoap11FaultString = langAttributeOnSoap11FaultString;
@@ -218,6 +218,9 @@ public boolean isXopPackage() {
218218
try {
219219
return MTOMConstants.MTOM_TYPE.equals(attachments.getAttachmentSpecType());
220220
}
221+
catch (OMException ex) {
222+
return false;
223+
}
221224
catch (NullPointerException ex) {
222225
// gotta love Axis2
223226
return false;

core/src/main/java/org/springframework/ws/soap/axiom/support/AxiomUtils.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -34,7 +34,6 @@
3434
import org.apache.axiom.om.OMElement;
3535
import org.apache.axiom.om.OMException;
3636
import org.apache.axiom.om.OMNamespace;
37-
import org.apache.axiom.om.OMNode;
3837
import org.apache.axiom.soap.SOAPEnvelope;
3938
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
4039
import org.w3c.dom.DOMImplementation;
@@ -105,8 +104,8 @@ public static Locale toLocale(String language) {
105104
/** Removes the contents (i.e. children) of the container. */
106105
public static void removeContents(OMContainer container) {
107106
for (Iterator<?> iterator = container.getChildren(); iterator.hasNext();) {
108-
OMNode child = (OMNode) iterator.next();
109-
child.detach();
107+
iterator.next();
108+
iterator.remove();
110109
}
111110
}
112111

core/src/test/java/org/springframework/ws/soap/axiom/AxiomHandlerTest.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
/*
2-
* Copyright 2005-2010 the original author or authors.
2+
* Copyright 2005-2012 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
77
*
8-
* http://www.apache.org/licenses/LICENSE-2.0
8+
* http://www.apache.org/licenses/LICENSE-2.0
99
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
@@ -18,6 +18,7 @@
1818

1919
import java.io.ByteArrayOutputStream;
2020
import java.io.StringReader;
21+
import java.util.Iterator;
2122

2223
import org.apache.axiom.om.OMAbstractFactory;
2324
import org.apache.axiom.om.OMDocument;
@@ -31,6 +32,8 @@
3132
import org.xml.sax.helpers.XMLReaderFactory;
3233

3334
import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
35+
import static org.junit.Assert.assertEquals;
36+
import static org.junit.Assert.assertTrue;
3437

3538
public class AxiomHandlerTest {
3639

@@ -49,6 +52,10 @@ public class AxiomHandlerTest {
4952
private static final String XML_3_ENTITY =
5053
"<predefined-entity-reference>&lt;&gt;&amp;&quot;&apos;</predefined-entity-reference>";
5154

55+
private static final String XML_4_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace1' />";
56+
57+
private static final String XML_5_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>" + "<x:child xmlns:x='namespace1' />";
58+
5259
private AxiomHandler handler;
5360

5461
private OMDocument result;
@@ -98,6 +105,48 @@ public void testContentHandlerElement() throws Exception {
98105
result.serialize(bos);
99106
assertXMLEqual("Invalid result", XML_2_EXPECTED, bos.toString("UTF-8"));
100107
}
108+
109+
@Test
110+
public void testContentHandlerElementWithSamePrefixAndDifferentNamespace() throws Exception {
111+
OMNamespace namespace = factory.createOMNamespace("namespace1", "");
112+
OMElement rootElement = factory.createOMElement("root", namespace, result);
113+
handler = new AxiomHandler(rootElement, factory);
114+
xmlReader.setContentHandler(handler);
115+
xmlReader.parse(new InputSource(new StringReader(XML_2_SNIPPET)));
116+
Iterator<?> it = result.getOMDocumentElement().getChildrenWithLocalName("child");
117+
assertTrue(it.hasNext());
118+
OMElement child = (OMElement) it.next();
119+
assertEquals("", child.getQName().getPrefix());
120+
assertEquals("namespace2", child.getQName().getNamespaceURI());
121+
}
122+
123+
@Test
124+
public void testContentHandlerElementWithSameNamespacesAndPrefix() throws Exception {
125+
OMNamespace namespace = factory.createOMNamespace("namespace1", "");
126+
OMElement rootElement = factory.createOMElement("root", namespace, result);
127+
handler = new AxiomHandler(rootElement, factory);
128+
xmlReader.setContentHandler(handler);
129+
xmlReader.parse(new InputSource(new StringReader(XML_4_SNIPPET)));
130+
Iterator<?> it = result.getOMDocumentElement().getChildrenWithLocalName("child");
131+
assertTrue(it.hasNext());
132+
OMElement child = (OMElement) it.next();
133+
assertEquals("", child.getQName().getPrefix());
134+
assertEquals("namespace1", child.getQName().getNamespaceURI());
135+
}
136+
137+
@Test
138+
public void testContentHandlerElementWithSameNamespacesAndDifferentPrefix() throws Exception {
139+
OMNamespace namespace = factory.createOMNamespace("namespace1", "");
140+
OMElement rootElement = factory.createOMElement("root", namespace, result);
141+
handler = new AxiomHandler(rootElement, factory);
142+
xmlReader.setContentHandler(handler);
143+
xmlReader.parse(new InputSource(new StringReader(XML_5_SNIPPET)));
144+
Iterator<?> it = result.getOMDocumentElement().getChildrenWithLocalName("child");
145+
assertTrue(it.hasNext());
146+
OMElement child = (OMElement) it.next();
147+
assertEquals("x", child.getQName().getPrefix());
148+
assertEquals("namespace1", child.getQName().getNamespaceURI());
149+
}
101150

102151
@Test
103152
public void testContentHandlerPredefinedEntityReference() throws Exception {
@@ -109,4 +158,4 @@ public void testContentHandlerPredefinedEntityReference() throws Exception {
109158
result.serialize(bos);
110159
assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8"));
111160
}
112-
}
161+
}

parent/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,7 @@
464464
<dependency>
465465
<groupId>org.apache.ws.commons.axiom</groupId>
466466
<artifactId>axiom-api</artifactId>
467-
<version>1.2.9</version>
467+
<version>1.2.13</version>
468468
<exclusions>
469469
<exclusion>
470470
<groupId>org.apache.geronimo.specs</groupId>
@@ -487,7 +487,7 @@
487487
<dependency>
488488
<groupId>org.apache.ws.commons.axiom</groupId>
489489
<artifactId>axiom-impl</artifactId>
490-
<version>1.2.9</version>
490+
<version>1.2.13</version>
491491
<exclusions>
492492
<exclusion>
493493
<groupId>org.apache.geronimo.specs</groupId>

0 commit comments

Comments
 (0)