camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r675124 - in /activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf: CxfSoapBinding.java transport/CamelConduit.java transport/CamelDestination.java
Date Wed, 09 Jul 2008 09:31:23 GMT
Author: ningjiang
Date: Wed Jul  9 02:31:23 2008
New Revision: 675124

URL: http://svn.apache.org/viewvc?rev=675124&view=rev
Log:
CAMEL-686 Applied patch with thanks to Eduard

Modified:
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
    activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java?rev=675124&r1=675123&r2=675124&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/CxfSoapBinding.java
Wed Jul  9 02:31:23 2008
@@ -17,10 +17,17 @@
 package org.apache.camel.component.cxf;
 
 import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
 
 import javax.xml.transform.Source;
 
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.message.ExchangeImpl;
+import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
 
 public final class CxfSoapBinding {
@@ -43,8 +50,17 @@
             cxfExchange = new ExchangeImpl();
             exchange.setProperty(CxfConstants.CXF_EXCHANGE, cxfExchange);
         }
-        Object body = message.getBody(InputStream.class);
 
+        Map<String, Object> headers = null;
+        if (isClient) {
+            headers = exchange.getOut().getHeaders();
+        } else {
+            headers = exchange.getIn().getHeaders();
+        }
+
+        answer.put(Message.PROTOCOL_HEADERS, getProtocolHeader(headers));
+
+        Object body = message.getBody(InputStream.class);
         if (body == null) {
             body = message.getBody();
         }
@@ -74,6 +90,14 @@
         } else {
             message = exchange.getOut();
         }
+        Map<String, Object> headers = null;
+        if (isClient) {
+            headers = exchange.getIn().getHeaders();
+        } else {
+            headers = exchange.getOut().getHeaders();
+        }
+
+        outMessage.put(Message.PROTOCOL_HEADERS, getProtocolHeader(headers));
         // send the body back
         Object body = message.getBody(Source.class);
         if (body == null) {
@@ -86,5 +110,39 @@
         return outMessage;
     }
 
+    private static Map<String, List<String>> getProtocolHeader(Map<String,
Object> headers) {
+        Map<String, List<String>> protocolHeader = new HashMap<String, List<String>>();
+        Iterator headersKeySetIterator = headers.keySet().iterator();
+        while (headersKeySetIterator.hasNext()) {
+            String key = (String)headersKeySetIterator.next();
+            Object value = headers.get(key);
+            if (value != null) {
+                protocolHeader.put(key, Collections.singletonList(value.toString()));
+            } else {
+                protocolHeader.put(key, null);
+            }
+        }
+        return protocolHeader;
+    }
+
+    public static void setProtocolHeader(Map<String, Object> headers, Map<String,
List<String>> protocolHeader) {
+        if (protocolHeader != null) {
+            StringBuilder value = new StringBuilder(256);
+            for (Map.Entry<String, List<String>> entry : protocolHeader.entrySet())
{
+                value.setLength(0);
+                boolean first = true;
+                for (String s : entry.getValue()) {
+                    if (!first) {
+                        value.append("; ");
+                    }
+                    value.append(s);
+                    first = false;
+                }
+                headers.put(entry.getKey(), value.toString());
+            }
+        }
+
+    }
+
 
 }

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java?rev=675124&r1=675123&r2=675124&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelConduit.java
Wed Jul  9 02:31:23 2008
@@ -18,6 +18,8 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -33,8 +35,10 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
+import org.apache.cxf.service.Service;
 import org.apache.cxf.service.model.EndpointInfo;
 import org.apache.cxf.transport.AbstractConduit;
 import org.apache.cxf.transport.Conduit;
@@ -155,18 +159,18 @@
                 pattern = ExchangePattern.InOut;
             }
             getLogger().log(Level.FINE, "send the message to endpoint" + targetCamelEndpointUri);
-            // we could wait for the rely asynconized
+            // We could wait for the rely asynchronously
             org.apache.camel.Exchange exchange = getCamelTemplate().send(targetCamelEndpointUri,
pattern, new Processor() {
                 public void process(org.apache.camel.Exchange ex) throws IOException {
                     CachedOutputStream outputStream = (CachedOutputStream)outMessage.getContent(OutputStream.class);
-                    // send out the request message here
-                    ex.getIn().setHeaders(outMessage);
-                    ex.getIn().setBody(outputStream.getInputStream());
-                    // setup the out message
+                    // Send out the request message here, copy the protocolHeader back
+                    Map<String, List<String>> protocolHeader = CastUtils.cast((Map<?,
?>)outMessage.get(Message.PROTOCOL_HEADERS));
+                    CxfSoapBinding.setProtocolHeader(ex.getIn().getHeaders(), protocolHeader);
+                    ex.getIn().setBody(outputStream.getBytes());
                     getLogger().log(Level.FINE, "template sending request: ", ex.getIn());
                 }
             });
-
+            exchange.setProperty(CxfConstants.CXF_EXCHANGE, outMessage.getExchange());
             if (!isOneWay) {
                 handleResponse(exchange);
             }

Modified: activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java?rev=675124&r1=675123&r2=675124&view=diff
==============================================================================
--- activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
(original)
+++ activemq/camel/trunk/components/camel-cxf/src/main/java/org/apache/camel/component/cxf/transport/CamelDestination.java
Wed Jul  9 02:31:23 2008
@@ -18,6 +18,8 @@
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.List;
+import java.util.Map;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -34,6 +36,7 @@
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.configuration.Configurable;
 import org.apache.cxf.configuration.Configurer;
+import org.apache.cxf.helpers.CastUtils;
 import org.apache.cxf.io.CachedOutputStream;
 import org.apache.cxf.message.Message;
 import org.apache.cxf.message.MessageImpl;
@@ -240,12 +243,13 @@
             outMessage = m;
         }
 
-        // prepair the message and get the send out message
+        // Prepare the message and get the send out message
         private void commitOutputMessage() throws IOException {
             Exchange camelExchange = (Exchange)outMessage.get(CxfConstants.CAMEL_EXCHANGE);
-            camelExchange.getOut().setHeaders(outMessage);
+            Map<String, List<String>> protocolHeader = CastUtils.cast((Map<?,
?>)outMessage.get(Message.PROTOCOL_HEADERS));
+            CxfSoapBinding.setProtocolHeader(camelExchange.getOut().getHeaders(), protocolHeader);
             CachedOutputStream outputStream = (CachedOutputStream)outMessage.getContent(OutputStream.class);
-            camelExchange.getOut().setBody(outputStream.getInputStream());
+            camelExchange.getOut().setBody(outputStream.getBytes());
             getLogger().log(Level.FINE, "send the response message: " + outputStream);
 
         }



Mime
View raw message