This is an automated email from the ASF dual-hosted git repository.

veithen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ws-axiom.git


The following commit(s) were added to refs/heads/master by this push:
     new 2d9b87f  AXIOM-512: Allow adding OMElements to SOAPHeaders
2d9b87f is described below

commit 2d9b87f40d3851fbf0f78fe4949190f15a7977ec
Author: Andreas Veithen <[email protected]>
AuthorDate: Sat Mar 12 22:28:50 2022 +0000

    AXIOM-512: Allow adding OMElements to SOAPHeaders
---
 .../soap/impl/mixin/AxiomSOAPHeaderMixin.java      |  6 ++-
 .../apache/axiom/ts/soap/SOAPTestSuiteBuilder.java |  1 +
 .../header/TestAddChildWithPlainOMElement.java     | 46 ++++++++++++++++++++++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git 
a/mixins/om-mixins/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderMixin.java
 
b/mixins/om-mixins/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderMixin.java
index 4109680..b53552c 100644
--- 
a/mixins/om-mixins/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderMixin.java
+++ 
b/mixins/om-mixins/src/main/java/org/apache/axiom/soap/impl/mixin/AxiomSOAPHeaderMixin.java
@@ -39,6 +39,7 @@ import org.apache.axiom.soap.impl.common.MURoleChecker;
 import org.apache.axiom.soap.impl.common.RoleChecker;
 import org.apache.axiom.soap.impl.common.RolePlayerChecker;
 import org.apache.axiom.soap.impl.common.SOAPHeaderBlockMapper;
+import org.apache.axiom.soap.impl.intf.AxiomSOAPElement;
 import org.apache.axiom.soap.impl.intf.AxiomSOAPHeader;
 import org.apache.axiom.weaver.annotation.Mixin;
 
@@ -46,7 +47,10 @@ import org.apache.axiom.weaver.annotation.Mixin;
 public abstract class AxiomSOAPHeaderMixin implements AxiomSOAPHeader {
     @Override
     public final boolean isChildElementAllowed(OMElement child) {
-        return child instanceof SOAPHeaderBlock;
+        // Axiom 1.2.x allowed adding plain OMElements as children to 
SOAPHeaders. Note that the
+        // Iterator<SOAPHeaderBlock> instances will automatically replace such 
elements by
+        // SOAPHeaderBlocks.
+        return child instanceof SOAPHeaderBlock || !(child instanceof 
AxiomSOAPElement);
     }
 
     @Override
diff --git 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
index e8fe925..101eee8 100644
--- 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
+++ 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/SOAPTestSuiteBuilder.java
@@ -209,6 +209,7 @@ public class SOAPTestSuiteBuilder extends 
MatrixTestSuiteBuilder {
         addTest(new 
org.apache.axiom.ts.soap.faultrole.TestGetRoleValue(metaFactory, spec));
         addTest(new 
org.apache.axiom.ts.soap.faultrole.TestGetRoleValueWithParser(metaFactory, 
spec));
         addTest(new 
org.apache.axiom.ts.soap.faultrole.TestSetRoleValue(metaFactory, spec));
+        addTest(new 
org.apache.axiom.ts.soap.header.TestAddChildWithPlainOMElement(metaFactory, 
spec));
         addTest(new 
org.apache.axiom.ts.soap.header.TestAddHeaderBlock(metaFactory, spec));
         addTest(new 
org.apache.axiom.ts.soap.header.TestAddHeaderBlockFromQName(metaFactory, spec));
         addTest(new 
org.apache.axiom.ts.soap.header.TestAddHeaderBlockFromQNameWithoutNamespace(metaFactory,
 spec));
diff --git 
a/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/header/TestAddChildWithPlainOMElement.java
 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/header/TestAddChildWithPlainOMElement.java
new file mode 100644
index 0000000..3048197
--- /dev/null
+++ 
b/testing/axiom-testsuite/src/main/java/org/apache/axiom/ts/soap/header/TestAddChildWithPlainOMElement.java
@@ -0,0 +1,46 @@
+/*
+ * 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.ts.soap.header;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import java.util.Iterator;
+
+import org.apache.axiom.om.OMMetaFactory;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.ts.soap.SOAPSpec;
+import org.apache.axiom.ts.soap.SOAPTestCase;
+
+/** Regression test for AXIOM-512. */
+public class TestAddChildWithPlainOMElement extends SOAPTestCase {
+    public TestAddChildWithPlainOMElement(OMMetaFactory metaFactory, SOAPSpec 
spec) {
+        super(metaFactory, spec);
+    }
+
+    @Override
+    protected void runTest() throws Throwable {
+        SOAPHeader soapHeader = soapFactory.createSOAPHeader();
+        soapHeader.addChild(soapFactory.createOMElement("foobar", 
"http://example.org";, "p"));
+        Iterator<SOAPHeaderBlock> it = soapHeader.examineAllHeaderBlocks();
+        assertThat(it.hasNext()).isTrue();
+        SOAPHeaderBlock headerBlock = it.next();
+        assertThat(headerBlock.getLocalName()).isEqualTo("foobar");
+    }
+}

Reply via email to