svn commit: r564677 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-ftp/src/main/data/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/ co...

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

svn commit: r564677 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/ camel-core/src/main/java/org/apache/camel/impl/ components/camel-ftp/src/main/data/ components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/ co...

jstrachan-2
Author: jstrachan
Date: Fri Aug 10 09:55:11 2007
New Revision: 564677

URL: http://svn.apache.org/viewvc?view=rev&rev=564677
Log:
added a test case and bug fix for CAMEL-98

Added:
    activemq/camel/trunk/components/camel-ftp/src/main/data/
    activemq/camel/trunk/components/camel-ftp/src/main/data/bar.xml
      - copied unchanged from r564651, activemq/camel/trunk/camel-core/src/main/data/bar.xml
    activemq/camel/trunk/components/camel-ftp/src/main/data/foo.xml
      - copied unchanged from r564651, activemq/camel/trunk/camel-core/src/main/data/foo.xml
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java   (with props)
Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
    activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
    activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java?view=diff&rev=564677&r1=564676&r2=564677
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/Message.java Fri Aug 10 09:55:11 2007
@@ -16,6 +16,8 @@
  */
 package org.apache.camel;
 
+import org.apache.camel.impl.MessageSupport;
+
 import java.util.Map;
 
 /**
@@ -120,4 +122,8 @@
      */
     Message copy();
 
+    /**
+     * Copies the contents of the other message into this message
+     */
+    void copyFrom(Message message);
 }

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java?view=diff&rev=564677&r1=564676&r2=564677
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/DefaultExchange.java Fri Aug 10 09:55:11 2007
@@ -59,12 +59,33 @@
             return;
         }
         setProperties(safeCopy(exchange.getProperties()));
-        setIn(safeCopy(exchange.getIn()));
-        setOut(safeCopy(exchange.getOut()));
-        setFault(safeCopy(exchange.getFault()));
+
+        // this can cause strangeness if we copy, say, a FileMessage onto an FtpExchange with overloaded getExchange() methods etc.
+
+        safeCopy(getIn(), exchange, exchange.getIn());
+        Message copyOut = exchange.getOut();
+        if (copyOut != null) {
+            safeCopy(getOut(true), exchange, copyOut);
+        }
+        Message copyFault = exchange.getFault();
+        if (copyFault != null) {
+            safeCopy(getFault(), exchange, copyFault);
+        }
+
+/*
+        setIn(safeCopy(exchange, exchange.getIn()));
+        setOut(safeCopy(exchange, exchange.getOut()));
+        setFault(safeCopy(exchange, exchange.getFault()));
+*/
         setException(exchange.getException());
     }
 
+    private static void safeCopy(Message message, Exchange exchange, Message that) {
+        if (message != null) {
+            message.copyFrom(that);
+        }
+    }
+
     private static Map<String, Object> safeCopy(Map<String, Object> properties) {
         if (properties == null) {
             return null;
@@ -72,11 +93,16 @@
         return new HashMap<String, Object>(properties);
     }
 
-    private static Message safeCopy(Message message) {
+    private static Message safeCopy(Exchange exchange, Message message) {
         if (message == null) {
             return null;
         }
-        return message.copy();
+        Message answer = message.copy();
+        if (answer instanceof MessageSupport) {
+            MessageSupport messageSupport = (MessageSupport) answer;
+            messageSupport.setExchange(exchange);
+        }
+        return answer;
     }
 
     public Exchange newInstance() {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java?view=diff&rev=564677&r1=564676&r2=564677
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java (original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/MessageSupport.java Fri Aug 10 09:55:11 2007
@@ -69,10 +69,14 @@
 
     public Message copy() {
         Message answer = newInstance();
-        answer.setMessageId(getMessageId());
-        answer.setBody(getBody());
-        answer.getHeaders().putAll(getHeaders());
+        answer.copyFrom(this);
         return answer;
+    }
+
+    public void copyFrom(Message that) {
+        setMessageId(that.getMessageId());
+        setBody(that.getBody());
+        getHeaders().putAll(that.getHeaders());
     }
 
     public Exchange getExchange() {

Added: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java?view=auto&rev=564677
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java (added)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java Fri Aug 10 09:55:11 2007
@@ -0,0 +1,44 @@
+/**
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.component.file.remote;
+
+import org.apache.camel.builder.RouteBuilder;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class FromFileToFtpTest extends FtpRouteTest {
+    public void testFtpRoute() throws Exception {
+        resultEndpoint.expectedMinimumMessageCount(1);
+
+        resultEndpoint.assertIsSatisfied();
+    }
+
+    protected RouteBuilder createRouteBuilder() throws Exception {
+        ftpUrl = "ftp://admin@localhost:20010/tmp2/camel?password=admin";
+
+
+        return new RouteBuilder() {
+            public void configure() throws Exception {
+                from("file:src/main/data?noop=true").to(ftpUrl);
+
+                from(ftpUrl).to("mock:result");
+            }
+        };
+    }
+}

Propchange: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFileToFtpTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java?view=diff&rev=564677&r1=564676&r2=564677
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java (original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpRouteTest.java Fri Aug 10 09:55:11 2007
@@ -32,11 +32,11 @@
  */
 public class FtpRouteTest extends ContextTestSupport {
     protected MockEndpoint resultEndpoint;
-    protected String startEndpointUri = "ftp://admin@localhost:20010/tmp/camel?password=admin";
+    protected String ftpUrl = "ftp://admin@localhost:20010/tmp/camel?password=admin";
     protected FtpServer ftpServer;
+    protected String expectedBody = "Hello there!";
 
-    public void testFtpRouteWithTextMessage() throws Exception {
-        String expectedBody = "Hello there!";
+    public void testFtpRoute() throws Exception {
 
         resultEndpoint.expectedBodiesReceived(expectedBody);
 
@@ -50,7 +50,7 @@
     }
 
     protected void sendExchange(final Object expectedBody) {
-        template.sendBodyAndHeader(startEndpointUri, expectedBody, "cheese", 123);
+        template.sendBodyAndHeader(ftpUrl, expectedBody, "cheese", 123);
     }
 
     @Override
@@ -75,7 +75,7 @@
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() throws Exception {
-                from(startEndpointUri).to("mock:result");
+                from(ftpUrl).to("mock:result");
             }
         };
     }

Modified: activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties?view=diff&rev=564677&r1=564676&r2=564677
==============================================================================
--- activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties (original)
+++ activemq/camel/trunk/components/camel-ftp/src/test/resources/log4j.properties Fri Aug 10 09:55:11 2007
@@ -20,10 +20,12 @@
 #
 log4j.rootLogger=WARN, out
 
+# uncomment the following to enable camel debugging
+#log4j.logger.org.apache.camel=DEBUG
+
 log4j.logger.org.apache.activemq=WARN
 log4j.logger.org.apache.mina=WARN
 log4j.logger.org.apache.ftpserver=WARN
-#log4j.logger.org.apache.camel=DEBUG
 
 # CONSOLE appender not used by default
 log4j.appender.out=org.apache.log4j.ConsoleAppender