camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1441877 - in /camel/branches/camel-2.10.x: ./ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/impl/ camel-core/src/test/java/org/apache/camel/impl/ components/camel-jms/src/test/java/org/...
Date Sun, 03 Feb 2013 08:56:27 GMT
Author: davsclaus
Date: Sun Feb  3 08:56:27 2013
New Revision: 1441877

URL: http://svn.apache.org/viewvc?rev=1441877&view=rev
Log:
CAMEL-5774: Fixed issuse with file binding when using preMove to load content. Do not support
file bodies for transferExchange as this is not a good idea and causes problem on the receiver
side.

Added:
    camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsPreMoveTest.java
      - copied unchanged from r1441876, camel/trunk/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsPreMoveTest.java
Modified:
    camel/branches/camel-2.10.x/   (props changed)
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileBinding.java
    camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
    camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
    camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
  Merged /camel/trunk:r1441876

Propchange: camel/branches/camel-2.10.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileBinding.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileBinding.java?rev=1441877&r1=1441876&r2=1441877&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileBinding.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/component/file/FileBinding.java
Sun Feb  3 08:56:27 2013
@@ -35,7 +35,7 @@ public class FileBinding implements Gene
             return content;
         }
         
-        // as we use java.io.File itself as the body (not loading its content into a OutputStream
etc.)
+        // as we use java.io.File itself as the body (not loading its content into an OutputStream
etc.)
         // we just store a java.io.File handle to the actual file denoted by the
         // file.getAbsoluteFilePath. We must do this as the original file consumed can be
renamed before
         // being processed (preMove) and thus it points to an invalid file location.
@@ -54,7 +54,7 @@ public class FileBinding implements Gene
     public void loadContent(Exchange exchange, GenericFile<?> file) throws IOException
{
         if (content == null) {
             try {
-                content = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class,
exchange, file.getFile());
+                content = exchange.getContext().getTypeConverter().mandatoryConvertTo(byte[].class,
exchange, file);
             } catch (NoTypeConversionAvailableException e) {
                 throw new IOException("Cannot load file content: " + file.getAbsoluteFilePath(),
e);
             }

Modified: camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java?rev=1441877&r1=1441876&r2=1441877&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/main/java/org/apache/camel/impl/DefaultExchangeHolder.java
Sun Feb  3 08:56:27 2013
@@ -16,12 +16,15 @@
  */
 package org.apache.camel.impl;
 
+import java.io.File;
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.LinkedHashMap;
 import java.util.Map;
 
 import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.WrappedFile;
 import org.apache.camel.util.ObjectHelper;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -30,6 +33,9 @@ import org.slf4j.LoggerFactory;
  * Holder object for sending an exchange over a remote wire as a serialized object.
  * This is usually configured using the <tt>transferExchange=true</tt> option
on the endpoint.
  * <p/>
+ * Note: Message body of type {@link File} or {@link WrappedFile} is <b>not</b>
supported and
+ * a {@link RuntimeExchangeException} is thrown.
+ * <p/>
  * As opposed to normal usage where only the body part of the exchange is transferred over
the wire,
  * this holder object serializes the following fields over the wire:
  * <ul>
@@ -79,6 +85,12 @@ public class DefaultExchangeHolder imple
      * @return the holder object with information copied form the exchange
      */
     public static DefaultExchangeHolder marshal(Exchange exchange, boolean includeProperties)
{
+        // we do not support files
+        Object body = exchange.getIn().getBody();
+        if (body instanceof WrappedFile || body instanceof File) {
+            throw new RuntimeExchangeException("Message body of type " + body.getClass().getCanonicalName()
+ " is not supported by this marshaller.", exchange);
+        }
+
         DefaultExchangeHolder payload = new DefaultExchangeHolder();
 
         payload.exchangeId = exchange.getExchangeId();

Modified: camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java?rev=1441877&r1=1441876&r2=1441877&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
(original)
+++ camel/branches/camel-2.10.x/camel-core/src/test/java/org/apache/camel/impl/DefaultExchangeHolderTest.java
Sun Feb  3 08:56:27 2013
@@ -16,6 +16,7 @@
  */
 package org.apache.camel.impl;
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -23,6 +24,7 @@ import java.util.Map;
 
 import org.apache.camel.ContextTestSupport;
 import org.apache.camel.Exchange;
+import org.apache.camel.RuntimeExchangeException;
 
 /**
  * @version 
@@ -125,6 +127,18 @@ public class DefaultExchangeHolderTest e
         assertNull(exchange.getIn().getHeader("Foo"));
     }
 
+    public void testFileNotSupported() throws Exception {
+        Exchange exchange = new DefaultExchange(context);
+        exchange.getIn().setBody(new File("src/test/resources/log4j.properties"));
+
+        try {
+            DefaultExchangeHolder.marshal(exchange);
+            fail("Should have thrown exception");
+        } catch (RuntimeExchangeException e) {
+            // expected
+        }
+    }
+
     private DefaultExchangeHolder createHolder(boolean includeProperties) {
         Exchange exchange = new DefaultExchange(context);
         id = exchange.getExchangeId();

Modified: camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java?rev=1441877&r1=1441876&r2=1441877&view=diff
==============================================================================
--- camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
(original)
+++ camel/branches/camel-2.10.x/components/camel-jms/src/test/java/org/apache/camel/component/jms/FileRouteJmsKeepLastModifiedTest.java
Sun Feb  3 08:56:27 2013
@@ -28,12 +28,19 @@ import org.junit.Test;
 import static org.apache.camel.component.jms.JmsComponent.jmsComponentAutoAcknowledge;
 
 /**
- * Unit test that we can produce JMS message from files
+ *
  */
 public class FileRouteJmsKeepLastModifiedTest extends CamelTestSupport {
 
     protected String componentName = "activemq";
 
+    @Override
+    public void setUp() throws Exception {
+        deleteDirectory("target/inbox");
+        deleteDirectory("target/outbox");
+        super.setUp();
+    }
+
     @Test
     public void testKeepLastModified() throws Exception {
         getMockEndpoint("mock:result").expectedMessageCount(1);



Mime
View raw message