[ 
https://issues.apache.org/jira/browse/CAMEL-12380?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16635071#comment-16635071
 ] 

ASF GitHub Bot commented on CAMEL-12380:
----------------------------------------

oscerd closed pull request #2542: CAMEL-12380 - Thanks to Laurent Chiarello for 
reporting and providing…
URL: https://github.com/apache/camel/pull/2542
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
index 196dfc258fe..e90ab2c497d 100644
--- 
a/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
+++ 
b/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
@@ -128,6 +128,14 @@ protected boolean doConnect(RemoteFileConfiguration 
configuration) throws Generi
                     throw new 
GenericFileOperationFailedException(client.getReplyCode(), 
client.getReplyString(), "Server refused connection");
                 }
             } catch (Exception e) {
+                if (client.isConnected()) {
+                    log.trace("Disconnecting due to exception during connect");
+                    try {
+                        client.disconnect(); // ensures socket is closed
+                    } catch (IOException ignore) {
+                        log.trace("Ignore exception during disconnect: {}", 
ignore.getMessage());
+                    }
+                }
                 // check if we are interrupted so we can break out
                 if (Thread.currentThread().isInterrupted()) {
                     throw new GenericFileOperationFailedException("Interrupted 
during connecting", new InterruptedException("Interrupted during connecting"));
diff --git 
a/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java
 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java
new file mode 100644
index 00000000000..d6313be747c
--- /dev/null
+++ 
b/components/camel-ftp/src/test/java/org/apache/camel/component/file/remote/FtpSoTimeoutTest.java
@@ -0,0 +1,108 @@
+/**
+ * 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 java.net.ServerSocket;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.impl.JndiRegistry;
+import org.apache.camel.test.junit4.CamelTestSupport;
+import org.apache.commons.net.ftp.FTPClient;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+/**
+ * Test class used to demonstrate the problematic disconnect sequence of the 
{@link FtpOperations}.
+ * <p>
+ * Setting the logging level of {@code org.apache.camel.file.remote} to {@code 
TRACE} will provide useful information
+ * 
+ * @author l.chiarello
+ *
+ */
+public class FtpSoTimeoutTest extends CamelTestSupport {
+
+    private ServerSocket serverSocket;
+
+    // --- Set up
+    
+    @Override
+    @Before
+    public void setUp() throws Exception {
+        // the created server socket makes it possible for the FTP client to 
establish the socket connection.
+        // However, no message will ever be sent back, thus a read timeout 
should occur within FTPClient#__getReply()
+        serverSocket = new ServerSocket(0);
+        super.setUp();
+    }
+
+    @Override
+    @After
+    public void tearDown() throws Exception {
+        super.tearDown();
+        if (serverSocket != null) {
+            serverSocket.close();
+        }
+    }
+    
+    @Override
+    protected int getShutdownTimeout() {
+        return 5; // speedup graceful shutdown
+    }
+    
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:with")
+                    .to("ftp://localhost:"; + serverSocket.getLocalPort()
+                        + 
"?ftpClient=#myftpclient&connectTimeout=300&soTimeout=300&reconnectDelay=100");
+                
+                from("direct:without")
+                    .to("ftp://localhost:"; + serverSocket.getLocalPort()
+                        + 
"?connectTimeout=300&soTimeout=300&reconnectDelay=100");
+            }
+        };
+    }
+
+    @Override
+    protected JndiRegistry createRegistry() throws Exception {
+        FTPClient ftpClient = new FTPClient();
+        ftpClient.setDefaultTimeout(300);
+        JndiRegistry registry = super.createRegistry();
+        registry.bind("myftpclient", ftpClient);
+        return registry;
+    }
+    
+    // --- Tests
+    
+    @Test(timeout = 10000, expected = CamelExecutionException.class)
+    public void testWithDefaultTimeout() throws Exception {
+        // send exchange to the route using the custom FTPClient (with a 
default timeout)
+        // the soTimeout triggers in time and test is successful
+        template.sendBody("direct:with", "");
+    }
+    
+    @Test(timeout = 10000, expected = CamelExecutionException.class)
+    public void testWithoutDefaultTimeout() throws Exception {
+        // send exchange to the route using the default FTPClient (without a 
default timeout)
+        // the soTimeout never triggers and test fails after its own timeout
+        template.sendBody("direct:without", "");
+    }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


> Spring Boot 2 - Remove dependency on code ported from 1.5.x
> -----------------------------------------------------------
>
>                 Key: CAMEL-12380
>                 URL: https://issues.apache.org/jira/browse/CAMEL-12380
>             Project: Camel
>          Issue Type: Sub-task
>            Reporter: Nicola Ferraro
>            Assignee: Nicola Ferraro
>            Priority: Minor
>
> Looks like some code ported from 1.5.x was necessary to support compatibility 
> of both spring-boot 1 and spring-boot 2, but we can rely on v2-only code now.
>  
> E.g. RelaxedPropertyResolver is not necessary if using [canonical 
> properties|https://github.com/spring-projects/spring-boot/wiki/Canonical-properties#spring-boot-20-canonical-properties].
>  
> Others classes currently forward-ported:
> - PropertySourceUtils
> - RelaxedNames



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to