Skip to content

Commit b64e379

Browse files
GregBraggartembilan
authored andcommitted
Add documentation for SMB Support
* Updated, polished documentation prior to PR review * Updated after PR review comments, changed Adapter verbiage to Support * Add `SmbMessageHandler(SmbRemoteFileTemplate)` ctors * Clean up `smb.adoc` for extra redundant interim headlines
1 parent 18e410a commit b64e379

File tree

6 files changed

+177
-13
lines changed

6 files changed

+177
-13
lines changed

spring-integration-smb/src/main/java/org/springframework/integration/smb/outbound/SmbMessageHandler.java

+18-13
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,31 @@
2222
import org.springframework.integration.smb.session.SmbRemoteFileTemplate;
2323

2424
import jcifs.smb.SmbFile;
25+
import reactor.core.publisher.Mono;
2526

2627
/**
27-
* The SMB specific {@link FileTransferringMessageHandler} extension. Based on the
28-
* {@link SmbRemoteFileTemplate}.
29-
*
30-
* @author Gregory Bragg
31-
* @author Artem Bilan
32-
*
33-
* @since 6.0
34-
*
35-
* @see SmbRemoteFileTemplate
36-
*/
28+
* The SMB specific {@link FileTransferringMessageHandler} extension. Based on the
29+
* {@link SmbRemoteFileTemplate}.
30+
*
31+
* @author Gregory Bragg
32+
* @author Artem Bilan
33+
*
34+
* @since 6.0
35+
*
36+
* @see SmbRemoteFileTemplate
37+
*/
3738
public class SmbMessageHandler extends FileTransferringMessageHandler<SmbFile> {
3839

3940
public SmbMessageHandler(SessionFactory<SmbFile> sessionFactory) {
40-
this(sessionFactory, FileExistsMode.REPLACE);
41+
this(new SmbRemoteFileTemplate(sessionFactory));
42+
}
43+
44+
public SmbMessageHandler(SmbRemoteFileTemplate remoteFileTemplate) {
45+
super(remoteFileTemplate);
4146
}
4247

43-
public SmbMessageHandler(SessionFactory<SmbFile> sessionFactory, FileExistsMode mode) {
44-
super(new SmbRemoteFileTemplate(sessionFactory), mode);
48+
public SmbMessageHandler(SmbRemoteFileTemplate remoteFileTemplate, FileExistsMode mode) {
49+
super(remoteFileTemplate, mode);
4550
}
4651

4752
}

src/reference/asciidoc/endpoint-summary.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,12 @@ The following table summarizes the various endpoints with quick links to the app
174174
| N
175175
| <<./sftp.adoc#sftp-outbound-gateway,SFTP Outbound Gateway>>
176176

177+
| *SMB*
178+
| <<./smb.adoc#smb-inbound,SMB Inbound Channel Adapter>>
179+
| <<./smb.adoc#smb-outbound,SMB Outbound Channel Adapter>>
180+
| N
181+
| N
182+
177183
| *STOMP*
178184
| <<./stomp.adoc#stomp-inbound-adapter,STOMP Inbound Channel Adapter>>
179185
| <<./stomp.adoc#stomp-outbound-adapter,STOMP Outbound Channel Adapter>>

src/reference/asciidoc/index-single.adoc

+2
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ include::./rsocket.adoc[]
7171

7272
include::./sftp.adoc[]
7373

74+
include::./smb.adoc[]
75+
7476
include::./stomp.adoc[]
7577

7678
include::./stream.adoc[]

src/reference/asciidoc/index.adoc

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ This documentation is also available as single searchable link:index-single.html
4545
<<./resource.adoc#resource,Resource Support>> ::
4646
<<./rsocket.adoc#rsocket,RSocket Support>> ::
4747
<<./sftp.adoc#sftp,SFTP Adapters>> ::
48+
<<./smb.adoc#smb,SMB Support>> ::
4849
<<./stomp.adoc#stomp,STOMP Support>> ::
4950
<<./stream.adoc#stream,Stream Support>> ::
5051
<<./syslog.adoc#syslog,Syslog Support>> ::

src/reference/asciidoc/smb.adoc

+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
[[smb]]
2+
== SMB Support
3+
4+
Spring Integration provides support for file transfer operations with SMB.
5+
6+
The https://en.wikipedia.org/wiki/Server_Message_Block[Server Message Block] (SMB) is a simple network protocol that lets you transfer files to a shared file server.
7+
8+
You need to include this dependency into your project:
9+
10+
====
11+
[source, xml, subs="normal", role="primary"]
12+
.Maven
13+
----
14+
<dependency>
15+
<groupId>org.springframework.integration</groupId>
16+
<artifactId>spring-integration-smb</artifactId>
17+
<version>{project-version}</version>
18+
</dependency>
19+
----
20+
[source, groovy, subs="normal", role="secondary"]
21+
.Gradle
22+
----
23+
compile "org.springframework.integration:spring-integration-smb:{project-version}"
24+
----
25+
====
26+
27+
=== Overview
28+
29+
The https://github.com/codelibs/jcifs[Java CIFS] Client Library has been chosen as a Java implementation for the CIFS/SMB networking protocol.
30+
Its `SmbFile` abstraction is simply wrapped to the Spring Integration "Remote File" foundations like `SmbSession`, `SmbRemoteFileTemplate`, etc.
31+
32+
The SMB Channel Adapters and support classes implementations are fully similar to existing components for (S)FTP or AWS S3 protocols.
33+
So, if you familiar with those components it is pretty straightforward to use.
34+
35+
[[smb-session-factory]]
36+
=== SMB Session Factory
37+
38+
Before configuring the SMB adapter, you must configure an SMB session factory.
39+
You can configure the SMB session factory with a regular bean definition, as the following examples show:
40+
41+
The `SmbSessionFactory` exposes options to set the SMB protocol with Min/Max versions.
42+
For example, supporting a minimum version of SMB 2.1 and a maximum version of the SMB 3.1.1:
43+
44+
[source,java]
45+
----
46+
@Bean
47+
public SmbSessionFactory smbSessionFactory() {
48+
SmbSessionFactory smbSession = new SmbSessionFactory();
49+
smbSession.setHost("myHost");
50+
smbSession.setPort(445);
51+
smbSession.setDomain("myDomain");
52+
smbSession.setUsername("myUser");
53+
smbSession.setPassword("myPassword");
54+
smbSession.setShareAndDir("myShareAndDir");
55+
smbSession.setSmbMinVersion(DialectVersion.SMB210);
56+
smbSession.setSmbMaxVersion(DialectVersion.SMB311);
57+
return smbSession;
58+
}
59+
----
60+
61+
The `SmbSessionFactory` can be initialized with a custom `jcifs.CIFSContext`.
62+
63+
NOTE: Setting of the SMB protocol Min/Max versions must be done in your implementation of `jcifs.CIFSContext`.
64+
65+
[source,java]
66+
----
67+
@Bean
68+
public SmbSessionFactory smbSessionFactory() {
69+
SmbSessionFactory smbSession = new SmbSessionFactory(new MyCIFSContext());
70+
smbSession.setHost("myHost");
71+
smbSession.setPort(445);
72+
smbSession.setDomain("myDomain");
73+
smbSession.setUsername("myUser");
74+
smbSession.setPassword("myPassword");
75+
smbSession.setShareAndDir("myShareAndDir");
76+
return smbSession;
77+
}
78+
----
79+
80+
[[smb-inbound]]
81+
=== SMB Inbound Channel Adapter
82+
83+
To download SMB files locally the `SmbInboundFileSynchronizingMessageSource` is provided.
84+
It is simple extension of the `AbstractInboundFileSynchronizingMessageSource` which requires `SmbInboundFileSynchronizer` injection.
85+
For filtering remote files you still can use any existing `FileListFilter` implementations, but particular `SmbRegexPatternFileListFilter` and `SmbSimplePatternFileListFilter` are provided.
86+
87+
[source,java]
88+
----
89+
@Bean
90+
public SmbInboundFileSynchronizer smbInboundFileSynchronizer() {
91+
SmbInboundFileSynchronizer fileSynchronizer =
92+
new SmbInboundFileSynchronizer(smbSessionFactory());
93+
fileSynchronizer.setFilter(compositeFileListFilter());
94+
fileSynchronizer.setRemoteDirectory("mySharedDirectoryPath");
95+
fileSynchronizer.setDeleteRemoteFiles(true);
96+
return fileSynchronizer;
97+
}
98+
99+
@Bean
100+
public CompositeFileListFilter<SmbFile> compositeFileListFilter() {
101+
CompositeFileListFilter<SmbFile> filters = new CompositeFileListFilter<>();
102+
filters.addFilter(new SmbRegexPatternFileListFilter("^(?i).+((\\.txt))$"));
103+
return filters;
104+
}
105+
106+
@Bean
107+
public MessageChannel smbFileInputChannel() {
108+
return new DirectChannel();
109+
}
110+
111+
@Bean
112+
@InboundChannelAdapter(value = "smbFileInputChannel",
113+
poller = @Poller(fixedDelay = "2000"))
114+
public MessageSource<File> smbMessageSource() {
115+
SmbInboundFileSynchronizingMessageSource messageSource =
116+
new SmbInboundFileSynchronizingMessageSource(smbInboundFileSynchronizer());
117+
messageSource.setLocalDirectory(new File("myLocalDirectoryPath"));
118+
messageSource.setAutoCreateLocalDirectory(true);
119+
return messageSource;
120+
}
121+
----
122+
123+
For XML configuration the `<int-smb:inbound-channel-adapter>` component is provided.
124+
125+
[[smb-outbound]]
126+
=== SMB Outbound Channel Adapter
127+
128+
For writing files to an SMB share, and for XML `<int-smb:outbound-channel-adapter>` component we use the `SmbMessageHandler`.
129+
In case of Java configuration a `SmbMessageHandler` should be supplied with the `SmbSessionFactory` (or `SmbRemoteFileTemplate`).
130+
131+
[source,java]
132+
----
133+
@Bean
134+
@ServiceActivator(inputChannel = "storeToSmbShare")
135+
public MessageHandler smbMessageHandler(SmbSessionFactory smbSessionFactory) {
136+
SmbMessageHandler handler = new SmbMessageHandler(smbSessionFactory);
137+
handler.setRemoteDirectoryExpression(
138+
new LiteralExpression("remote-target-dir"));
139+
handler.setFileNameGenerator(m ->
140+
m.getHeaders().get(FileHeaders.FILENAME, String.class) + ".test");
141+
handler.setAutoCreateDirectory(true);
142+
return handler;
143+
}
144+
----

src/reference/asciidoc/whats-new.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ In general the project has been moved to Java 17 baseline and migrated from Java
2323
The GraphQL support has been added.
2424
See <<./graphql.adoc#graphql,GraphQL Support>> for more information.
2525

26+
[[x6.0-smb]]
27+
=== SMB Support
28+
29+
SMB support has been added from the Spring Integration Extensions project.
30+
See <<./smb.adoc#smb,SMB Support>> for more information.
31+
2632
[[x6.0-general]]
2733
=== General Changes
2834

0 commit comments

Comments
 (0)