Author: veithen
Date: Fri Jul 23 19:45:25 2010
New Revision: 967226
URL: http://svn.apache.org/viewvc?rev=967226&view=rev
Log:
Synchronized DOOM's SOAPEnvelopeImpl#addChild with that of LLOM in order to
solve WSCOMMONS-552. Also added some new test cases for SOAPEnvelope.
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml
(with props)
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml
(with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP11EnvelopeTestBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP12EnvelopeTestBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/UnifiedSOAPTestCase.java
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP11EnvelopeTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP11EnvelopeTestBase.java?rev=967226&r1=967225&r2=967226&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP11EnvelopeTestBase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP11EnvelopeTestBase.java
Fri Jul 23 19:45:25 2010
@@ -24,4 +24,13 @@ public class SOAP11EnvelopeTestBase exte
public SOAP11EnvelopeTestBase(OMMetaFactory omMetaFactory) {
super(omMetaFactory, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
}
+
+ /**
+ * Test that adding an arbitrary element to the envelope is allowed. SOAP
1.1 indeed allows for
+ * arbitrary elements to appear after the SOAP body.
+ */
+ public void testAddElementAfterBody() {
+ SOAPEnvelope env = soapFactory.getDefaultEnvelope();
+ env.addChild(soapFactory.createOMElement("test", "urn:test", "p"));
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP12EnvelopeTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP12EnvelopeTestBase.java?rev=967226&r1=967225&r2=967226&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP12EnvelopeTestBase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAP12EnvelopeTestBase.java
Fri Jul 23 19:45:25 2010
@@ -24,4 +24,17 @@ public class SOAP12EnvelopeTestBase exte
public SOAP12EnvelopeTestBase(OMMetaFactory omMetaFactory) {
super(omMetaFactory, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
}
+
+ /**
+ * Test that an attempt to add an arbitrary element to the SOAP envelope
triggers an exception.
+ */
+ public void testAddElementAfterBody() {
+ SOAPEnvelope env = soapFactory.getDefaultEnvelope();
+ try {
+ env.addChild(soapFactory.createOMElement("test", "urn:test", "p"));
+ fail("Expected SOAPProcessingException");
+ } catch (SOAPProcessingException ex) {
+ // Expected
+ }
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java?rev=967226&r1=967225&r2=967226&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/SOAPEnvelopeTestBase.java
Fri Jul 23 19:45:25 2010
@@ -93,4 +93,15 @@ public class SOAPEnvelopeTestBase extend
envelope.getHeader().discard();
envelope.getBody().toStringWithConsume();
}
+
+ /**
+ * Test the behavior when adding a header to an envelope that has not yet
been built completely.
+ * This is a regression test for WSCOMMONS-552.
+ */
+ public void testAddHeaderToIncompleteEnvelope() {
+ SOAPEnvelope envelope = getTestMessage(MESSAGE_WITHOUT_HEADER);
+ assertNull(envelope.getHeader());
+ SOAPHeader header = soapFactory.createSOAPHeader(envelope);
+ assertSame(header, envelope.getHeader());
+ }
}
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/UnifiedSOAPTestCase.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/UnifiedSOAPTestCase.java?rev=967226&r1=967225&r2=967226&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/UnifiedSOAPTestCase.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/java/org/apache/axiom/soap/UnifiedSOAPTestCase.java
Fri Jul 23 19:45:25 2010
@@ -28,6 +28,7 @@ import org.apache.axiom.soap.impl.builde
public class UnifiedSOAPTestCase extends AbstractTestCase {
protected static final String MESSAGE = "message.xml";
+ protected static final String MESSAGE_WITHOUT_HEADER =
"message_without_header.xml";
protected final OMMetaFactory omMetaFactory;
protected final String envelopeNamespaceURI;
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml?rev=967226&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml
Fri Jul 23 19:45:25 2010
@@ -0,0 +1,5 @@
+<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
+ <soapenv:Body>
+ <test/>
+ </soapenv:Body>
+</soapenv:Envelope>
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap11/message_without_header.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml?rev=967226&view=auto
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml
(added)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml
Fri Jul 23 19:45:25 2010
@@ -0,0 +1,5 @@
+<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
+ <soapenv:Body>
+ <test/>
+ </soapenv:Body>
+</soapenv:Envelope>
Propchange:
webservices/commons/trunk/modules/axiom/modules/axiom-api/src/test/resources/soap/soap12/message_without_header.xml
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java?rev=967226&r1=967225&r2=967226&view=diff
==============================================================================
---
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
(original)
+++
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
Fri Jul 23 19:45:25 2010
@@ -32,6 +32,7 @@ import org.apache.axiom.om.impl.util.OMS
import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAP11Version;
import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAP12Version;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPConstants;
import org.apache.axiom.soap.SOAPEnvelope;
@@ -113,11 +114,40 @@ public class SOAPEnvelopeImpl extends SO
}
public void addChild(OMNode child) {
- if (this.done && (child instanceof SOAPHeader)) {
- SOAPBody body = getBody();
- if (body != null) {
- body.insertSiblingBefore(child);
- return;
+ // SOAP 1.1 allows for arbitrary elements after SOAPBody so do NOT
check for
+ // node types when appending to SOAP 1.1 envelope.
+ if (getVersion() instanceof SOAP12Version) {
+ checkChild(child);
+ }
+
+ if (child instanceof SOAPHeader) {
+ // The SOAPHeader is added before the SOAPBody
+ // We must be sensitive to the state of the parser. It is
possible that the
+ // has not been processed yet.
+ if (this.done) {
+ // Parsing is complete, therefore it is safe to
+ // call getBody.
+ SOAPBody body = getBody();
+ if (body != null) {
+ body.insertSiblingBefore(child);
+ return;
+ }
+ } else {
+ // Flow to here indicates that we are still expanding the
+ // envelope. The body or body contents may not be
+ // parsed yet. We can't use getBody() yet...it will
+ // cause a failure. So instead, carefully find the
+ // body and insert the header. If the body is not found,
+ // this indicates that it has not been parsed yet...and
+ // the code will fall through to the super.addChild.
+ OMNode node = this.lastChild;
+ while (node != null) {
+ if (node instanceof SOAPBody) {
+ node.insertSiblingBefore(child);
+ return;
+ }
+ node = node.getPreviousOMSibling();
+ }
}
}
super.addChild(child);