camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r560349 - in /activemq/camel/trunk: ./ camel-core/src/main/java/org/apache/camel/component/file/ camel-core/src/main/java/org/apache/camel/converter/ camel-core/src/test/java/org/apache/camel/converter/ components/camel-jaxb/src/main/java/o...
Date Fri, 27 Jul 2007 18:40:17 GMT
Author: jstrachan
Date: Fri Jul 27 11:40:16 2007
New Revision: 560349

URL: http://svn.apache.org/viewvc?view=rev&rev=560349
Log:
added the ability to specify file output names in the DSL

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
    activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
    activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
    activemq/camel/trunk/examples/camel-example-etl/pom.xml
    activemq/camel/trunk/examples/camel-example-etl/src/main/java/org/apache/camel/example/etl/EtlRoutes.java
    activemq/camel/trunk/pom.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileComponent.java
Fri Jul 27 11:40:16 2007
@@ -32,7 +32,9 @@
  * @version $Revision: 523772 $
  */
 public class FileComponent extends DefaultComponent<FileExchange> {
-    public FileComponent() {
+    public static final String HEADER_FILE_NAME = "org.apache.camel.file.name";
+
+	public FileComponent() {
     }
 
     public FileComponent(CamelContext context) {

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/FileProducer.java
Fri Jul 27 11:40:16 2007
@@ -14,7 +14,6 @@
 package org.apache.camel.component.file;
 
 import org.apache.camel.Exchange;
-import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Producer;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.ExchangeHelper;
@@ -50,22 +49,17 @@
     }
 
     public void process(FileExchange exchange) throws Exception {
-        String fileName = exchange.getIn().getMessageId();
         ByteBuffer payload = exchange.getIn().getBody(ByteBuffer.class);
         if (payload == null) {
             InputStream in = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
             payload = ExchangeHelper.convertToMandatoryType(exchange, ByteBuffer.class, in);
         }
         payload.flip();
-        File file = null;
-        File endpointFile = endpoint.getFile();
-        if (endpointFile != null && endpointFile.isDirectory()) {
-            file = new File(endpointFile, fileName);
-        }
-        else {
-            file = new File(fileName);
-        }
+        File file = createFileName(exchange);
         buildDirectory(file);
+        if (log.isDebugEnabled()) {
+            log.debug("Creating file: " + file);
+        }
         try {
             FileChannel fc = new RandomAccessFile(file, "rw").getChannel();
             fc.position(fc.size());
@@ -74,6 +68,28 @@
         }
         catch (Throwable e) {
             log.error("Failed to write to File: " + file, e);
+        }
+    }
+
+    protected File createFileName(FileExchange exchange) {
+        String fileName = exchange.getIn().getMessageId();
+
+        File endpointFile = endpoint.getFile();
+        String name = exchange.getIn().getHeader(FileComponent.HEADER_FILE_NAME, String.class);
+        if (name != null) {
+            File answer = new File(endpointFile, name);
+            if (answer.isDirectory()) {
+                return new File(answer, fileName);
+            }
+            else {
+                return answer;
+            }
+        }
+        if (endpointFile != null && endpointFile.isDirectory()) {
+            return new File(endpointFile, fileName);
+        }
+        else {
+            return new File(fileName);
         }
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/IOConverter.java
Fri Jul 27 11:40:16 2007
@@ -45,6 +45,11 @@
     }
 
     @Converter
+    public static File toFile(String name) throws FileNotFoundException {
+        return new File(name);
+    }
+
+    @Converter
     public static OutputStream toOutputStream(File file) throws FileNotFoundException {
         return new BufferedOutputStream(new FileOutputStream(file));
     }

Modified: activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
(original)
+++ activemq/camel/trunk/camel-core/src/test/java/org/apache/camel/converter/ConverterTest.java
Fri Jul 27 11:40:16 2007
@@ -26,6 +26,7 @@
 
 import java.beans.PropertyEditorManager;
 import java.beans.PropertyEditorSupport;
+import java.io.File;
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -131,7 +132,12 @@
         List resultList = converter.convertTo(List.class, intArray);
         assertEquals("List size", 2, resultList.size());
         log.debug("From primitive type array we've created the list: " + resultList);
+    }
 
+    public void testStringToFile() throws Exception {
+        File file = converter.convertTo(File.class, "foo.txt");
+        assertNotNull("Should have converted to a file!");
+        assertEquals("file name", "foo.txt", file.getName());
     }
 
     public void testPrimitiveBooleanConversion() throws Exception {

Modified: activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
(original)
+++ activemq/camel/trunk/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
Fri Jul 27 11:40:16 2007
@@ -46,8 +46,6 @@
     }
 
     public <T> T convertTo(Class<T> type, Object value) {
-        log.debug("Investigating JAXB type conversions");
-
         try {
             if (isJaxbType(type)) {
                 return unmarshall(type, value);

Modified: activemq/camel/trunk/examples/camel-example-etl/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-etl/pom.xml?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/examples/camel-example-etl/pom.xml (original)
+++ activemq/camel/trunk/examples/camel-example-etl/pom.xml Fri Jul 27 11:40:16 2007
@@ -45,6 +45,10 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-jaxb</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.camel</groupId>
+      <artifactId>camel-juel</artifactId>
+    </dependency>
 
     <!-- lets use log4j -->
     <dependency>
@@ -117,6 +121,7 @@
         </executions>
         <configuration>
           <mainClass>org.apache.camel.example.etl.Main</mainClass>
+          <includePluginDependencies>false</includePluginDependencies>
         </configuration>
       </plugin>
 

Modified: activemq/camel/trunk/examples/camel-example-etl/src/main/java/org/apache/camel/example/etl/EtlRoutes.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-etl/src/main/java/org/apache/camel/example/etl/EtlRoutes.java?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/examples/camel-example-etl/src/main/java/org/apache/camel/example/etl/EtlRoutes.java
(original)
+++ activemq/camel/trunk/examples/camel-example-etl/src/main/java/org/apache/camel/example/etl/EtlRoutes.java
Fri Jul 27 11:40:16 2007
@@ -17,6 +17,9 @@
  */
 package org.apache.camel.example.etl;
 
+import static org.apache.camel.language.juel.JuelExpression.el;
+import org.apache.camel.component.file.FileComponent;
+import org.apache.camel.language.juel.JuelExpression;
 import org.apache.camel.spring.SpringRouteBuilder;
 
 /**
@@ -32,7 +35,9 @@
 
 
         // the following will dump the database to files
-        //from("jpa:org.apache.camel.example.etl.CustomerEntity?consumeDelete=false").to("file:target/customers");
+        from("jpa:org.apache.camel.example.etl.CustomerEntity?consumeDelete=false").
+        		setHeader(FileComponent.HEADER_FILE_NAME, el("${in.body.userName}.xml")).
+        		to("file:target/customers");
     }
 }
 // END SNIPPET: example

Modified: activemq/camel/trunk/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/pom.xml?view=diff&rev=560349&r1=560348&r2=560349
==============================================================================
--- activemq/camel/trunk/pom.xml (original)
+++ activemq/camel/trunk/pom.xml Fri Jul 27 11:40:16 2007
@@ -362,7 +362,7 @@
       <dependency>
         <groupId>commons-collections</groupId>
         <artifactId>commons-collections</artifactId>
-        <version>3.1</version>
+        <version>3.2</version>
         <scope>test</scope>
       </dependency>
       <dependency>



Mime
View raw message