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 2025/06/19 05:13:59 UTC
(camel) branch camel-4.10.x updated: CAMEL-22174 Catch TransportExceptions and disconnect share calls so we can recover from network outage (#18387) (#18399)
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-4.10.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-4.10.x by this push:
new feaa958265d CAMEL-22174 Catch TransportExceptions and disconnect share calls so we can recover from network outage (#18387) (#18399)
feaa958265d is described below
commit feaa958265d389ded78b3c5d8d4fa379ef5301bc
Author: Tom Cunningham <tc...@redhat.com>
AuthorDate: Thu Jun 19 01:13:53 2025 -0400
CAMEL-22174 Catch TransportExceptions and disconnect share calls so we can recover from network outage (#18387) (#18399)
---
.../apache/camel/component/smb/SmbOperations.java | 74 +++++++++++++++++++---
1 file changed, 66 insertions(+), 8 deletions(-)
diff --git a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java
index 333d28b0092..b7e40c1da09 100644
--- a/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java
+++ b/components/camel-smb/src/main/java/org/apache/camel/component/smb/SmbOperations.java
@@ -28,8 +28,10 @@ import com.hierynomus.msfscc.fileinformation.FileIdBothDirectoryInformation;
import com.hierynomus.mssmb2.SMB2CreateDisposition;
import com.hierynomus.mssmb2.SMB2CreateOptions;
import com.hierynomus.mssmb2.SMB2ShareAccess;
+import com.hierynomus.protocol.transport.TransportException;
import com.hierynomus.smbj.SMBClient;
import com.hierynomus.smbj.auth.AuthenticationContext;
+import com.hierynomus.smbj.common.SMBRuntimeException;
import com.hierynomus.smbj.connection.Connection;
import com.hierynomus.smbj.session.Session;
import com.hierynomus.smbj.share.DiskShare;
@@ -126,6 +128,12 @@ public class SmbOperations implements SmbFileOperations {
if (session != null) {
try {
session.close();
+ } catch (TransportException t) {
+ try {
+ session.getConnection().close(true);
+ } catch (IOException e) {
+ // ignore
+ }
} catch (Exception e) {
// ignore
}
@@ -189,6 +197,11 @@ public class SmbOperations implements SmbFileOperations {
}
src.deleteOnClose();
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
}
return true;
}
@@ -197,7 +210,15 @@ public class SmbOperations implements SmbFileOperations {
public boolean buildDirectory(String directory, boolean absolute) throws GenericFileOperationFailedException {
connectIfNecessary();
SmbFiles files = new SmbFiles();
- files.mkdirs(share, normalize(directory));
+
+ try {
+ files.mkdirs(share, normalize(directory));
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
+ }
return true;
}
@@ -215,7 +236,16 @@ public class SmbOperations implements SmbFileOperations {
public boolean existsFolder(String name) {
connectIfNecessary();
- return share.folderExists(name);
+ boolean result = false;
+ try {
+ result = share.folderExists(name);
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
+ }
+ return result;
}
private boolean retrieveFileToStreamInBody(String name, Exchange exchange) throws GenericFileOperationFailedException {
@@ -242,6 +272,11 @@ public class SmbOperations implements SmbFileOperations {
}
exchange.getIn().setHeader(SmbConstants.SMB_UNC_PATH, shareFile.getUncPath());
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
}
return true;
}
@@ -490,7 +525,16 @@ public class SmbOperations implements SmbFileOperations {
public FileIdBothDirectoryInformation[] listFiles(String path, String searchPattern)
throws GenericFileOperationFailedException {
connectIfNecessary();
- return share.list(path, searchPattern).toArray(FileIdBothDirectoryInformation[]::new);
+ FileIdBothDirectoryInformation[] result = null;
+ try {
+ result = share.list(path, searchPattern).toArray(FileIdBothDirectoryInformation[]::new);
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
+ }
+ return result;
}
public byte[] getBody(String path) {
@@ -503,16 +547,30 @@ public class SmbOperations implements SmbFileOperations {
} catch (Exception e) {
throw new GenericFileOperationFailedException(e.getMessage(), e);
}
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
}
+ return null;
}
public InputStream getBodyAsInputStream(Exchange exchange, String path) {
connectIfNecessary();
- File shareFile = share.openFile(path, EnumSet.of(AccessMask.GENERIC_READ), null,
- SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN, null);
- InputStream is = shareFile.getInputStream();
- exchange.getIn().setHeader(SmbComponent.SMB_FILE_INPUT_STREAM, is);
- exchange.getIn().setHeader(SmbConstants.SMB_UNC_PATH, shareFile.getUncPath());
+ InputStream is = null;
+ try {
+ File shareFile = share.openFile(path, EnumSet.of(AccessMask.GENERIC_READ), null,
+ SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OPEN, null);
+ is = shareFile.getInputStream();
+ exchange.getIn().setHeader(SmbComponent.SMB_FILE_INPUT_STREAM, is);
+ exchange.getIn().setHeader(SmbConstants.SMB_UNC_PATH, shareFile.getUncPath());
+ } catch (SMBRuntimeException smbre) {
+ if (smbre.getCause() instanceof TransportException) {
+ disconnect();
+ throw smbre;
+ }
+ }
return is;
}