[camel] branch camel-2.23.x updated: [CAMEL-13898]ensure camel-cxf consumer can propagate protocol headers from camel exchange headers when throwing a soap fault

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

[camel] branch camel-2.23.x updated: [CAMEL-13898]ensure camel-cxf consumer can propagate protocol headers from camel exchange headers when throwing a soap fault

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

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


The following commit(s) were added to refs/heads/camel-2.23.x by this push:
     new 0579d72  [CAMEL-13898]ensure camel-cxf consumer can propagate protocol headers from camel exchange headers when throwing a soap fault
0579d72 is described below

commit 0579d728cbae9c0daf6621a70e62c4308f91300b
Author: Freeman Fang <[hidden email]>
AuthorDate: Thu Aug 22 11:40:58 2019 -0400

    [CAMEL-13898]ensure camel-cxf consumer can propagate protocol headers from camel exchange headers when throwing a soap fault
   
    (cherry picked from commit e5bb417c5b1d06c9cee18443f0b30fbc808eae02)
    (cherry picked from commit fdfa5b4c4c7ec301bf39dfc597bd6aaf6dcfeb21)
    (cherry picked from commit cb6135a7bc018035594a9853f65891038dc5e7bd)
---
 .../apache/camel/component/cxf/CxfConsumer.java    |  1 +
 .../camel/component/cxf/DefaultCxfBinding.java     | 41 ++++++++++++++++++++++
 2 files changed, 42 insertions(+)

diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
index ff6741b..333e037 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfConsumer.java
@@ -318,6 +318,7 @@ public class CxfConsumer extends DefaultConsumer implements Suspendable {
             CxfEndpoint endpoint = (CxfEndpoint)getEndpoint();
             CxfBinding binding = endpoint.getCxfBinding();
 
+            ((DefaultCxfBinding)binding).populateCxfHeaderFromCamelExchangeBeforeCheckError(camelExchange, cxfExchange);
             checkFailure(camelExchange, cxfExchange);
 
             binding.populateCxfResponseFromExchange(camelExchange, cxfExchange);
diff --git a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
index 4c7aa52..ee9eb54 100644
--- a/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
+++ b/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/DefaultCxfBinding.java
@@ -314,6 +314,47 @@ public class DefaultCxfBinding implements CxfBinding, HeaderFilterStrategyAware
             }
         }
     }
+    
+    /**
+     * This method is called by {@link CxfConsumer} to populate a CXF response protocol headers
+     * from a Camel exchange headers before CheckError.
+     * Ensure can send protocol headers back even error/exception thrown
+     */
+    public void populateCxfHeaderFromCamelExchangeBeforeCheckError(Exchange camelExchange,
+            org.apache.cxf.message.Exchange cxfExchange) {
+        
+        if (cxfExchange.isOneWay()) {
+            return;
+        }
+        
+        // create response context
+        Map<String, Object> responseContext = new HashMap<String, Object>();
+        
+        org.apache.camel.Message response;
+        if (camelExchange.getPattern().isOutCapable()) {
+            if (camelExchange.hasOut()) {
+                response = camelExchange.getOut();
+                LOG.trace("Get the response from the out message");
+            } else { // Take the in message as a fall back
+                response = camelExchange.getIn();
+                LOG.trace("Get the response from the in message as a fallback");
+            }
+        } else {
+            response = camelExchange.getIn();
+            LOG.trace("Get the response from the in message");
+        }
+        
+        // propagate response context
+        Map<String, Object> camelHeaders = response.getHeaders();
+        extractInvocationContextFromCamel(camelExchange, camelHeaders,
+                responseContext, Client.RESPONSE_CONTEXT);
+        
+        propagateHeadersFromCamelToCxf(camelExchange, camelHeaders, cxfExchange,
+                responseContext);
+        if (cxfExchange.getOutMessage() != null) {
+            cxfExchange.getOutMessage().put(Message.PROTOCOL_HEADERS, responseContext.get(Message.PROTOCOL_HEADERS));
+        }
+    }
 
     /**
      * This method is called by {@link CxfConsumer} to populate a CXF response exchange