This is an automated email from the ASF dual-hosted git repository.
asf-gitbox-commits pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/nifi.git
The following commit(s) were added to refs/heads/main by this push:
new bbaddda97f9 NIFI-15977 Configurable port in PutSmbFile
bbaddda97f9 is described below
commit bbaddda97f9a345ee5219f1894bf98416149a589
Author: Kuba Bogusz <[email protected]>
AuthorDate: Wed May 27 13:26:06 2026 +0200
NIFI-15977 Configurable port in PutSmbFile
This closes #11285.
Signed-off-by: Peter Turcsanyi <[email protected]>
---
.../org/apache/nifi/processors/smb/PutSmbFile.java | 11 ++++++++++-
.../apache/nifi/processors/smb/PutSmbFileTest.java | 22 ++++++++++++++++++++--
2 files changed, 30 insertions(+), 3 deletions(-)
diff --git
a/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/main/java/org/apache/nifi/processors/smb/PutSmbFile.java
b/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/main/java/org/apache/nifi/processors/smb/PutSmbFile.java
index 197fb93fc19..b1ea0e1b547 100644
---
a/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/main/java/org/apache/nifi/processors/smb/PutSmbFile.java
+++
b/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/main/java/org/apache/nifi/processors/smb/PutSmbFile.java
@@ -97,6 +97,13 @@ public class PutSmbFile extends AbstractProcessor {
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES)
.build();
+ public static final PropertyDescriptor PORT = new
PropertyDescriptor.Builder()
+ .name("Port")
+ .description("The port to use for the SMB connection.")
+ .required(true)
+ .addValidator(StandardValidators.PORT_VALIDATOR)
+ .defaultValue("445")
+ .build();
public static final PropertyDescriptor SHARE = new
PropertyDescriptor.Builder()
.name("Share")
.description("The network share to which files should be written.
This is the \"first folder\"" +
@@ -179,6 +186,7 @@ public class PutSmbFile extends AbstractProcessor {
private static final List<PropertyDescriptor> PROPERTY_DESCRIPTORS =
List.of(
HOSTNAME,
+ PORT,
SHARE,
DIRECTORY,
DOMAIN,
@@ -297,6 +305,7 @@ public class PutSmbFile extends AbstractProcessor {
final String hostname = flowFileFilter.getHostName();
final String shareName = flowFileFilter.getShare();
+ final int port = context.getProperty(PORT).asInteger();
final String domain = context.getProperty(DOMAIN).getValue();
final String username = context.getProperty(USERNAME).getValue();
String password = context.getProperty(PASSWORD).getValue();
@@ -311,7 +320,7 @@ public class PutSmbFile extends AbstractProcessor {
ac = AuthenticationContext.anonymous();
}
- try (Connection connection = smbClient.connect(hostname);
+ try (Connection connection = smbClient.connect(hostname, port);
Session smbSession = connection.authenticate(ac);
DiskShare share = (DiskShare) smbSession.connectShare(shareName)) {
diff --git
a/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/test/java/org/apache/nifi/processors/smb/PutSmbFileTest.java
b/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/test/java/org/apache/nifi/processors/smb/PutSmbFileTest.java
index d6625614e85..d73eacbfa44 100644
---
a/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/test/java/org/apache/nifi/processors/smb/PutSmbFileTest.java
+++
b/nifi-extension-bundles/nifi-smb-bundle/nifi-smb-processors/src/test/java/org/apache/nifi/processors/smb/PutSmbFileTest.java
@@ -50,6 +50,7 @@ import java.util.concurrent.atomic.AtomicInteger;
import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anySet;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.doThrow;
@@ -96,7 +97,7 @@ public class PutSmbFileTest {
serverList = mock(ServerList.class);
baOutputStream = new ByteArrayOutputStream();
- when(smbClient.connect(any(String.class))).thenReturn(connection);
+ when(smbClient.connect(any(String.class),
anyInt())).thenReturn(connection);
when(smbClient.getServerList()).thenReturn(serverList);
when(connection.authenticate(any(AuthenticationContext.class))).thenReturn(session);
@@ -242,6 +243,23 @@ public class PutSmbFileTest {
assertEquals(30, testRunner.getQueueSize().getObjectCount());
}
+ @Test
+ public void testDefaultPortIsUsed() throws IOException {
+ testRunner.enqueue("data");
+ testRunner.run();
+
+ verify(smbClient).connect(HOSTNAME, 445);
+ }
+
+ @Test
+ public void testCustomPortIsUsed() throws IOException {
+ testRunner.setProperty(PutSmbFile.PORT, "4445");
+ testRunner.enqueue("data");
+ testRunner.run();
+
+ verify(smbClient).connect(HOSTNAME, 4445);
+ }
+
@Test
public void testNormalAuth() throws IOException {
testRunner.enqueue("data");
@@ -431,7 +449,7 @@ public class PutSmbFileTest {
@Test
public void testConnectionError() throws IOException {
String emsg = "mock connection exception";
- when(smbClient.connect(any(String.class))).thenThrow(new
IOException(emsg));
+ when(smbClient.connect(any(String.class), anyInt())).thenThrow(new
IOException(emsg));
testRunner.enqueue("1");
testRunner.enqueue("2");