You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2012/11/13 10:47:59 UTC
svn commit: r1408656 - in /camel/trunk:
camel-core/src/main/java/org/apache/camel/component/file/
components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/
components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/
Author: davsclaus
Date: Tue Nov 13 09:47:58 2012
New Revision: 1408656
URL: http://svn.apache.org/viewvc?rev=1408656&view=rev
Log:
CAMEL-5320: Added download option to ftp component. Thanks to Rich Newcomb for the patch. I added unit test.
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java (with props)
Modified:
camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java?rev=1408656&r1=1408655&r2=1408656&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/file/GenericFileConsumer.java Tue Nov 13 09:47:58 2012
@@ -310,20 +310,26 @@ public abstract class GenericFileConsume
// must use full name when downloading so we have the correct path
final String name = target.getAbsoluteFilePath();
try {
- // retrieve the file using the stream
- log.trace("Retrieving file: {} from: {}", name, endpoint);
-
- // retrieve the file and check it was a success
- boolean retrieved = operations.retrieveFile(name, exchange);
- if (!retrieved) {
- // throw exception to handle the problem with retrieving the file
- // then if the method return false or throws an exception is handled the same in here
- // as in both cases an exception is being thrown
- throw new GenericFileOperationFailedException("Cannot retrieve file: " + file + " from: " + endpoint);
+
+ if (isRetrieveFile()) {
+ // retrieve the file using the stream
+ log.trace("Retrieving file: {} from: {}", name, endpoint);
+
+ // retrieve the file and check it was a success
+ boolean retrieved = operations.retrieveFile(name, exchange);
+ if (!retrieved) {
+ // throw exception to handle the problem with retrieving the file
+ // then if the method return false or throws an exception is handled the same in here
+ // as in both cases an exception is being thrown
+ throw new GenericFileOperationFailedException("Cannot retrieve file: " + file + " from: " + endpoint);
+ }
+
+ log.trace("Retrieved file: {} from: {}", name, endpoint);
+ } else {
+ log.trace("Skiped retrieval of file: {} from: {}", name, endpoint);
+ exchange.getIn().setBody(null);
}
- log.trace("Retrieved file: {} from: {}", name, endpoint);
-
// register on completion callback that does the completion strategies
// (for instance to move the file after we have processed it)
exchange.addOnCompletion(new GenericFileOnCompletion<T>(endpoint, operations, target, absoluteFileName));
@@ -355,6 +361,15 @@ public abstract class GenericFileConsume
}
/**
+ * Override if required. Files are retrieved / returns true by default
+ *
+ * @return <tt>true</tt> to retrieve files, <tt>false</tt> to skip retrieval of files.
+ */
+ protected boolean isRetrieveFile() {
+ return true;
+ }
+
+ /**
* Processes the exchange using a custom processor.
*
* @param exchange the exchange
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java?rev=1408656&r1=1408655&r2=1408656&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileConsumer.java Tue Nov 13 09:47:58 2012
@@ -93,6 +93,11 @@ public abstract class RemoteFileConsumer
exchange.setProperty(Exchange.UNIT_OF_WORK_PROCESS_SYNC, Boolean.TRUE);
super.processExchange(exchange);
}
+
+ @Override
+ protected boolean isRetrieveFile() {
+ return getEndpoint().isDownload();
+ }
@Override
protected void doStop() throws Exception {
Modified: camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java?rev=1408656&r1=1408655&r2=1408656&view=diff
==============================================================================
--- camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java (original)
+++ camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java Tue Nov 13 09:47:58 2012
@@ -37,6 +37,7 @@ public abstract class RemoteFileEndpoint
private long reconnectDelay = 1000;
private boolean disconnect;
private boolean fastExistsCheck;
+ private boolean download = true;
public RemoteFileEndpoint() {
// no args constructor for spring bean endpoint configuration
@@ -198,5 +199,12 @@ public abstract class RemoteFileEndpoint
public void setFastExistsCheck(boolean fastExistsCheck) {
this.fastExistsCheck = fastExistsCheck;
}
+
+ public boolean isDownload() {
+ return this.download;
+ }
+ public void setDownload(boolean download) {
+ this.download = download;
+ }
}
Added: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java?rev=1408656&view=auto
==============================================================================
--- camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java (added)
+++ camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java Tue Nov 13 09:47:58 2012
@@ -0,0 +1,79 @@
+/**
+ * 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.Endpoint;
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.Producer;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ *
+ */
+public class FromFtpNotDownloadTest extends FtpServerTestSupport {
+
+ protected String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/download?password=admin&noop=true&download=false";
+ }
+
+ @Override
+ @Before
+ public void setUp() throws Exception {
+ super.setUp();
+ prepareFtpServer();
+ }
+
+ @Test
+ public void testNotDownload() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isNull();
+ mock.message(0).header(Exchange.FILE_NAME).isEqualTo("hello.txt");
+
+ mock.assertIsSatisfied();
+ }
+
+ private void prepareFtpServer() throws Exception {
+ Endpoint endpoint = context.getEndpoint(getFtpUrl());
+ Exchange exchange = endpoint.createExchange();
+ exchange.getIn().setBody("Hello World this file will not be downloaded");
+ exchange.getIn().setHeader(Exchange.FILE_NAME, "hello.txt");
+ Producer producer = endpoint.createProducer();
+ producer.start();
+ producer.process(exchange);
+ producer.stop();
+ }
+
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() throws Exception {
+ from(getFtpUrl()).process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ assertNull("Should not download the file", exchange.getIn().getBody());
+ assertEquals("hello.txt", exchange.getIn().getHeader(Exchange.FILE_NAME));
+ }
+ }).to("mock:result");
+ }
+ };
+ }
+
+
+}
Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FromFtpNotDownloadTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date