Author: davsclaus
Date: Wed Apr 24 09:42:09 2013
New Revision: 1471330
URL: http://svn.apache.org/r1471330
Log:
CAMEL-6293: Ftp/ftps consumer and producer adds headers with ftp client reply
code/string when downloading or uploading a file.
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConstants.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerReplyStringTest.java
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerReplyStringTest.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Added:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConstants.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConstants.java?rev=1471330&view=auto
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConstants.java
(added)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpConstants.java
Wed Apr 24 09:42:09 2013
@@ -0,0 +1,29 @@
+/**
+ * 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;
+
+/**
+ * Constants
+ */
+public final class FtpConstants {
+
+ public static final String FTP_REPLY_CODE = "CamelFtpReplyCode";
+ public static final String FTP_REPLY_STRING = "CamelFtpReplyString";
+
+ private FtpConstants() {
+ }
+}
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=1471330&r1=1471329&r2=1471330&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Wed Apr 24 09:42:09 2013
@@ -352,6 +352,10 @@ public class FtpOperations implements Re
result = client.retrieveFile(remoteName, os);
}
+ // store client reply information after the operation
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE,
client.getReplyCode());
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING,
client.getReplyString());
+
// change back to current directory
if (endpoint.getConfiguration().isStepwise()) {
changeCurrentDirectory(currentDir);
@@ -435,6 +439,10 @@ public class FtpOperations implements Re
log.trace("Client retrieveFile: {}", remoteName);
result = client.retrieveFile(remoteName, os);
+ // store client reply information after the operation
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE,
client.getReplyCode());
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING,
client.getReplyString());
+
// change back to current directory
if (endpoint.getConfiguration().isStepwise()) {
changeCurrentDirectory(currentDir);
@@ -567,6 +575,10 @@ public class FtpOperations implements Re
new Object[]{TimeUtils.printDuration(watch.taken()),
watch.taken(), targetName, answer});
}
+ // store client reply information after the operation
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_CODE,
client.getReplyCode());
+ exchange.getIn().setHeader(FtpConstants.FTP_REPLY_STRING,
client.getReplyString());
+
return answer;
} catch (IOException e) {
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerReplyStringTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerReplyStringTest.java?rev=1471330&view=auto
==============================================================================
---
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerReplyStringTest.java
(added)
+++
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpConsumerReplyStringTest.java
Wed Apr 24 09:42:09 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class FtpConsumerReplyStringTest extends FtpServerTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/reply?password=admin";
+ }
+
+ @Test
+ public void testReplyCodeAndString() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye World");
+ mock.expectedHeaderReceived(FtpConstants.FTP_REPLY_CODE, 226);
+ mock.expectedHeaderReceived(FtpConstants.FTP_REPLY_STRING, "226
Transfer complete.\r\n");
+
+ template.requestBodyAndHeader(getFtpUrl(), "Bye World",
Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from(getFtpUrl()).to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file
Added:
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerReplyStringTest.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerReplyStringTest.java?rev=1471330&view=auto
==============================================================================
---
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerReplyStringTest.java
(added)
+++
camel/trunk/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpProducerReplyStringTest.java
Wed Apr 24 09:42:09 2013
@@ -0,0 +1,52 @@
+/**
+ * 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.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.junit.Test;
+
+public class FtpProducerReplyStringTest extends FtpServerTestSupport {
+
+ private String getFtpUrl() {
+ return "ftp://admin@localhost:" + getPort() + "/reply?password=admin";
+ }
+
+ @Test
+ public void testReplyCodeAndString() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:result");
+ mock.expectedBodiesReceived("Bye World");
+ mock.expectedHeaderReceived(FtpConstants.FTP_REPLY_CODE, 226);
+ mock.expectedHeaderReceived(FtpConstants.FTP_REPLY_STRING, "226
Transfer complete.\r\n");
+
+ template.requestBodyAndHeader("direct:start", "Bye World",
Exchange.FILE_NAME, "hello.txt");
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("direct:start").to(getFtpUrl()).to("mock:result");
+ }
+ };
+ }
+
+}
\ No newline at end of file