Skip to content

Commit ac6af71

Browse files
GregBraggartembilan
authored andcommitted
Add Java DSL for SMB module
* Added supporting classes for DSL, fixed checkstyle build errors * Added JUnit tests for DSL package * Updated Java Doc with instructions to setup an external SMB share * Updated AsciiDoc to include instructions on Java DSL configurations * Updated implementation based on PR review feedback * Clean up the code * Add more info to `whats-new.adoc` for these SMB changes
1 parent 1790f23 commit ac6af71

File tree

13 files changed

+1222
-1
lines changed

13 files changed

+1222
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.smb.dsl;
18+
19+
import java.io.File;
20+
import java.util.Comparator;
21+
22+
import org.springframework.integration.file.remote.MessageSessionCallback;
23+
import org.springframework.integration.file.remote.RemoteFileTemplate;
24+
import org.springframework.integration.file.remote.session.SessionFactory;
25+
import org.springframework.integration.file.support.FileExistsMode;
26+
import org.springframework.integration.smb.outbound.SmbOutboundGateway;
27+
import org.springframework.integration.smb.session.SmbRemoteFileTemplate;
28+
29+
import jcifs.smb.SmbFile;
30+
31+
/**
32+
* The factory for SMB components.
33+
*
34+
* @author Gregory Bragg
35+
*
36+
* @since 6.0
37+
*/
38+
public final class Smb {
39+
40+
/**
41+
* A {@link SmbInboundChannelAdapterSpec} factory for an inbound channel adapter spec.
42+
* @param sessionFactory the session factory.
43+
* @return the spec.
44+
*/
45+
public static SmbInboundChannelAdapterSpec inboundAdapter(SessionFactory<SmbFile> sessionFactory) {
46+
return inboundAdapter(sessionFactory, null);
47+
}
48+
49+
/**
50+
* A {@link SmbInboundChannelAdapterSpec} factory for an inbound channel adapter spec.
51+
* @param sessionFactory the session factory.
52+
* @param receptionOrderComparator the comparator.
53+
* @return the spec.
54+
*/
55+
public static SmbInboundChannelAdapterSpec inboundAdapter(SessionFactory<SmbFile> sessionFactory,
56+
Comparator<File> receptionOrderComparator) {
57+
58+
return new SmbInboundChannelAdapterSpec(sessionFactory, receptionOrderComparator);
59+
}
60+
61+
/**
62+
* A {@link SmbStreamingInboundChannelAdapterSpec} factory for an inbound channel
63+
* adapter spec.
64+
* @param remoteFileTemplate the remote file template.
65+
* @return the spec.
66+
*/
67+
public static SmbStreamingInboundChannelAdapterSpec inboundStreamingAdapter(
68+
RemoteFileTemplate<SmbFile> remoteFileTemplate) {
69+
70+
return inboundStreamingAdapter(remoteFileTemplate, null);
71+
}
72+
73+
/**
74+
* A {@link SmbStreamingInboundChannelAdapterSpec} factory for an inbound channel
75+
* adapter spec.
76+
* @param remoteFileTemplate the remote file template.
77+
* @param receptionOrderComparator the comparator.
78+
* @return the spec.
79+
*/
80+
public static SmbStreamingInboundChannelAdapterSpec inboundStreamingAdapter(
81+
RemoteFileTemplate<SmbFile> remoteFileTemplate,
82+
Comparator<SmbFile> receptionOrderComparator) {
83+
84+
return new SmbStreamingInboundChannelAdapterSpec(remoteFileTemplate, receptionOrderComparator);
85+
}
86+
87+
/**
88+
* A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec.
89+
* @param sessionFactory the session factory.
90+
* @return the spec.
91+
*/
92+
public static SmbMessageHandlerSpec outboundAdapter(SessionFactory<SmbFile> sessionFactory) {
93+
return new SmbMessageHandlerSpec(sessionFactory);
94+
}
95+
96+
/**
97+
* A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec.
98+
* @param sessionFactory the session factory.
99+
* @param fileExistsMode the file exists mode.
100+
* @return the spec.
101+
*/
102+
public static SmbMessageHandlerSpec outboundAdapter(SessionFactory<SmbFile> sessionFactory,
103+
FileExistsMode fileExistsMode) {
104+
105+
return outboundAdapter(new SmbRemoteFileTemplate(sessionFactory), fileExistsMode);
106+
}
107+
108+
/**
109+
* A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec.
110+
* @param smbRemoteFileTemplate the remote file template.
111+
* @return the spec.
112+
*/
113+
public static SmbMessageHandlerSpec outboundAdapter(SmbRemoteFileTemplate smbRemoteFileTemplate) {
114+
return new SmbMessageHandlerSpec(smbRemoteFileTemplate);
115+
}
116+
117+
/**
118+
* A {@link SmbMessageHandlerSpec} factory for an outbound channel adapter spec.
119+
* @param smbRemoteFileTemplate the remote file template.
120+
* @param fileExistsMode the file exists mode.
121+
* @return the spec.
122+
*/
123+
public static SmbMessageHandlerSpec outboundAdapter(SmbRemoteFileTemplate smbRemoteFileTemplate,
124+
FileExistsMode fileExistsMode) {
125+
126+
return new SmbMessageHandlerSpec(smbRemoteFileTemplate, fileExistsMode);
127+
}
128+
129+
/**
130+
* Produce a {@link SmbOutboundGatewaySpec} based on the
131+
* {@link MessageSessionCallback}.
132+
* @param sessionFactory the {@link SessionFactory} to connect to.
133+
* @param messageSessionCallback the {@link MessageSessionCallback} to perform SMB.
134+
* operation(s) with the {@code Message} context.
135+
* @return the {@link SmbOutboundGatewaySpec}
136+
* @see MessageSessionCallback
137+
*/
138+
public static SmbOutboundGatewaySpec outboundGateway(SessionFactory<SmbFile> sessionFactory,
139+
MessageSessionCallback<SmbFile, ?> messageSessionCallback) {
140+
141+
return new SmbOutboundGatewaySpec(new SmbOutboundGateway(sessionFactory, messageSessionCallback));
142+
}
143+
144+
private Smb() {
145+
}
146+
147+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.smb.dsl;
18+
19+
import java.io.File;
20+
import java.util.Comparator;
21+
22+
import org.springframework.integration.file.dsl.RemoteFileInboundChannelAdapterSpec;
23+
import org.springframework.integration.file.filters.CompositeFileListFilter;
24+
import org.springframework.integration.file.filters.FileListFilter;
25+
import org.springframework.integration.file.remote.session.SessionFactory;
26+
import org.springframework.integration.metadata.SimpleMetadataStore;
27+
import org.springframework.integration.smb.filters.SmbPersistentAcceptOnceFileListFilter;
28+
import org.springframework.integration.smb.filters.SmbRegexPatternFileListFilter;
29+
import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter;
30+
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizer;
31+
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMessageSource;
32+
33+
import jcifs.smb.SmbFile;
34+
35+
/**
36+
* A {@link RemoteFileInboundChannelAdapterSpec} for an {@link SmbInboundFileSynchronizingMessageSource}.
37+
*
38+
* @author Gregory Bragg
39+
*
40+
* @since 6.0
41+
*/
42+
public class SmbInboundChannelAdapterSpec
43+
extends RemoteFileInboundChannelAdapterSpec<SmbFile, SmbInboundChannelAdapterSpec,
44+
SmbInboundFileSynchronizingMessageSource> {
45+
46+
protected SmbInboundChannelAdapterSpec(SessionFactory<SmbFile> sessionFactory, Comparator<File> comparator) {
47+
super(new SmbInboundFileSynchronizer(sessionFactory));
48+
this.target = new SmbInboundFileSynchronizingMessageSource(this.synchronizer, comparator);
49+
}
50+
51+
/**
52+
* Specify a simple pattern to match remote files.
53+
* @param pattern the pattern.
54+
* @see SmbSimplePatternFileListFilter
55+
* @see #filter(org.springframework.integration.file.filters.FileListFilter)
56+
*/
57+
@Override
58+
public SmbInboundChannelAdapterSpec patternFilter(String pattern) {
59+
return filter(composeFilters(new SmbSimplePatternFileListFilter(pattern)));
60+
}
61+
62+
/**
63+
* Specify a regular expression to match remote files.
64+
* @param regex the expression.
65+
* @see SmbRegexPatternFileListFilter
66+
* @see #filter(org.springframework.integration.file.filters.FileListFilter)
67+
*/
68+
@Override
69+
public SmbInboundChannelAdapterSpec regexFilter(String regex) {
70+
return filter(composeFilters(new SmbRegexPatternFileListFilter(regex)));
71+
}
72+
73+
private CompositeFileListFilter<SmbFile> composeFilters(FileListFilter<SmbFile> fileListFilter) {
74+
CompositeFileListFilter<SmbFile> compositeFileListFilter = new CompositeFileListFilter<>();
75+
compositeFileListFilter.addFilters(fileListFilter,
76+
new SmbPersistentAcceptOnceFileListFilter(new SimpleMetadataStore(), "smbMessageSource"));
77+
return compositeFileListFilter;
78+
}
79+
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.smb.dsl;
18+
19+
import org.springframework.integration.file.dsl.FileTransferringMessageHandlerSpec;
20+
import org.springframework.integration.file.remote.session.SessionFactory;
21+
import org.springframework.integration.file.support.FileExistsMode;
22+
import org.springframework.integration.smb.outbound.SmbMessageHandler;
23+
import org.springframework.integration.smb.session.SmbRemoteFileTemplate;
24+
25+
import jcifs.smb.SmbFile;
26+
27+
/**
28+
* A {@link FileTransferringMessageHandlerSpec} for SMB.
29+
*
30+
* @author Gregory Bragg
31+
*
32+
* @since 6.0
33+
*/
34+
public class SmbMessageHandlerSpec extends FileTransferringMessageHandlerSpec<SmbFile, SmbMessageHandlerSpec> {
35+
36+
protected SmbMessageHandlerSpec(SessionFactory<SmbFile> sessionFactory) {
37+
this.target = new SmbMessageHandler(sessionFactory);
38+
}
39+
40+
protected SmbMessageHandlerSpec(SmbRemoteFileTemplate smbRemoteFileTemplate) {
41+
this.target = new SmbMessageHandler(smbRemoteFileTemplate);
42+
}
43+
44+
protected SmbMessageHandlerSpec(SmbRemoteFileTemplate smbRemoteFileTemplate, FileExistsMode fileExistsMode) {
45+
this.target = new SmbMessageHandler(smbRemoteFileTemplate, fileExistsMode);
46+
}
47+
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 2022 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.integration.smb.dsl;
18+
19+
import org.springframework.integration.file.dsl.RemoteFileOutboundGatewaySpec;
20+
import org.springframework.integration.smb.filters.SmbRegexPatternFileListFilter;
21+
import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter;
22+
import org.springframework.integration.smb.outbound.SmbOutboundGateway;
23+
24+
import jcifs.smb.SmbFile;
25+
26+
/**
27+
* A {@link RemoteFileOutboundGatewaySpec} for SMB.
28+
*
29+
* @author Gregory Bragg
30+
*
31+
* @since 6.0
32+
*/
33+
public class SmbOutboundGatewaySpec extends RemoteFileOutboundGatewaySpec<SmbFile, SmbOutboundGatewaySpec> {
34+
35+
protected SmbOutboundGatewaySpec(SmbOutboundGateway outboundGateway) {
36+
super(outboundGateway);
37+
}
38+
39+
/**
40+
* @see SmbSimplePatternFileListFilter
41+
*/
42+
@Override
43+
public SmbOutboundGatewaySpec patternFileNameFilter(String pattern) {
44+
return filter(new SmbSimplePatternFileListFilter(pattern));
45+
}
46+
47+
/**
48+
* @see SmbRegexPatternFileListFilter
49+
*/
50+
@Override
51+
public SmbOutboundGatewaySpec regexFileNameFilter(String regex) {
52+
return filter(new SmbRegexPatternFileListFilter(regex));
53+
}
54+
55+
}

0 commit comments

Comments
 (0)