SWS-763 - Namespace problems after upgrading to Axiom 1.2.13
This commit is contained in:
@@ -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<String, String> 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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 =
|
||||
"<predefined-entity-reference><>&"'</predefined-entity-reference>";
|
||||
|
||||
private static final String XML_4_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>" + "<child xmlns='namespace1' />";
|
||||
|
||||
private static final String XML_5_SNIPPET = "<?xml version='1.0' encoding='UTF-8'?>" + "<x:child xmlns:x='namespace1' />";
|
||||
|
||||
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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +464,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>axiom-api</artifactId>
|
||||
<version>1.2.9</version>
|
||||
<version>1.2.13</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
@@ -487,7 +487,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.ws.commons.axiom</groupId>
|
||||
<artifactId>axiom-impl</artifactId>
|
||||
<version>1.2.9</version>
|
||||
<version>1.2.13</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.apache.geronimo.specs</groupId>
|
||||
|
||||
Reference in New Issue
Block a user