Skip to content

Commit

Permalink
Migrate SMB extension project to respective module
Browse files Browse the repository at this point in the history
* Removed deprecated replaceFile and useTempFile session configs
* Refactored to use AssertJ instead of JUnit asserts as per PR feedback
* Code clean up for SMB module
  • Loading branch information
GregBragg authored and artembilan committed May 6, 2022
1 parent 392455e commit 7ad71d3
Show file tree
Hide file tree
Showing 46 changed files with 3,785 additions and 0 deletions.
11 changes: 11 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ ext {
h2Version = '2.1.210'
jacksonVersion = '2.13.2'
jaxbVersion = '3.0.2'
jcifsVersion = '2.1.29'
jeroMqVersion = '0.5.2'
jmsApiVersion = '3.0.0'
jpaApiVersion = '3.0.2'
Expand Down Expand Up @@ -874,6 +875,16 @@ project('spring-integration-sftp') {
}
}

project('spring-integration-smb') {
description = 'Spring Integration SMB Support'
dependencies {
api project(':spring-integration-file')
api "org.codelibs:jcifs:$jcifsVersion"

testImplementation project(':spring-integration-file').sourceSets.test.output
}
}

project('spring-integration-stomp') {
description = 'Spring Integration STOMP Support'
dependencies {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.config;

import org.springframework.integration.file.config.AbstractRemoteFileInboundChannelAdapterParser;
import org.springframework.integration.file.filters.AbstractPersistentAcceptOnceFileListFilter;
import org.springframework.integration.file.filters.FileListFilter;
import org.springframework.integration.file.remote.synchronizer.InboundFileSynchronizer;
import org.springframework.integration.smb.filters.SmbPersistentAcceptOnceFileListFilter;
import org.springframework.integration.smb.filters.SmbRegexPatternFileListFilter;
import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter;
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizer;
import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMessageSource;

/**
* Parser for the SMB 'inbound-channel-adapter' element.
*
* @author Markus Spann
* @author Artem Bilan
* @author Prafull Kumar Soni
*
* @since 6.0
*/
public class SmbInboundChannelAdapterParser extends AbstractRemoteFileInboundChannelAdapterParser {

@Override
protected String getMessageSourceClassname() {
return SmbInboundFileSynchronizingMessageSource.class.getName();
}

@Override
protected Class<? extends InboundFileSynchronizer> getInboundFileSynchronizerClass() {
return SmbInboundFileSynchronizer.class;
}

@Override
protected Class<? extends FileListFilter<?>> getSimplePatternFileListFilterClass() {
return SmbSimplePatternFileListFilter.class;
}

@Override
protected Class<? extends FileListFilter<?>> getRegexPatternFileListFilterClass() {
return SmbRegexPatternFileListFilter.class;
}

@Override
protected Class<? extends AbstractPersistentAcceptOnceFileListFilter<?>> getPersistentAcceptOnceFileListFilterClass() {
return SmbPersistentAcceptOnceFileListFilter.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.config;

import org.springframework.integration.config.xml.AbstractIntegrationNamespaceHandler;

/**
* Provides namespace support for using SMB.
*
* @author Markus Spann
* @author Artem Bilan
*
* @since 6.0
*/
public class SmbNamespaceHandler extends AbstractIntegrationNamespaceHandler {

public void init() {
registerBeanDefinitionParser("inbound-channel-adapter", new SmbInboundChannelAdapterParser());
registerBeanDefinitionParser("outbound-channel-adapter", new SmbOutboundChannelAdapterParser());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2017-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.config;

import org.springframework.integration.file.config.RemoteFileOutboundChannelAdapterParser;
import org.springframework.integration.file.remote.RemoteFileOperations;
import org.springframework.integration.smb.session.SmbRemoteFileTemplate;

/**
* The parser for {@code <Int-smb:outbound-channel-adapter>}.
*
* @author Artem Bilan
*
* @since 6.0
*/
public class SmbOutboundChannelAdapterParser extends RemoteFileOutboundChannelAdapterParser {

@Override
protected Class<? extends RemoteFileOperations<?>> getTemplateClass() {
return SmbRemoteFileTemplate.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* SMB-specific file list filter classes.
*/
package org.springframework.integration.smb.config;
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Copyright 2018-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.filters;

import org.springframework.integration.file.filters.AbstractPersistentAcceptOnceFileListFilter;
import org.springframework.integration.metadata.ConcurrentMetadataStore;

import jcifs.smb.SmbFile;

/**
* Implementation of {@link AbstractPersistentAcceptOnceFileListFilter} for SMB.
*
* @author Prafull Kumar Soni
*
* @since 6.0
*/
public class SmbPersistentAcceptOnceFileListFilter extends AbstractPersistentAcceptOnceFileListFilter<SmbFile> {


public SmbPersistentAcceptOnceFileListFilter(ConcurrentMetadataStore store, String prefix) {
super(store, prefix);
}

@Override
protected long modified(SmbFile file) {
return file.getLastModified();
}

@Override
protected String fileName(SmbFile file) {
return file.getName();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Copyright 2012-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.filters;

import java.io.UncheckedIOException;
import java.util.regex.Pattern;

import org.springframework.integration.file.filters.AbstractRegexPatternFileListFilter;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

/**
* Implementation of {@link AbstractRegexPatternFileListFilter} for SMB.
*
* @author Markus Spann
* @author Prafull Kumar Soni
*
* @since 6.0
*/
public class SmbRegexPatternFileListFilter extends AbstractRegexPatternFileListFilter<SmbFile> {

public SmbRegexPatternFileListFilter(String pattern) {
this(Pattern.compile(pattern));
}

public SmbRegexPatternFileListFilter(Pattern pattern) {
super(pattern);
}

/**
* Gets the specified SMB file's name.
* @param file SMB file object
* @return file name
* @see AbstractRegexPatternFileListFilter#getFilename(java.lang.Object)
*/
@Override
protected String getFilename(SmbFile file) {
return (file != null ? file.getName() : null);
}

@Override
protected boolean isDirectory(SmbFile file) {
try {
return file.isDirectory();
}
catch (SmbException e) {
throw new UncheckedIOException(e);
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
* Copyright 2018-2022 the original author or authors.
*
* Licensed 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
*
* https://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.springframework.integration.smb.filters;

import java.io.UncheckedIOException;

import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter;

import jcifs.smb.SmbException;
import jcifs.smb.SmbFile;

/**
* Implementation of {@link AbstractSimplePatternFileListFilter} for SMB.
*
* @author Markus Spann
* @author Prafull Kumar Soni
*
* @since 6.0
*/
public class SmbSimplePatternFileListFilter extends AbstractSimplePatternFileListFilter<SmbFile> {

public SmbSimplePatternFileListFilter(String pathPattern) {
super(pathPattern);
}

/**
* Gets the specified SMB file's name.
* @param file SMB file object
* @return file name
* @see AbstractSimplePatternFileListFilter#getFilename(java.lang.Object)
*/
@Override
protected String getFilename(SmbFile file) {
return (file != null) ? file.getName() : null;
}


@Override
protected boolean isDirectory(SmbFile file) {
try {
return file.isDirectory();
}
catch (SmbException e) {
throw new UncheckedIOException(e);
}
}

}

0 comments on commit 7ad71d3

Please sign in to comment.