Merged revisions 1446995 via svnmerge from 
https://svn.apache.org/repos/asf/servicemix/smx4/features/trunk

........
  r1446995 | ningjiang | 2013-02-17 11:31:07 +0800 (Sun, 17 Feb 2013) | 1 line
  
  SMX4-1378 copy the cxf protocol header to nmr message
........


git-svn-id: https://svn.apache.org/repos/asf/servicemix/smx4/features/branches/features-4.4.x@1446996 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitOutputStream.java b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitOutputStream.java
index 6ce4874..8fb8d0e 100644
--- a/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitOutputStream.java
+++ b/cxf/cxf-transport-nmr/src/main/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitOutputStream.java
@@ -27,16 +27,15 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.logging.Logger;
-
 import javax.activation.DataHandler;
 import javax.jws.WebService;
 import javax.security.auth.Subject;
 import javax.xml.namespace.QName;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
-
 import org.apache.cxf.attachment.AttachmentImpl;
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.io.CachedOutputStream;
@@ -139,6 +138,17 @@
                     inMsg.setHeader(ent.getKey(), ent.getValue());
                 }
             }
+
+            // we need to copy the protocol headers
+            Map<String, List<String>> protocolHeaders = (Map<String, List<String>>)message.get(Message.PROTOCOL_HEADERS);
+            if (protocolHeaders != null) {
+                for (Map.Entry<String, List<String>> ent : protocolHeaders.entrySet()) {
+                    if (ent.getValue().size() > 0) {
+                        // here we just put the first header value
+                        inMsg.setHeader(ent.getKey(), ent.getValue().get(0));
+                    }
+                }
+            }
             
             //copy securitySubject
             inMsg.setSecuritySubject((Subject) message.get(NMRTransportFactory.NMR_SECURITY_SUBJECT));
diff --git a/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitTest.java b/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitTest.java
index 1963dad..4757e14 100644
--- a/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitTest.java
+++ b/cxf/cxf-transport-nmr/src/test/java/org/apache/servicemix/cxf/transport/nmr/NMRConduitTest.java
@@ -24,13 +24,15 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.lang.reflect.Method;
+import java.util.ArrayList;
 import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.TreeMap;
 import java.util.logging.Logger;
-
 import javax.xml.stream.XMLStreamReader;
 import javax.xml.transform.Source;
 import javax.xml.transform.stream.StreamSource;
-
 import org.apache.cxf.common.logging.LogUtils;
 import org.apache.cxf.message.ExchangeImpl;
 import org.apache.cxf.message.Message;
@@ -71,6 +73,12 @@
         Class<org.apache.servicemix.cxf.transport.nmr.Greeter> greeterCls
             = org.apache.servicemix.cxf.transport.nmr.Greeter.class;
         message.put(Method.class.getName(), greeterCls.getMethod("sayHi"));
+        Map<String, List<String>> protocolHeaders = new TreeMap<String, List<String>>(String.CASE_INSENSITIVE_ORDER);
+        List<String> value = new ArrayList<String>();
+        value.add("value");
+        protocolHeaders.put("myHeader", value);
+        message.put(Message.PROTOCOL_HEADERS,  protocolHeaders);
+
         
         org.apache.cxf.message.Exchange exchange = new ExchangeImpl();
         exchange.setOneWay(false);
@@ -86,6 +94,9 @@
         EasyMock.expect(channel.createExchange(Pattern.InOut)).andReturn(xchg);
         org.apache.servicemix.nmr.api.Message inMsg = control.createMock(org.apache.servicemix.nmr.api.Message.class);
         EasyMock.expect(xchg.getIn()).andReturn(inMsg);
+        // just need to make sure the customer header is set
+        inMsg.setHeader("myHeader", "value");
+        EasyMock.expectLastCall();
         EndpointRegistry endpoints = control.createMock(EndpointRegistry.class);
         EasyMock.expect(channel.getNMR()).andReturn(nmr);
         EasyMock.expect(nmr.getEndpointRegistry()).andReturn(endpoints);
@@ -108,7 +119,10 @@
         OutputStream os = message.getContent(OutputStream.class);
         assertTrue("The OutputStream should not be null ", os != null);
         os.write("HelloWorld".getBytes());
-        os.close();              
+        os.close();
+        control.verify();
+        // check the customer protocol header
+        //assertEquals("Should get the customer header here.", "value", headers.get("myHeader"));
         InputStream is = inMessage.getContent(InputStream.class);
         assertNotNull(is);
         XMLStreamReader reader = StaxUtils.createXMLStreamReader(is, null);