Skip to content

Commit

Permalink
SWS-763 - Namespace problems after upgrading to Axiom 1.2.13
Browse files Browse the repository at this point in the history
  • Loading branch information
poutsma committed May 1, 2012
1 parent 93de7a8 commit 0dd60b4
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -45,7 +45,6 @@
* @author Arjen Poutsma
* @since 1.0.0
*/
@SuppressWarnings("Since15")
class AxiomHandler implements ContentHandler, LexicalHandler {

private final OMFactory factory;
Expand All @@ -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;
Expand All @@ -84,7 +83,8 @@ public void endPrefixMapping(String prefix) throws SAXException {

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) {
Expand All @@ -94,9 +94,6 @@ public void startElement(String uri, String localName, String qName, Attributes
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -59,7 +59,6 @@
* @see SOAPMessage
* @since 1.0.0
*/
@SuppressWarnings("Since15")
public class AxiomSoapMessage extends AbstractSoapMessage implements StreamingWebServiceMessage {

private static final String EMPTY_SOAP_ACTION = "\"\"";
Expand Down Expand Up @@ -97,7 +96,8 @@ public AxiomSoapMessage(SOAPFactory soapFactory) {
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;
Expand Down Expand Up @@ -218,6 +218,9 @@ public boolean isXopPackage() {
try {
return MTOMConstants.MTOM_TYPE.equals(attachments.getAttachmentSpecType());
}
catch (OMException ex) {
return false;
}
catch (NullPointerException ex) {
// gotta love Axis2
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -34,7 +34,6 @@
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;
Expand Down Expand Up @@ -105,8 +104,8 @@ public static Locale toLocale(String language) {
/** 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();
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -18,6 +18,7 @@

import java.io.ByteArrayOutputStream;
import java.io.StringReader;
import java.util.Iterator;

import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMDocument;
Expand All @@ -31,6 +32,8 @@
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 {

Expand All @@ -49,6 +52,10 @@ public class AxiomHandlerTest {
private static final String XML_3_ENTITY =
"<predefined-entity-reference>&lt;&gt;&amp;&quot;&apos;</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;
Expand Down Expand Up @@ -98,6 +105,48 @@ public void testContentHandlerElement() throws Exception {
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 {
Expand All @@ -109,4 +158,4 @@ public void testContentHandlerPredefinedEntityReference() throws Exception {
result.serialize(bos);
assertXMLEqual("Invalid result", XML_3_ENTITY, bos.toString("UTF-8"));
}
}
}
4 changes: 2 additions & 2 deletions parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down

0 comments on commit 0dd60b4

Please sign in to comment.