You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/10/10 18:58:23 UTC

[camel] branch camel-3.18.x updated: [CXF-8762] CXF client sends the SOAPAction header without quotes (#8494)

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

davsclaus pushed a commit to branch camel-3.18.x
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/camel-3.18.x by this push:
     new fb90d971ada [CXF-8762] CXF client sends the SOAPAction header without quotes (#8494)
fb90d971ada is described below

commit fb90d971ada25c3afa9cfe082b85a08c14aa90c6
Author: Radovan Netuka <rn...@redhat.com>
AuthorDate: Mon Oct 10 20:57:40 2022 +0200

    [CXF-8762] CXF client sends the SOAPAction header without quotes (#8494)
---
 .../camel/component/cxf/jaxws/DefaultCxfBinding.java     | 16 ++++++++++++++++
 .../camel/component/cxf/jaxws/DefaultCxfBindingTest.java | 14 +++++++-------
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBinding.java b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBinding.java
index 9d44c938831..0d5abb73da3 100644
--- a/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBinding.java
+++ b/components/camel-cxf/camel-cxf-soap/src/main/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBinding.java
@@ -25,6 +25,7 @@ import java.nio.charset.StandardCharsets;
 import java.security.Principal;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Iterator;
@@ -64,6 +65,7 @@ import org.apache.camel.support.ExchangeHelper;
 import org.apache.camel.support.SynchronizationAdapter;
 import org.apache.camel.util.IOHelper;
 import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.StringHelper;
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.binding.soap.Soap11;
 import org.apache.cxf.binding.soap.Soap12;
@@ -658,6 +660,12 @@ public class DefaultCxfBinding implements CxfBinding, HeaderFilterStrategyAware
                             LOG.trace("Find the multi-part Conent-Type, and replace it with {}", contentType);
                             camelHeaders.put(entry.getKey(), contentType);
                         }
+                    } else if (SoapBindingConstants.SOAP_ACTION.compareToIgnoreCase(entry.getKey()) == 0
+                            && entry.getValue().get(0) != null) {
+                        String soapAction = entry.getValue().get(0);
+                        // SOAPAction header may contain quoted value. Remove the quotes here.
+                        soapAction = StringHelper.removeLeadingAndEndingQuotes(soapAction);
+                        camelHeaders.put(SoapBindingConstants.SOAP_ACTION, soapAction);
                     } else {
                         LOG.trace("Populate header from CXF header={} value={}",
                                 entry.getKey(), entry.getValue());
@@ -831,6 +839,14 @@ public class DefaultCxfBinding implements CxfBinding, HeaderFilterStrategyAware
         }
 
         if (transportHeaders.size() > 0) {
+            List<String> soapActionList = transportHeaders.get(SoapBindingConstants.SOAP_ACTION);
+            if (soapActionList != null && soapActionList.size() == 1) {
+                String soapAction = soapActionList.get(0);
+                if (!soapAction.isEmpty() && !soapAction.startsWith("\"")) {
+                    //Per RFC, the SOAPAction HTTP header should be quoted if not empty
+                    transportHeaders.put(SoapBindingConstants.SOAP_ACTION, Collections.singletonList("\"" + soapAction + "\""));
+                }
+            }
             cxfContext.put(CxfConstants.PROTOCOL_HEADERS, transportHeaders);
         } else {
             // no propagated transport headers does really mean no headers, not the ones
diff --git a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBindingTest.java b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBindingTest.java
index 748914c8091..5944512d1b9 100644
--- a/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBindingTest.java
+++ b/components/camel-cxf/camel-cxf-soap/src/test/java/org/apache/camel/component/cxf/jaxws/DefaultCxfBindingTest.java
@@ -180,9 +180,9 @@ public class DefaultCxfBindingTest {
         assertNotNull(headers);
         assertEquals(3, headers.size());
 
-        verifyHeader(headers, "soapaction", "urn:hello:world");
-        verifyHeader(headers, "SoapAction", "urn:hello:world");
-        verifyHeader(headers, "SOAPAction", "urn:hello:world");
+        verifyHeader(headers, "soapaction", "\"urn:hello:world\"");
+        verifyHeader(headers, "SoapAction", "\"urn:hello:world\"");
+        verifyHeader(headers, "SOAPAction", "\"urn:hello:world\"");
         verifyHeader(headers, "myfruitheader", "peach");
         verifyHeader(headers, "myFruitHeader", "peach");
         verifyHeader(headers, "MYFRUITHEADER", "peach");
@@ -319,9 +319,9 @@ public class DefaultCxfBindingTest {
         assertNotNull(headers);
         assertEquals(2, headers.size());
 
-        verifyHeader(headers, "soapaction", "urn:hello:world");
-        verifyHeader(headers, "SoapAction", "urn:hello:world");
-        verifyHeader(headers, "SOAPAction", "urn:hello:world");
+        verifyHeader(headers, "soapaction", "\"urn:hello:world\"");
+        verifyHeader(headers, "SoapAction", "\"urn:hello:world\"");
+        verifyHeader(headers, "SOAPAction", "\"urn:hello:world\"");
         verifyHeader(headers, "myfruitheader", "peach");
         verifyHeader(headers, "myFruitHeader", "peach");
         verifyHeader(headers, "MYFRUITHEADER", "peach");
@@ -345,7 +345,7 @@ public class DefaultCxfBindingTest {
         Map<String, List<String>> headers = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
         headers.put("content-type", Arrays.asList("text/xml;charset=UTF-8"));
         headers.put("Content-Length", Arrays.asList("241"));
-        headers.put("soapAction", Arrays.asList("urn:hello:world"));
+        headers.put("soapAction", Arrays.asList("\"urn:hello:world\""));
         headers.put("myfruitheader", Arrays.asList("peach"));
         headers.put("mybrewheader", Arrays.asList("cappuccino", "espresso"));
         cxfMessage.put(org.apache.cxf.message.Message.PROTOCOL_HEADERS, headers);