You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ga...@apache.org on 2009/01/06 17:10:51 UTC
svn commit: r731983 - in /webservices/commons/trunk/modules/axiom/modules:
axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/
axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/
axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/ axiom-imp...
Author: gawor
Date: Tue Jan 6 08:10:50 2009
New Revision: 731983
URL: http://svn.apache.org/viewvc?rev=731983&view=rev
Log:
SOAP 1.1 allows for arbitrary elements in SOAPEnvelope after SOAPBody (related to WSCOMMONS-197)
Added:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java (with props)
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java (with props)
Modified:
webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/main/java/org/apache/axiom/soap/impl/dom/SOAPEnvelopeImpl.java
webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
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=731983&r1=731982&r2=731983&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 Tue Jan 6 08:10:50 2009
@@ -30,6 +30,7 @@
import org.apache.axiom.om.impl.dom.NodeImpl;
import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.soap.SOAP11Version;
import org.apache.axiom.soap.SOAP12Constants;
import org.apache.axiom.soap.SOAPBody;
import org.apache.axiom.soap.SOAPConstants;
@@ -112,7 +113,6 @@
}
public void addChild(OMNode child) {
- checkChild(child);
if (this.done && (child instanceof SOAPHeader)) {
SOAPBody body = getBody();
if (body != null) {
@@ -126,8 +126,13 @@
public Node insertBefore(Node newChild, Node refChild) throws DOMException {
// Check that the child to be added is valid in the context of a SOAP envelope.
// Note that this also covers the appendChild case, since that method
- // calls insertBefore with refChild == null.
- checkChild((OMNode)newChild);
+ // calls insertBefore with refChild == null.
+
+ // SOAP 1.1 allows for arbitrary elements after SOAPBody so do NOT check for
+ // allowed node types when appending to SOAP 1.1 envelope.
+ if (!(getVersion() instanceof SOAP11Version && refChild == null)) {
+ checkChild((OMNode)newChild);
+ }
return super.insertBefore(newChild, refChild);
}
Added: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java?rev=731983&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java Tue Jan 6 08:10:50 2009
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.om.impl.dom;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axiom.soap.impl.dom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.dom.soap12.SOAP12Factory;
+
+public class SOAPEnvelopeTest extends TestCase {
+
+ public void testAppendSOAP11() throws Exception {
+ SOAP11Factory factory;
+ SOAPEnvelope env;
+
+ // SOAP 1.1 allows for arbitrary elements after SOAPBody element
+
+ // these addChild() should fail since appending before SOAPBody
+ // but they do not at this point (need a better check).
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ checkAddChild(env, false);
+
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ checkAddChild(env, false);
+
+ // these addChild() should work since appending after SOAPBody
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPBody(env);
+ checkAddChild(env, false);
+
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ factory.createSOAPBody(env);
+ checkAddChild(env, false);
+ }
+
+ public void testAppendSOAP12() throws Exception {
+ SOAP12Factory factory;
+ SOAPEnvelope env;
+
+ // SOAP 1.2 only allows SOAPHeader and SOAPBody elements
+
+ // All these addChild() should fail
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPBody(env);
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ factory.createSOAPBody(env);
+ checkAddChild(env, true);
+ }
+
+ private void checkAddChild(SOAPEnvelope env, boolean fail) {
+ OMElement elem = env.getOMFactory().createOMElement(new QName("foo"));
+ if (fail) {
+ try {
+ env.addChild(elem);
+ fail("did not throw exception");
+ } catch (SOAPProcessingException e) {
+ // expected
+ }
+ } else {
+ env.addChild(elem);
+ }
+ }
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-dom/src/test/java/org/apache/axiom/om/impl/dom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain
Modified: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java?rev=731983&r1=731982&r2=731983&view=diff
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java (original)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/main/java/org/apache/axiom/soap/impl/llom/SOAPEnvelopeImpl.java Tue Jan 6 08:10:50 2009
@@ -30,6 +30,7 @@
import org.apache.axiom.om.impl.util.OMSerializerUtil;
import org.apache.axiom.soap.SOAP11Constants;
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;
@@ -90,48 +91,61 @@
}
/**
- * Add a SOAPHeader or SOAPBody object
- * @param child an OMNode to add - must be either a SOAPHeader or a SOAPBody
+ * Check that a node is allowed as a child of a SOAP envelope.
+ *
+ * @param child
*/
- public void addChild(OMNode child) {
- if ((child instanceof OMElement) &&
- !(child instanceof SOAPHeader || child instanceof SOAPBody)) {
+ private void checkChild(OMNode child) {
+ if ((child instanceof OMElement)
+ && !(child instanceof SOAPHeader || child instanceof SOAPBody)) {
throw new SOAPProcessingException(
"SOAP Envelope can not have children other than SOAP Header and Body",
SOAP12Constants.FAULT_CODE_SENDER);
- } else {
- 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);
+ }
+ }
+
+ /**
+ * Add a SOAPHeader or SOAPBody object
+ * @param child an OMNode to add - must be either a SOAPHeader or a SOAPBody
+ */
+ public void addChild(OMNode child) {
+ // 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((OMNode)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;
}
- } 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();
- }
+ node = node.getPreviousOMSibling();
}
}
- super.addChild(child);
}
+ super.addChild(child);
}
/**
Added: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java?rev=731983&view=auto
==============================================================================
--- webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java (added)
+++ webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java Tue Jan 6 08:10:50 2009
@@ -0,0 +1,106 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.axiom.om.impl.llom;
+
+import javax.xml.namespace.QName;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPProcessingException;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axiom.soap.impl.llom.soap12.SOAP12Factory;
+
+public class SOAPEnvelopeTest extends TestCase {
+
+ public void testAppendSOAP11() throws Exception {
+ SOAP11Factory factory;
+ SOAPEnvelope env;
+
+ // SOAP 1.1 allows for arbitrary elements after SOAPBody element
+
+ // these addChild() should fail since appending before SOAPBody
+ // but they do not at this point (need a better check).
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ checkAddChild(env, false);
+
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ checkAddChild(env, false);
+
+ // these addChild() should work since appending after SOAPBody
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPBody(env);
+ checkAddChild(env, false);
+
+ factory = new SOAP11Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ factory.createSOAPBody(env);
+ checkAddChild(env, false);
+ }
+
+ public void testAppendSOAP12() throws Exception {
+ SOAP12Factory factory;
+ SOAPEnvelope env;
+
+ // SOAP 1.2 only allows SOAPHeader and SOAPBody elements
+
+ // All these addChild() should fail
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPBody(env);
+ checkAddChild(env, true);
+
+ factory = new SOAP12Factory();
+ env = factory.createSOAPEnvelope();
+ factory.createSOAPHeader(env);
+ factory.createSOAPBody(env);
+ checkAddChild(env, true);
+ }
+
+ private void checkAddChild(SOAPEnvelope env, boolean fail) {
+ OMElement elem = env.getOMFactory().createOMElement(new QName("foo"));
+ if (fail) {
+ try {
+ env.addChild(elem);
+ fail("did not throw exception");
+ } catch (SOAPProcessingException e) {
+ // expected
+ }
+ } else {
+ env.addChild(elem);
+ }
+ }
+
+}
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: webservices/commons/trunk/modules/axiom/modules/axiom-impl/src/test/java/org/apache/axiom/om/impl/llom/SOAPEnvelopeTest.java
------------------------------------------------------------------------------
svn:mime-type = text/plain