This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/main by this push:
     new 65404a6b347 CAMEL-21266: camel-smb - Use init for creating client
65404a6b347 is described below

commit 65404a6b347acfc8f2f814f0652436d66192a543
Author: Claus Ibsen <[email protected]>
AuthorDate: Thu Dec 19 09:49:50 2024 +0100

    CAMEL-21266: camel-smb - Use init for creating client
---
 .../apache/camel/component/smb/SmbConsumer.java    | 29 ++++++++++++----------
 1 file changed, 16 insertions(+), 13 deletions(-)

diff --git 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConsumer.java
 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConsumer.java
index 309e28b9fa5..47c6a16fca7 100644
--- 
a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConsumer.java
+++ 
b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbConsumer.java
@@ -35,21 +35,14 @@ public class SmbConsumer extends ScheduledPollConsumer {
     private final SmbEndpoint endpoint;
     private final SmbConfiguration configuration;
 
-    private final SMBClient smbClient;
+    private SMBClient smbClient;
     private Connection connection;
-    private Session session;
     private DiskShare share;
 
     public SmbConsumer(SmbEndpoint endpoint, Processor processor) {
         super(endpoint, processor);
         this.endpoint = endpoint;
         this.configuration = endpoint.getConfiguration();
-
-        if (this.configuration.getSmbConfig() != null) {
-            smbClient = new SMBClient(this.configuration.getSmbConfig());
-        } else {
-            smbClient = new SMBClient();
-        }
     }
 
     private int pollDirectory(DiskShare share, SmbConfiguration configuration, 
int polledCount, String path) throws Exception {
@@ -65,13 +58,13 @@ public class SmbConsumer extends ScheduledPollConsumer {
             }
 
             String fullFilePath = "";
-            if (!"".equals(path)) {
-                fullFilePath = new String(path + java.io.File.separator + 
f.getFileName());
+            if (!path.isEmpty()) {
+                fullFilePath = path + java.io.File.separator + f.getFileName();
             }
 
             if (share.folderExists(fullFilePath)) {
                 if (configuration.isRecursive()) {
-                    polledCount = pollDirectory(share, configuration, 
polledCount, new String(fullFilePath));
+                    polledCount = pollDirectory(share, configuration, 
polledCount, fullFilePath);
                 }
                 continue;
             }
@@ -128,16 +121,25 @@ public class SmbConsumer extends ScheduledPollConsumer {
         AuthenticationContext ac = new AuthenticationContext(
                 configuration.getUsername(), 
configuration.getPassword().toCharArray(),
                 configuration.getDomain());
-        session = connection.authenticate(ac);
+        Session session = connection.authenticate(ac);
 
         // Connect to the share
         share = (DiskShare) session.connectShare(endpoint.getShareName());
     }
 
+    @Override
+    protected void doInit() throws Exception {
+        super.doInit();
+        if (this.configuration.getSmbConfig() != null) {
+            smbClient = new SMBClient(this.configuration.getSmbConfig());
+        } else {
+            smbClient = new SMBClient();
+        }
+    }
+
     @Override
     protected void doStart() throws Exception {
         super.doStart();
-
         refreshConnection();
     }
 
@@ -145,6 +147,7 @@ public class SmbConsumer extends ScheduledPollConsumer {
     protected void doStop() throws Exception {
         if (connection != null) {
             IOHelper.close(connection);
+            connection = null;
         }
 
         super.doStop();

Reply via email to