Author: davsclaus
Date: Wed Jan 21 23:56:56 2009
New Revision: 736583
URL: http://svn.apache.org/viewvc?rev=736583&view=rev
Log:
CAMEL-505: ftp endpoint can now be created using spring beans
Added:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
(contents, props changed)
- copied, changed from r736562,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
(contents, props changed)
- copied, changed from r736562,
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/RemoteFileEndpoint.java
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=736583&r1=736582&r2=736583&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
Wed Jan 21 23:56:56 2009
@@ -71,6 +71,9 @@
private String readLock = "none";
private long readLockTimeout;
+ public RemoteFileEndpoint() {
+ }
+
public RemoteFileEndpoint(String uri, RemoteFileComponent component,
RemoteFileOperations operations, RemoteFileConfiguration configuration) {
super(uri, component);
this.operations = operations;
@@ -90,13 +93,23 @@
}
public RemoteFileConsumer createConsumer(Processor processor) throws
Exception {
+ ObjectHelper.notNull(configuration, "remoteFileConfiguration");
String protocol = getConfiguration().getProtocol();
ObjectHelper.notEmpty(protocol, "protocol");
+ ObjectHelper.notEmpty(configuration.getHost(), "host");
RemoteFileConsumer consumer;
if ("ftp".equals(protocol)) {
+ // create operations for this protocol if not already set
+ // for instance if using spring bean configured endpoints instead
of URI parameters
+ if (operations == null) {
+ operations = new FtpRemoteFileOperations();
+ }
consumer = new FtpConsumer(this, processor, operations);
} else if ("sftp".equals(protocol)) {
+ if (operations == null) {
+ operations = new SftpRemoteFileOperations();
+ }
consumer = new SftpConsumer(this, processor, operations);
} else {
throw new IllegalArgumentException("Unsupported protocol: " +
protocol);
@@ -151,6 +164,10 @@
this.processStrategy = remoteFileProcessStrategy;
}
+ public void setRemoteFileOperations(RemoteFileOperations operations) {
+ this.operations = operations;
+ }
+
public boolean isNoop() {
return noop;
}
@@ -387,6 +404,7 @@
* A strategy method to lazily create the file strategy
*/
protected RemoteFileProcessStrategy createRemoteFileStrategy() {
+ ObjectHelper.notNull(getCamelContext(), "camelContext");
Class<?> factory = null;
try {
FactoryFinder finder =
getCamelContext().createFactoryFinder("META-INF/services/org/apache/camel/component/");
Copied:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
(from r736562,
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java?p2=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java&p1=camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java&r1=736562&r2=736583&rev=736583&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest.java
(original)
+++
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
Wed Jan 21 23:56:56 2009
@@ -31,13 +31,12 @@
import
org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
/**
- * Unit testing FTP ant path matcher
+ * Unit testing FTP configured using spring bean
*/
@ContextConfiguration
-public class SpringFileAntPathMatcherRemoteFileFilterTest extends
AbstractJUnit38SpringContextTests {
+public class SpringFtpEndpointTest extends AbstractJUnit38SpringContextTests {
protected FtpServer ftpServer;
- protected String expectedBody = "Godday World";
@Autowired
protected ProducerTemplate template;
@EndpointInject(name = "myFTPEndpoint")
@@ -45,14 +44,10 @@
@EndpointInject(uri = "mock:result")
protected MockEndpoint result;
- public void testAntPatchMatherFilter() throws Exception {
- result.expectedBodiesReceived(expectedBody);
+ public void testFtpEndpointAsSpringBean() throws Exception {
+ result.expectedBodiesReceived("Hello World");
template.sendBodyAndHeader(inputFTP, "Hello World",
FileComponent.HEADER_FILE_NAME, "hello.txt");
- template.sendBodyAndHeader(inputFTP, "Bye World",
FileComponent.HEADER_FILE_NAME, "bye.xml");
- template.sendBodyAndHeader(inputFTP, "Bad world",
FileComponent.HEADER_FILE_NAME, "subfolder/badday.txt");
- template.sendBodyAndHeader(inputFTP, "Day world",
FileComponent.HEADER_FILE_NAME, "day.xml");
- template.sendBodyAndHeader(inputFTP, expectedBody,
FileComponent.HEADER_FILE_NAME, "subfolder/foo/godday.txt");
result.assertIsSatisfied();
}
@@ -80,8 +75,7 @@
uman.configure();
ftpServer.setUserManager(uman);
- ftpServer.getListener("default").setPort(20123);
+ ftpServer.getListener("default").setPort(20124);
}
-}
-
+}
\ No newline at end of file
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/ftp/SpringFtpEndpointTest.java
------------------------------------------------------------------------------
svn:mergeinfo =
Copied:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
(from r736562,
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml)
URL:
http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml?p2=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml&p1=camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml&r1=736562&r2=736583&rev=736583&view=diff
==============================================================================
---
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFileAntPathMatcherRemoteFileFilterTest-context.xml
(original)
+++
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
Wed Jan 21 23:56:56 2009
@@ -22,26 +22,28 @@
http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd
">
+ <bean id="myFTPEndpoint"
class="org.apache.camel.component.file.remote.RemoteFileEndpoint">
+ <property name="camelContext" ref="camel"/>
+ <property name="configuration" ref="ftpConfig"/>
+ </bean>
+
+ <bean id="ftpConfig"
class="org.apache.camel.component.file.remote.RemoteFileConfiguration">
+ <property name="host" value="localhost"/>
+ <property name="port" value="20124"/>
+ <property name="username" value="admin"/>
+ <property name="password" value="admin"/>
+ <property name="protocol" value="ftp"/>
+ <property name="file" value="helloftp"/>
+ </bean>
+
<!-- START SNIPPET: example -->
- <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+ <camelContext id="camel"
xmlns="http://activemq.apache.org/camel/schema/spring">
<template id="camelTemplate"/>
- <!-- use myFilter as filter to allow setting ANT paths for which files
to scan for -->
- <endpoint id="myFTPEndpoint"
uri="ftp://ad...@localhost:20123/antpath?password=admin&recursive=true&delay=10000&initialDelay=2000&filter=#myAntFilter"/>
-
<route>
<from ref="myFTPEndpoint"/>
<to uri="mock:result"/>
</route>
</camelContext>
- <!-- we use the AntPathMatcherRemoteFileFilter to use ant paths for
includes and exlucde -->
- <bean id="myAntFilter"
class="org.apache.camel.component.file.remote.AntPathMatcherRemoteFileFilter">
- <!-- include and file in the subfolder that has day in the name -->
- <property name="includes" value="**/subfolder/**/*day*"/>
- <!-- exclude all files with bad in name or .xml files. Use comma to
seperate multiple excludes -->
- <property name="excludes" value="**/*bad*,**/*.xml"/>
- </bean>
- <!-- END SNIPPET: example -->
-
</beans>
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:keywords = Rev Date
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:mergeinfo =
Propchange:
camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/ftp/SpringFtpEndpointTest-context.xml
------------------------------------------------------------------------------
svn:mime-type = text/xml