This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch fix/CAMEL-24121 in repository https://gitbox.apache.org/repos/asf/camel.git
commit 068c5f50deef3eecdd741bb6314f724e4cc59199 Author: Claus Ibsen <[email protected]> AuthorDate: Thu Jul 16 13:25:48 2026 +0200 CAMEL-24121: camel-smb - Add connectIfNecessary to existsFile and storeFileDirectly Co-Authored-By: Claude Opus 4.6 <[email protected]> Signed-off-by: Claus Ibsen <[email protected]> --- .../apache/camel/component/smb/SmbOperations.java | 9 ++++- .../component/smb/SmbProducerTempPrefixIT.java | 42 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) 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 b0c302133952..f3126e084762 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 @@ -201,7 +201,13 @@ public class SmbOperations implements SmbFileOperations { @Override public boolean existsFile(String name) throws GenericFileOperationFailedException { - return share.fileExists(name); + connectIfNecessary(); + try { + return share.fileExists(name); + } catch (SMBRuntimeException smbre) { + safeDisconnect(smbre); + throw smbre; + } } @Override @@ -526,6 +532,7 @@ public class SmbOperations implements SmbFileOperations { @Override public boolean storeFileDirectly(String name, String payload) throws GenericFileOperationFailedException { + connectIfNecessary(); ByteArrayInputStream bis = new ByteArrayInputStream(payload.getBytes()); try { try (File shareFile = share.openFile(name, EnumSet.of(AccessMask.FILE_WRITE_DATA), diff --git a/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbProducerTempPrefixIT.java b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbProducerTempPrefixIT.java new file mode 100644 index 000000000000..248c20a95e3b --- /dev/null +++ b/components/camel-smb/src/test/java/org/apache/camel/component/smb/SmbProducerTempPrefixIT.java @@ -0,0 +1,42 @@ +/* + * 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.smb; + +import java.util.concurrent.TimeUnit; + +import org.junit.jupiter.api.Test; + +import static org.awaitility.Awaitility.await; +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class SmbProducerTempPrefixIT extends SmbServerTestSupport { + + protected String getSmbUrl() { + return String.format( + "smb:%s/%s?username=%s&password=%s&tempPrefix=.uploading", + service.address(), service.shareName(), service.userName(), service.password()); + } + + @Test + public void testProduceTempPrefix() { + sendFile(getSmbUrl(), "Hello World", "tempprefix.txt"); + + await().atMost(15, TimeUnit.SECONDS) + .untilAsserted(() -> assertEquals("Hello World", + new String(copyFileContentFromContainer("/data/rw/tempprefix.txt")))); + } +}
