Author: ningjiang
Date: Fri Aug 28 12:11:14 2009
New Revision: 808856

URL: http://svn.apache.org/viewvc?rev=808856&view=rev
Log:
CAMEL-1955 Fixed the issue of MessageSupport.copyFrom()

Modified:
    
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java

Modified: 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?rev=808856&r1=808855&r2=808856&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
 (original)
+++ 
camel/branches/camel-1.x/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
 Fri Aug 28 12:11:14 2009
@@ -136,7 +136,9 @@
     public void copyFrom(Message that) {
         setMessageId(that.getMessageId());
         setBody(that.getBody());
+        getHeaders().clear();
         getHeaders().putAll(that.getHeaders());
+        getAttachments().clear();
         getAttachments().putAll(that.getAttachments());
     }
 

Modified: 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
URL: 
http://svn.apache.org/viewvc/camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java?rev=808856&r1=808855&r2=808856&view=diff
==============================================================================
--- 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
 (original)
+++ 
camel/branches/camel-1.x/camel-core/src/test/java/org/apache/camel/processor/PipelineTest.java
 Fri Aug 28 12:11:14 2009
@@ -16,8 +16,12 @@
  */
 package org.apache.camel.processor;
 
+import javax.activation.DataHandler;
+import javax.activation.FileDataSource;
+
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.ExchangePattern;
 import org.apache.camel.Message;
 import org.apache.camel.Processor;
 import org.apache.camel.builder.RouteBuilder;
@@ -121,6 +125,22 @@
         assertEquals(3, exchange.getOut().getHeader("copy-counter"));  
     }
     
+    public void testCopyInOutExchange() {
+        Exchange exchange = template.request("direct:start", new Processor() {
+            public void process(Exchange exchange) {
+                exchange.setPattern(ExchangePattern.InOut);
+                exchange.getIn().setBody("test");
+            }
+        });
+        assertEquals("There should have no message header", 0, 
exchange.getOut().getHeaders().size());
+        assertEquals("There should have no attachments", 0, 
exchange.getOut().getAttachments().size());
+        assertEquals("Get a wrong message body", "test", 
exchange.getOut().getBody());
+        assertNull(exchange.getOut().getHeader("test"));
+        assertNull(exchange.getOut().getAttachment("test1.xml"));
+        
+    }
+    
+    
     @Override
     protected void setUp() throws Exception {
         super.setUp();
@@ -153,6 +173,25 @@
                 from("direct:b").process(new InToOut()).process(new 
InToOut()).process(new InToOut());
                 // Create a route that uses the  InToFault processor.. the 
last InToOut will not be called since the Fault occurs before.
                 from("direct:c").process(new InToOut()).process(new 
InToFault()).process(new InToOut());
+                
+                from("direct:start")
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            exchange.getOut().copyFrom(exchange.getIn());
+                            //Added the header and attachment
+                            exchange.getOut().setHeader("test", "testValue");
+                            exchange.getOut().addAttachment("test1.xml", new 
DataHandler(new FileDataSource("pom.xml")));
+                        }
+                    })
+                    .process(new Processor() {
+                        public void process(Exchange exchange) throws 
Exception {
+                            exchange.getOut().copyFrom(exchange.getIn());
+                            assertNotNull("The test attachment should not be 
null", exchange.getOut().getAttachment("test1.xml"));
+                            assertNotNull("The test header should not be 
null", exchange.getOut().getHeader("test"));
+                            exchange.getOut().removeAttachment("test1.xml");
+                            exchange.getOut().removeHeader("test");
+                        }
+                    });
             }
         };
     }


Reply via email to