diff --git a/spring-integration-smb/.travis.yml b/spring-integration-smb/.travis.yml new file mode 100644 index 0000000..aa1ed9e --- /dev/null +++ b/spring-integration-smb/.travis.yml @@ -0,0 +1,12 @@ +language: java +jdk: oraclejdk8 +sudo: false +before_cache: + - rm -f $HOME/.gradle/caches/modules-2/modules-2.lock +cache: + directories: + - $HOME/.gradle/caches/ + - $HOME/.gradle/wrapper/ +install: true +script: + - ./gradlew check --no-daemon diff --git a/spring-integration-smb/README.md b/spring-integration-smb/README.md index 9a5e40c..aecf634 100644 --- a/spring-integration-smb/README.md +++ b/spring-integration-smb/README.md @@ -3,7 +3,7 @@ Spring Integration Smb Support ## Introduction -This module add Spring Integration* support for [Server Message Block][] (SMB). +This module add Spring Integration support for [Server Message Block][] (SMB). [Server Message Block]: http://en.wikipedia.org/wiki/Server_Message_Block diff --git a/spring-integration-smb/build.gradle b/spring-integration-smb/build.gradle index 479fe42..8585eae 100644 --- a/spring-integration-smb/build.gradle +++ b/spring-integration-smb/build.gradle @@ -1,43 +1,62 @@ -description = 'Spring Integration SMB Support' - buildscript { repositories { - maven { url 'https://repo.springsource.org/plugins-snapshot' } + maven { url 'https://repo.spring.io/plugins-release' } } dependencies { - classpath 'org.springframework.build.gradle:docbook-reference-plugin:0.1.5' + classpath 'io.spring.gradle:dependency-management-plugin:1.0.0.RC2' + classpath 'io.spring.gradle:spring-io-plugin:0.0.6.RELEASE' + classpath 'io.spring.gradle:docbook-reference-plugin:0.3.1' } } -apply plugin: 'java' +plugins { + id 'java' + id 'eclipse' + id 'idea' + id 'jacoco' + id 'checkstyle' + id 'org.sonarqube' version '2.1' +} + +description = 'Spring Integration SMB Support' + apply from: "${rootProject.projectDir}/publish-maven.gradle" -apply plugin: 'eclipse' -apply plugin: 'idea' group = 'org.springframework.integration' repositories { - maven { url 'http://repo.springsource.org/libs-milestone' } - maven { url 'http://repo.springsource.org/plugins-release' } // for bundlor + if (version.endsWith('BUILD-SNAPSHOT') || project.hasProperty('platformVersion')) { + maven { url 'http://repo.spring.io/libs-snapshot' } + } + maven { url 'http://repo.spring.io/libs-milestone' } } -// ensure JDK 5 compatibility (GRADLE-18; INT-1578) -sourceCompatibility=1.6 -targetCompatibility=1.6 +if (project.hasProperty('platformVersion')) { + apply plugin: 'spring-io' + + dependencyManagement { + springIoTestRuntime { + imports { + mavenBom "io.spring.platform:platform-bom:${platformVersion}" + } + } + } +} + +compileJava { + sourceCompatibility = 1.7 + targetCompatibility = 1.7 +} + +compileTestJava { + sourceCompatibility = 1.8 + targetCompatibility = 1.8 +} ext { - aspectjVersion = '1.6.8' - cglibVersion = '2.2' - commonsNetVersion = '3.0.1' - groovyVersion = '1.8.5' - jacksonVersion = '1.9.2' - javaxActivationVersion = '1.1.1' - junitVersion = '4.11' - log4jVersion = '1.2.12' - mockitoVersion = '1.9.0' - - springVersion = '3.1.3.RELEASE' - springIntegrationVersion = '2.2.1.RELEASE' + jcifsVersion = '1.3.18.2' + log4jVersion = '1.2.17' + springIntegrationVersion = '4.3.6.RELEASE' idPrefix = 'smb' @@ -50,24 +69,7 @@ ext { } -dependencies { - - compile "org.springframework.integration:spring-integration-core:$springIntegrationVersion" - compile "org.springframework.integration:spring-integration-file:$springIntegrationVersion" - compile "org.springframework.integration:spring-integration-stream:$springIntegrationVersion" - compile "jcifs:jcifs:1.3.17" - compile "org.springframework:spring-context-support:$springVersion" - compile("javax.activation:activation:$javaxActivationVersion", optional) - testCompile "org.springframework.integration:spring-integration-test:$springIntegrationVersion" - -} - - -eclipse { - project { - natures += 'org.springframework.ide.eclipse.core.springnature' - } -} +eclipse.project.natures += 'org.springframework.ide.eclipse.core.springnature' sourceSets { test { @@ -77,31 +79,43 @@ sourceSets { } } -// See http://www.gradle.org/docs/current/userguide/dependency_management.html#sub:configurations -// and http://www.gradle.org/docs/current/dsl/org.gradle.api.artifacts.ConfigurationContainer.html -configurations { - jacoco //Configuration Group used by Sonar to provide Code Coverage using JaCoCo +jacoco { + toolVersion = "0.7.8" +} + +checkstyle { + configFile = file("$rootDir/src/checkstyle/checkstyle.xml") + toolVersion = "6.16.1" } -// dependencies that are common across all java projects dependencies { - testCompile "cglib:cglib-nodep:$cglibVersion" - testCompile "junit:junit-dep:$junitVersion" - testCompile "log4j:log4j:$log4jVersion" - testCompile "org.hamcrest:hamcrest-all:1.1" - testCompile "org.mockito:mockito-all:$mockitoVersion" - testCompile "org.springframework:spring-test:$springVersion" - jacoco group: "org.jacoco", name: "org.jacoco.agent", version: "0.5.6.201201232323", classifier: "runtime" + compile "org.codelibs:jcifs:$jcifsVersion" + compile "org.springframework.integration:spring-integration-file:$springIntegrationVersion" + compile "org.springframework.integration:spring-integration-stream:$springIntegrationVersion" + + testCompile "org.springframework.integration:spring-integration-test:$springIntegrationVersion" + testRuntime "log4j:log4j:$log4jVersion" } // enable all compiler warnings; individual projects may customize further -ext.xLintArg = '-Xlint:all' -[compileJava, compileTestJava]*.options*.compilerArgs = [xLintArg] +[compileJava, compileTestJava]*.options*.compilerArgs = ['-Xlint:all,-options,-processing'] + +jacocoTestReport { + reports { + xml.enabled false + csv.enabled false + html.destination "${buildDir}/reports/jacoco/html" + } +} test { // suppress all console output during testing unless running `gradle -i` logging.captureStandardOutput(LogLevel.INFO) - jvmArgs "-javaagent:${configurations.jacoco.asPath}=destfile=${buildDir}/jacoco.exec,includes=*" + maxHeapSize = "1024m" + jacoco { + append = false + destinationFile = file("$buildDir/jacoco.exec") + } } task sourcesJar(type: Jar) { @@ -125,10 +139,8 @@ reference { sourceDir = file('src/reference/docbook') } -apply plugin: 'sonar-runner' - -sonarRunner { - sonarProperties { +sonarqube { + properties { property "sonar.jacoco.reportPath", "${buildDir.name}/jacoco.exec" property "sonar.links.homepage", linkHomepage property "sonar.links.ci", linkCi @@ -150,7 +162,7 @@ task api(type: Javadoc) { source = sourceSets.main.allJava classpath = project.sourceSets.main.compileClasspath - destinationDir = new File(buildDir, "api") + destinationDir = file("$buildDir/api") } task schemaZip(type: Zip) { @@ -163,15 +175,15 @@ task schemaZip(type: Zip) { def shortName = idPrefix.replaceFirst("${idPrefix}-", '') project.sourceSets.main.resources.find { - it.path.endsWith('META-INF/spring.schemas') + it.path.endsWith("META-INF${File.separator}spring.schemas") }?.withInputStream { schemas.load(it) } for (def key : schemas.keySet()) { File xsdFile = project.sourceSets.main.resources.find { - it.path.endsWith(schemas.get(key)) + it.path.replaceAll('\\\\', '/').endsWith(schemas.get(key)) } assert xsdFile != null - into ("integration/${shortName}") { + into("integration/${shortName}") { from xsdFile.path } } @@ -266,8 +278,3 @@ task dist(dependsOn: assemble) { group = 'Distribution' description = 'Builds -dist, -docs and -schema distribution archives.' } - -task wrapper(type: Wrapper) { - description = 'Generates gradlew[.bat] scripts' - gradleVersion = '1.6' -} diff --git a/spring-integration-smb/gradle.properties b/spring-integration-smb/gradle.properties index bebfcbc..5364470 100644 --- a/spring-integration-smb/gradle.properties +++ b/spring-integration-smb/gradle.properties @@ -1 +1 @@ -version=1.0.0.BUILD-SNAPSHOT +version=0.5.0.BUILD-SNAPSHOT diff --git a/spring-integration-smb/gradle/wrapper/gradle-wrapper.jar b/spring-integration-smb/gradle/wrapper/gradle-wrapper.jar index a7634b0..cf7c6b9 100644 Binary files a/spring-integration-smb/gradle/wrapper/gradle-wrapper.jar and b/spring-integration-smb/gradle/wrapper/gradle-wrapper.jar differ diff --git a/spring-integration-smb/gradle/wrapper/gradle-wrapper.properties b/spring-integration-smb/gradle/wrapper/gradle-wrapper.properties index 426d227..0cbb8f5 100644 --- a/spring-integration-smb/gradle/wrapper/gradle-wrapper.properties +++ b/spring-integration-smb/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ -#Wed May 15 22:13:48 EDT 2013 +#Mon Jan 16 10:37:27 EST 2017 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=http\://services.gradle.org/distributions/gradle-1.6-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-bin.zip diff --git a/spring-integration-smb/gradlew b/spring-integration-smb/gradlew index 91a7e26..4453cce 100755 --- a/spring-integration-smb/gradlew +++ b/spring-integration-smb/gradlew @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/usr/bin/env sh ############################################################################## ## @@ -6,12 +6,30 @@ ## ############################################################################## -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS="" +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG=`dirname "$PRG"`"/$link" + fi +done +SAVED="`pwd`" +cd "`dirname \"$PRG\"`/" >/dev/null +APP_HOME="`pwd -P`" +cd "$SAVED" >/dev/null APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS="" + # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" @@ -30,6 +48,7 @@ die ( ) { cygwin=false msys=false darwin=false +nonstop=false case "`uname`" in CYGWIN* ) cygwin=true @@ -40,31 +59,11 @@ case "`uname`" in MINGW* ) msys=true ;; + NONSTOP* ) + nonstop=true + ;; esac -# For Cygwin, ensure paths are in UNIX format before anything is touched. -if $cygwin ; then - [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"` -fi - -# Attempt to set APP_HOME -# Resolve links: $0 may be a link -PRG="$0" -# Need this for relative symlinks. -while [ -h "$PRG" ] ; do - ls=`ls -ld "$PRG"` - link=`expr "$ls" : '.*-> \(.*\)$'` - if expr "$link" : '/.*' > /dev/null; then - PRG="$link" - else - PRG=`dirname "$PRG"`"/$link" - fi -done -SAVED="`pwd`" -cd "`dirname \"$PRG\"`/" >&- -APP_HOME="`pwd -P`" -cd "$SAVED" >&- - CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. @@ -90,7 +89,7 @@ location of your Java installation." fi # Increase the maximum file descriptors if we can. -if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then +if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then @@ -114,6 +113,7 @@ fi if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` @@ -154,11 +154,19 @@ if $cygwin ; then esac fi -# Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules -function splitJvmOpts() { - JVM_OPTS=("$@") +# Escape application args +save ( ) { + for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done + echo " " } -eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS -JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" +APP_ARGS=$(save "$@") -exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" +# Collect all arguments for the java command, following the shell quoting and substitution rules +eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +exec "$JAVACMD" "$@" diff --git a/spring-integration-smb/gradlew.bat b/spring-integration-smb/gradlew.bat index aec9973..e95643d 100644 --- a/spring-integration-smb/gradlew.bat +++ b/spring-integration-smb/gradlew.bat @@ -8,14 +8,14 @@ @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal -@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -set DEFAULT_JVM_OPTS= - set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS= + @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome @@ -46,10 +46,9 @@ echo location of your Java installation. goto fail :init -@rem Get command-line arguments, handling Windowz variants +@rem Get command-line arguments, handling Windows variants if not "%OS%" == "Windows_NT" goto win9xME_args -if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. @@ -60,11 +59,6 @@ set _SKIP=2 if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* -goto execute - -:4NT_args -@rem Get arguments from the 4NT Shell from JP Software -set CMD_LINE_ARGS=%$ :execute @rem Setup the command line diff --git a/spring-integration-smb/publish-maven.gradle b/spring-integration-smb/publish-maven.gradle index 06eb14e..fe5dd02 100644 --- a/spring-integration-smb/publish-maven.gradle +++ b/spring-integration-smb/publish-maven.gradle @@ -31,10 +31,10 @@ def customizePom(pom, gradleProject) { generatedPom.project { name = gradleProject.description description = gradleProject.description - url = 'https://github.com/SpringSource/spring-integration-extensions' + url = linkHomepage organization { - name = 'SpringSource' - url = 'http://springsource.org' + name = 'SpringIO' + url = 'http://spring.io' } licenses { license { @@ -43,19 +43,37 @@ def customizePom(pom, gradleProject) { distribution 'repo' } } + scm { - url = 'https://github.com/SpringSource/spring-integration-extensions' - connection = 'scm:git:git://github.com/SpringSource/spring-integration-extensions' - developerConnection = 'scm:git:git://github.com/SpringSource/spring-integration-extensions' + url = linkScmUrl + connection = 'scm:git:' + linkScmConnection + developerConnection = 'scm:git:' + linkScmDevConnection + } + + issueManagement { + system = "Jira" + url = linkIssue } developers { developer { - id = 'not specified' - name = 'Markus Spann' - email = 'not specified' + id = 'garyrussell' + name = 'Gary Russell' + email = 'grussell@pivotal.io' + roles = ["project lead"] + } + developer { + id = 'ghillert' + name = 'Gunnar Hillert' + email = 'ghillert@pivotal.io' + } + developer { + id = 'abilan' + name = 'Artem Bilan' + email = 'abilan@pivotal.io' } } } } } + diff --git a/spring-integration-smb/settings.gradle b/spring-integration-smb/settings.gradle new file mode 100644 index 0000000..8e5f6a5 --- /dev/null +++ b/spring-integration-smb/settings.gradle @@ -0,0 +1 @@ +rootProject.name = 'spring-integration-smb' diff --git a/spring-integration-smb/src/api/overview.html b/spring-integration-smb/src/api/overview.html index fb0198b..61bbef4 100644 --- a/spring-integration-smb/src/api/overview.html +++ b/spring-integration-smb/src/api/overview.html @@ -5,7 +5,7 @@ This document is the API specification for Spring Integration

For further API reference and developer documentation, see the - Spring + Spring Integration reference documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, @@ -14,8 +14,8 @@ This document is the API specification for Spring Integration

If you are interested in commercial training, consultancy, and - support for Spring Integration, please visit - http://www.springsource.com + support for Spring Integration, please visit + https://spring.io

diff --git a/spring-integration-smb/src/checkstyle/checkstyle-header.txt b/spring-integration-smb/src/checkstyle/checkstyle-header.txt new file mode 100644 index 0000000..f470e97 --- /dev/null +++ b/spring-integration-smb/src/checkstyle/checkstyle-header.txt @@ -0,0 +1,17 @@ +^\Q/*\E$ +^\Q * Copyright \E20\d\d(\-20\d\d)?\Q the original author or authors.\E$ +^\Q *\E$ +^\Q * Licensed under the Apache License, Version 2.0 (the "License");\E$ +^\Q * you may not use this file except in compliance with the License.\E$ +^\Q * You may obtain a copy of the License at\E$ +^\Q *\E$ +^\Q * http://www.apache.org/licenses/LICENSE-2.0\E$ +^\Q *\E$ +^\Q * Unless required by applicable law or agreed to in writing, software\E$ +^\Q * distributed under the License is distributed on an "AS IS" BASIS,\E$ +^\Q * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\E$ +^\Q * See the License for the specific language governing permissions and\E$ +^\Q * limitations under the License.\E$ +^\Q */\E$ +^$ +^.*$ diff --git a/spring-integration-smb/src/checkstyle/checkstyle-suppressions.xml b/spring-integration-smb/src/checkstyle/checkstyle-suppressions.xml new file mode 100644 index 0000000..2db9e2f --- /dev/null +++ b/spring-integration-smb/src/checkstyle/checkstyle-suppressions.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + diff --git a/spring-integration-smb/src/checkstyle/checkstyle.xml b/spring-integration-smb/src/checkstyle/checkstyle.xml new file mode 100644 index 0000000..543ba4d --- /dev/null +++ b/spring-integration-smb/src/checkstyle/checkstyle.xml @@ -0,0 +1,188 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/spring-integration-smb/src/dist/readme.txt b/spring-integration-smb/src/dist/readme.txt index 82afb88..84ec4dc 100644 --- a/spring-integration-smb/src/dist/readme.txt +++ b/spring-integration-smb/src/dist/readme.txt @@ -1,13 +1,13 @@ -Spring Integration Smb Adapter +Spring Integration Smb Adapters ----------------------------------- To find out what has changed since any earlier releases, see 'changelog.txt'. Please consult the documentation located within the 'docs/reference' directory of this release and also visit the official Spring Integration home at -http://www.springsource.org/spring-integration +http://spring.io/spring-integration There you will find links to the forum, issue tracker, and several other resources. -See https://github.com/SpringSource/spring-integration#readme for additional +See https://github.com/spring-projects/spring-integration#readme for additional information including instructions on building from source. diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParser.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParser.java index 03f3e0b..ac1616c 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParser.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParser.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,39 +13,43 @@ * 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.FileListFilter; +import org.springframework.integration.file.remote.synchronizer.InboundFileSynchronizer; +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 - * @since 1.0 + * @author Artem Bilan */ public class SmbInboundChannelAdapterParser extends AbstractRemoteFileInboundChannelAdapterParser { - private static final String BASE_PACKAGE = "org.springframework.integration.smb"; - - @Override protected String getMessageSourceClassname() { - return BASE_PACKAGE + ".inbound.SmbInboundFileSynchronizingMessageSource"; + return SmbInboundFileSynchronizingMessageSource.class.getName(); } @Override - protected String getInboundFileSynchronizerClassname() { - return BASE_PACKAGE + ".inbound.SmbInboundFileSynchronizer"; + protected Class getInboundFileSynchronizerClass() { + return SmbInboundFileSynchronizer.class; } @Override - protected String getSimplePatternFileListFilterClassname() { - return BASE_PACKAGE + ".filters.SmbSimplePatternFileListFilter"; + protected Class> getSimplePatternFileListFilterClass() { + return SmbSimplePatternFileListFilter.class; } @Override - protected String getRegexPatternFileListFilterClassname() { - return BASE_PACKAGE + ".filters.SmbRegexPatternFileListFilter"; + protected Class> getRegexPatternFileListFilterClass() { + return SmbRegexPatternFileListFilter.class; } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbNamespaceHandler.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbNamespaceHandler.java index ab0b041..0ebc9d4 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbNamespaceHandler.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbNamespaceHandler.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,22 +13,22 @@ * 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; -import org.springframework.integration.file.config.RemoteFileOutboundChannelAdapterParser; /** * Provides namespace support for using SMB. * * @author Markus Spann - * @since 1.0 + * @author Artem Bilan */ public class SmbNamespaceHandler extends AbstractIntegrationNamespaceHandler { public void init() { - registerBeanDefinitionParser("inbound-channel-adapter", new SmbInboundChannelAdapterParser()); - registerBeanDefinitionParser("outbound-channel-adapter", new RemoteFileOutboundChannelAdapterParser()); // TODO need implementation for SMB? + registerBeanDefinitionParser("inbound-channel-adapter", new SmbInboundChannelAdapterParser()); + registerBeanDefinitionParser("outbound-channel-adapter", new SmbOutboundChannelAdapterParser()); } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParser.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParser.java new file mode 100644 index 0000000..1a90882 --- /dev/null +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParser.java @@ -0,0 +1,33 @@ +/* + * Copyright 2017 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 + * + * 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.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; + +/** + * @author Artem Bilan + */ +public class SmbOutboundChannelAdapterParser extends RemoteFileOutboundChannelAdapterParser { + + @Override + protected Class> getTemplateClass() { + return SmbRemoteFileTemplate.class; + } + +} diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbRegexPatternFileListFilter.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbRegexPatternFileListFilter.java index 1feab84..539358a 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbRegexPatternFileListFilter.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbRegexPatternFileListFilter.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,47 +13,39 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.filters; import java.util.regex.Pattern; -import jcifs.smb.SmbFile; - import org.springframework.integration.file.filters.AbstractRegexPatternFileListFilter; +import jcifs.smb.SmbFile; + /** * Implementation of {@link AbstractRegexPatternFileListFilter} for SMB. * * @author Markus Spann - * @since 1.0 */ public class SmbRegexPatternFileListFilter extends AbstractRegexPatternFileListFilter { - private final String toString; - - public SmbRegexPatternFileListFilter(String _pattern) { - this(Pattern.compile(_pattern)); + public SmbRegexPatternFileListFilter(String pattern) { + this(Pattern.compile(pattern)); } - public SmbRegexPatternFileListFilter(Pattern _pattern) { - super(_pattern); - toString = getClass().getName() + "[pattern='" + _pattern + "']"; + public SmbRegexPatternFileListFilter(Pattern pattern) { + super(pattern); } /** * Gets the specified SMB file's name. - * @param _file SMB file object + * @param file SMB file object * @return file name - * @see org.springframework.integration.file.filters.AbstractRegexPatternFileListFilter#getFilename(java.lang.Object) + * @see AbstractRegexPatternFileListFilter#getFilename(java.lang.Object) */ @Override - protected String getFilename(SmbFile _file) { - return (_file != null) ? _file.getName() : null; - } - - @Override - public String toString() { - return toString; + protected String getFilename(SmbFile file) { + return (file != null ? file.getName() : null); } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbSimplePatternFileListFilter.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbSimplePatternFileListFilter.java index ee89e20..4ffaef2 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbSimplePatternFileListFilter.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/filters/SmbSimplePatternFileListFilter.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,42 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.filters; -import jcifs.smb.SmbFile; - import org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter; +import jcifs.smb.SmbFile; + /** * Implementation of {@link AbstractSimplePatternFileListFilter} for SMB. * * @author Markus Spann - * @since 1.0 * */ public class SmbSimplePatternFileListFilter extends AbstractSimplePatternFileListFilter { - private final String toString; - - public SmbSimplePatternFileListFilter(String _pathPattern) { - super(_pathPattern); - toString = getClass().getName() + "[pattern='" + _pathPattern + "']"; + public SmbSimplePatternFileListFilter(String pathPattern) { + super(pathPattern); } /** * Gets the specified SMB file's name. - * @param _file SMB file object + * @param file SMB file object * @return file name - * @see org.springframework.integration.file.filters.AbstractSimplePatternFileListFilter#getFilename(java.lang.Object) + * @see AbstractSimplePatternFileListFilter#getFilename(java.lang.Object) */ @Override - protected String getFilename(SmbFile _file) { - return (_file != null) ? _file.getName() : null; - } - - @Override - public String toString() { - return toString; + protected String getFilename(SmbFile file) { + return (file != null) ? file.getName() : null; } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizer.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizer.java index 6f4132e..5d83f54 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizer.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizer.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,41 +13,37 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.inbound; -import jcifs.smb.SmbFile; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.springframework.integration.file.remote.session.SessionFactory; import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer; +import jcifs.smb.SmbFile; + /** * An implementation of {@link AbstractInboundFileSynchronizer} for SMB. * * @author Markus Spann - * @since 1.0 + * @author Artem Bilan */ public class SmbInboundFileSynchronizer extends AbstractInboundFileSynchronizer { - private final Log logger = LogFactory.getLog(SmbInboundFileSynchronizer.class); - - private final String toString; - /** * Create a synchronizer with the {@link SessionFactory} used to acquire * {@link org.springframework.integration.file.remote.session.Session} instances. + * @param sessionFactory the {@link SessionFactory} to use. */ - public SmbInboundFileSynchronizer(SessionFactory _sessionFactory) { - super(_sessionFactory); - toString = getClass().getName() + "[sessionFactory=" + _sessionFactory + "]"; + public SmbInboundFileSynchronizer(SessionFactory sessionFactory) { + super(sessionFactory); } @Override protected boolean isFile(SmbFile _file) { try { return _file != null && _file.isFile(); - } catch (Exception _ex) { + } + catch (Exception _ex) { logger.warn("Unable to get resource status [" + _file + "].", _ex); } return false; @@ -59,8 +55,8 @@ public class SmbInboundFileSynchronizer extends AbstractInboundFileSynchronizer< } @Override - public String toString() { - return toString; + protected long getModified(SmbFile file) { + return file.getLastModified(); } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizingMessageSource.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizingMessageSource.java index 1b8c0fb..62a7974 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizingMessageSource.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/inbound/SmbInboundFileSynchronizingMessageSource.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,16 +13,17 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.inbound; import java.io.File; import java.util.Comparator; -import jcifs.smb.SmbFile; - import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizer; import org.springframework.integration.file.remote.synchronizer.AbstractInboundFileSynchronizingMessageSource; +import jcifs.smb.SmbFile; + /** * A {@link org.springframework.integration.core.MessageSource} implementation for SMB. * @@ -31,26 +32,18 @@ import org.springframework.integration.file.remote.synchronizer.AbstractInboundF */ public class SmbInboundFileSynchronizingMessageSource extends AbstractInboundFileSynchronizingMessageSource { - private final static String componentType = "smb:inbound-channel-adapter"; - private final String toString; - public SmbInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer _synchronizer) { this(_synchronizer, null); } - public SmbInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer _synchronizer, Comparator _comparator) { + public SmbInboundFileSynchronizingMessageSource(AbstractInboundFileSynchronizer _synchronizer, + Comparator _comparator) { super(_synchronizer, _comparator); - toString = getClass().getName() + "[componentType=" + componentType + ", synchronizer=" + _synchronizer + ", comparator=" + _comparator + "]"; } @Override public String getComponentType() { - return componentType; - } - - @Override - public String toString() { - return toString; + return "smb:inbound-channel-adapter"; } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java index e6b8d61..d183204 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbConfig.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.session; import java.io.UnsupportedEncodingException; @@ -32,22 +33,27 @@ import org.springframework.util.StringUtils; */ public class SmbConfig { - private String host; - private int port; - private String domain; - private String username; - private String password; - private String shareAndDir; + private String host; + + private int port; + + private String domain; + + private String username; + + private String password; + + private String shareAndDir; private boolean replaceFile = false; + private boolean useTempFile = false; public SmbConfig() { } - public SmbConfig(String _host, int _port, String _domain, String _username, String _password, String _shareAndDir) throws UnsupportedEncodingException { - this(); - + public SmbConfig(String _host, int _port, String _domain, String _username, String _password, String _shareAndDir) + throws UnsupportedEncodingException { setHost(_host); setPort(_port); setDomain(_domain); @@ -62,7 +68,7 @@ public class SmbConfig { } public String getHost() { - return host; + return this.host; } public void setPort(int _port) { @@ -71,7 +77,7 @@ public class SmbConfig { } public int getPort() { - return port; + return this.port; } public void setDomain(String _domain) { @@ -80,7 +86,7 @@ public class SmbConfig { } public String getDomain() { - return domain; + return this.domain; } public void setUsername(String _username) { @@ -89,7 +95,7 @@ public class SmbConfig { } public String getUsername() { - return username; + return this.username; } public void setPassword(String _password) { @@ -98,7 +104,7 @@ public class SmbConfig { } public String getPassword() { - return password; + return this.password; } public void setShareAndDir(String _shareAndDir) { @@ -107,7 +113,7 @@ public class SmbConfig { } public String getShareAndDir() { - return shareAndDir; + return this.shareAndDir; } public void setReplaceFile(boolean _replaceFile) { @@ -115,7 +121,7 @@ public class SmbConfig { } public boolean isReplaceFile() { - return replaceFile; + return this.replaceFile; } void setUseTempFile(boolean _useTempFile) { @@ -123,7 +129,7 @@ public class SmbConfig { } public boolean isUseTempFile() { - return useTempFile; + return this.useTempFile; } String getDomainUserPass(boolean _includePassword) { @@ -131,7 +137,8 @@ public class SmbConfig { String user = _includePassword ? this.username : "********"; if (StringUtils.hasText(this.domain)) { domainUserPass = String.format("%s;%s", this.domain, user); - } else { + } + else { domainUserPass = user; } if (StringUtils.hasText(this.password)) { @@ -176,7 +183,7 @@ public class SmbConfig { public String toString() { return getClass().getSimpleName() + "[url=" + getUrl(false) - + ", replaceFile=" + replaceFile + + ", replaceFile=" + this.replaceFile + "]"; } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbRemoteFileTemplate.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbRemoteFileTemplate.java new file mode 100644 index 0000000..39d247b --- /dev/null +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbRemoteFileTemplate.java @@ -0,0 +1,37 @@ +/* + * Copyright 2017 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 + * + * 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.springframework.integration.smb.session; + +import org.springframework.integration.file.remote.RemoteFileTemplate; +import org.springframework.integration.file.remote.session.SessionFactory; + +import jcifs.smb.SmbFile; + +/** + * @author Artem Bilan + */ +public class SmbRemoteFileTemplate extends RemoteFileTemplate { + + /** + * Construct a {@link SmbRemoteFileTemplate} with the supplied session factory. + * @param sessionFactory the session factory. + */ + public SmbRemoteFileTemplate(SessionFactory sessionFactory) { + super(sessionFactory); + } + +} diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSession.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSession.java index 5cdc373..7ea9ce2 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSession.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSession.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.session; import java.io.ByteArrayInputStream; @@ -23,17 +24,19 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; -import jcifs.smb.SmbException; -import jcifs.smb.SmbFile; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.core.NestedIOException; import org.springframework.integration.file.remote.session.Session; import org.springframework.util.Assert; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; +import jcifs.smb.SmbException; +import jcifs.smb.SmbFile; +import jcifs.smb.SmbFileOutputStream; + /** * Implementation of the {@link Session} interface for Server Message Block (SMB) * also known as Common Internet File System (CIFS). The Samba project set out to @@ -45,19 +48,18 @@ import org.springframework.util.StringUtils; * See Server Message Block * for more details. * - * Inspired by the spring-integration-ftp implementation done by Mark Fisher - * and Oleg Zhurakousky. - * * @author Markus Spann * @author Mark Fisher * @author Oleg Zhurakousky + * @author Artem Bilan * - * @since 1.0 */ public class SmbSession implements Session { - private final Log logger = LogFactory.getLog(SmbSession.class); + private static final Log logger = LogFactory.getLog(SmbSession.class); + private static final String FILE_SEPARATOR = System.getProperty("file.separator"); + private static final String SMB_FILE_SEPARATOR = "/"; static { @@ -78,11 +80,12 @@ public class SmbSession implements Session { * @param _useTempFile make use temporary files when writing * @throws IOException in case of I/O errors */ - SmbSession(String _host, int _port, String _domain, String _user, String _password, String _shareAndDir, boolean _replaceFile, boolean _useTempFile) throws IOException { + SmbSession(String _host, int _port, String _domain, String _user, String _password, String _shareAndDir, + boolean _replaceFile, boolean _useTempFile) throws IOException { this(new SmbShare(new SmbConfig(_host, _port, _domain, _user, _password, _shareAndDir))); - smbShare.setReplaceFile(_replaceFile); - smbShare.setUseTempFile(_useTempFile); + this.smbShare.setReplaceFile(_replaceFile); + this.smbShare.setUseTempFile(_useTempFile); } /** @@ -91,8 +94,10 @@ public class SmbSession implements Session { */ public SmbSession(SmbShare _smbShare) { Assert.notNull(_smbShare, "smbShare must not be null"); - smbShare = _smbShare; - logger.debug("New " + getClass().getName() + " created."); + this.smbShare = _smbShare; + if (logger.isDebugEnabled()) { + logger.debug("New " + getClass().getName() + " created."); + } } /** @@ -100,8 +105,8 @@ public class SmbSession implements Session { * @param _path path to a remote file or directory * @return true if delete successful, false if resource is non-existent * @throws IOException on error conditions returned by a CIFS server - * @see org.springframework.integration.file.remote.session.Session#remove(java.lang.String) */ + @Override public boolean remove(String _path) throws IOException { Assert.hasText(_path, "path must not be empty"); @@ -112,9 +117,10 @@ public class SmbSession implements Session { removeFile.delete(); removed = true; } - if (!removed) { + if (!removed && logger.isInfoEnabled()) { logger.info("Could not remove non-existing resource [" + _path + "]."); - } else if (logger.isInfoEnabled()) { + } + else if (logger.isInfoEnabled()) { logger.info("Successfully removed resource [" + _path + "]."); } return removed; @@ -126,29 +132,34 @@ public class SmbSession implements Session { * @param _path path to a remote directory * @return array of SmbFile objects * @throws IOException on error conditions returned by a CIFS server or if the remote resource is not a directory. - * @see org.springframework.integration.file.remote.session.Session#list(java.lang.String) */ + @Override public SmbFile[] list(String _path) throws IOException { SmbFile[] files = new SmbFile[0]; try { SmbFile smbDir = createSmbDirectoryObject(_path); if (!smbDir.exists()) { - logger.warn("Remote directory [" + _path + "] does not exist. Cannot list resources."); + if (logger.isWarnEnabled()) { + logger.warn("Remote directory [" + _path + "] does not exist. Cannot list resources."); + } return files; - } else if (!smbDir.isDirectory()) { + } + else if (!smbDir.isDirectory()) { throw new NestedIOException("Resource [" + _path + "] is not a directory. Cannot list resources."); } files = smbDir.listFiles(); - - } catch (SmbException _ex) { + } + catch (SmbException _ex) { throw new NestedIOException("Failed to list resources in [" + _path + "].", _ex); } - String msg = "Successfully listed " + files.length + " resource(s) in [" + _path + "]"; + if (logger.isDebugEnabled()) { - logger.debug(msg + ": " + Arrays.toString(files)); - } else { - logger.info(msg + "."); + logger.debug("Successfully listed " + files.length + " resource(s) in [" + _path + "]" + + ": " + Arrays.toString(files)); + } + else if (logger.isInfoEnabled()) { + logger.info("Successfully listed " + files.length + " resource(s) in [" + _path + "]" + "."); } return files; @@ -160,34 +171,36 @@ public class SmbSession implements Session { * @param _path path to a remote file * @param _outputStream output stream * @throws IOException on error conditions returned by a CIFS server or if the remote resource is not a file. - * @see org.springframework.integration.file.remote.session.Session#read(java.lang.String, java.io.OutputStream) */ + @Override public void read(String _path, OutputStream _outputStream) throws IOException { Assert.hasText(_path, "path must not be empty"); Assert.notNull(_outputStream, "outputStream must not be null"); try { - SmbFile remoteFile = createSmbFileObject(_path); if (!remoteFile.isFile()) { throw new NestedIOException("Resource [" + _path + "] is not a file."); } FileCopyUtils.copy(remoteFile.getInputStream(), _outputStream); - - } catch (SmbException _ex) { + } + catch (SmbException _ex) { throw new NestedIOException("Failed to read resource [" + _path + "].", _ex); } - logger.info("Successfully read resource [" + _path + "]."); + + if (logger.isInfoEnabled()) { + logger.info("Successfully read resource [" + _path + "]."); + } } /** * Writes contents of the specified {@link InputStream} to the remote resource - * specified by path. Remote directories are created implicitely as required. + * specified by path. Remote directories are created implicitly as required. * @param _inputStream input stream * @param _path remote path (of a file) to write to * @throws IOException on error conditions returned by a CIFS server - * @see org.springframework.integration.file.remote.session.Session#write(java.io.InputStream, java.lang.String) */ + @Override public void write(InputStream _inputStream, String _path) throws IOException { Assert.notNull(_inputStream, "inputStream must not be empty"); Assert.hasText(_path, "path must not be null"); @@ -198,35 +211,39 @@ public class SmbSession implements Session { SmbFile targetFile = createSmbFileObject(_path); - if (smbShare.isUseTempFile()) { + if (this.smbShare.isUseTempFile()) { - String tempFileName = _path + smbShare.newTempFileSuffix(); + String tempFileName = _path + this.smbShare.newTempFileSuffix(); SmbFile tempFile = createSmbFileObject(tempFileName); tempFile.createNewFile(); Assert.isTrue(tempFile.canWrite(), "Temporary file [" + tempFileName + "] is not writable."); FileCopyUtils.copy(_inputStream, tempFile.getOutputStream()); - if (targetFile.exists() && smbShare.isReplaceFile()) { + if (targetFile.exists() && this.smbShare.isReplaceFile()) { targetFile.delete(); } tempFile.renameTo(targetFile); - - } else { - + } + else { FileCopyUtils.copy(_inputStream, targetFile.getOutputStream()); - } - } catch (SmbException _ex) { + } + catch (SmbException _ex) { throw new NestedIOException("Failed to write resource [" + _path + "].", _ex); } - logger.info("Successfully wrote remote file [" + _path + "]."); + if (logger.isInfoEnabled()) { + logger.info("Successfully wrote remote file [" + _path + "]."); + } } /** * Convenience method to write a local file object to a remote location. - * @see org.springframework.integration.smb.session.SmbSession#write(InputStream, String) + * @param _file the local file + * @param _path the remote path to write to + * @return the {@link SmbFile} for remote file + * @throws IOException the IO exception */ public SmbFile write(File _file, String _path) throws IOException { return writeAndClose(new FileInputStream(_file), _path); @@ -234,7 +251,10 @@ public class SmbSession implements Session { /** * Convenience method to write a byte array to a remote location. - * @see org.springframework.integration.smb.session.SmbSession#write(InputStream, String) + * @param _contents the {@code byte[]} to write + * @param _path the remote file to write to + * @return the {@link SmbFile} for remote file + * @throws IOException the IO exception */ public SmbFile write(byte[] _contents, String _path) throws IOException { return writeAndClose(new ByteArrayInputStream(_contents), _path); @@ -247,19 +267,25 @@ public class SmbSession implements Session { * @param _path remote path to create * @return always true (error states are express by exceptions) * @throws IOException on error conditions returned by a CIFS server - * @see org.springframework.integration.file.remote.session.Session#mkdir(java.lang.String) */ + @Override public boolean mkdir(String _path) throws IOException { try { SmbFile dir = createSmbDirectoryObject(_path); if (!dir.exists()) { dir.mkdirs(); - logger.info("Successfully created remote directory [" + _path + "] in share [" + smbShare + "]."); - } else { - logger.info("Remote directory [" + _path + "] exists in share [" + smbShare + "]."); + if (logger.isInfoEnabled()) { + logger.info("Successfully created remote directory [" + _path + "] in share [" + this.smbShare + "]."); + } + } + else { + if (logger.isInfoEnabled()) { + logger.info("Remote directory [" + _path + "] exists in share [" + this.smbShare + "]."); + } } return true; - } catch (SmbException _ex) { + } + catch (SmbException _ex) { throw new NestedIOException("Failed to create directory [" + _path + "].", _ex); } } @@ -269,8 +295,8 @@ public class SmbSession implements Session { * @param _path remote path * @return true if exists, false otherwise * @throws IOException on error conditions returned by a CIFS server - * @see org.springframework.integration.file.remote.session.Session#exists(java.lang.String) */ + @Override public boolean exists(String _path) throws IOException { return createSmbFileObject(_path).exists(); } @@ -313,54 +339,93 @@ public class SmbSession implements Session { return null; } - /** - * Renames a remote resource. - * @param _pathFrom remote source path - * @param _pathTo remote target path - * @throws IOException on error conditions returned by a CIFS server - * @see org.springframework.integration.file.remote.session.Session#rename(java.lang.String, java.lang.String) - */ + @Override public void rename(String _pathFrom, String _pathTo) throws IOException { try { SmbFile smbFileFrom = createSmbFileObject(_pathFrom); SmbFile smbFileTo = createSmbFileObject(_pathTo); - if (smbShare.isReplaceFile() && smbFileTo.exists()) { + if (this.smbShare.isReplaceFile() && smbFileTo.exists()) { smbFileTo.delete(); } smbFileFrom.renameTo(smbFileTo); - } catch (SmbException _ex) { + } + catch (SmbException _ex) { throw new NestedIOException("Failed to rename [" + _pathFrom + "] to [" + _pathTo + "].", _ex); } - logger.info("Successfully renamed remote resource [" + _pathFrom + "] to [" + _pathTo + "]."); + if (logger.isInfoEnabled()) { + logger.info("Successfully renamed remote resource [" + _pathFrom + "] to [" + _pathTo + "]."); + } } - /** - * Closes this SMB session. - * @see org.springframework.integration.file.remote.session.Session#close() - */ + @Override + public void append(InputStream inputStream, String destination) throws IOException { + SmbFile smbFile = createSmbFileObject(destination); + OutputStream fileOutputStream = new SmbFileOutputStream(smbFile, true); + FileCopyUtils.copy(inputStream, fileOutputStream); + } + + @Override + public boolean rmdir(String directory) throws IOException { + SmbFile dir = createSmbDirectoryObject(directory); + try { + dir.delete(); + } + catch (SmbException e) { + if (logger.isWarnEnabled()) { + logger.info("Failed to remove remote directory [" + directory + "]: " + e); + } + return false; + } + if (logger.isInfoEnabled()) { + logger.info("Successfully removed remote directory [" + directory + "]."); + } + return true; + } + + @Override + public InputStream readRaw(String source) throws IOException { + SmbFile remoteFile = createSmbFileObject(source); + if (!remoteFile.isFile()) { + throw new NestedIOException("Resource [" + source + "] is not a file."); + } + return remoteFile.getInputStream(); + } + + @Override + public boolean finalizeRaw() throws IOException { + return true; + } + + @Override + public Object getClientInstance() { + return this.smbShare; + } + + @Override public void close() { - smbShare.doClose(); + this.smbShare.doClose(); } /** * Checks with this SMB session is open and ready for work by attempting * to list remote files and checking for error conditions.. * @return true if the session is open, false otherwise - * @see org.springframework.integration.file.remote.session.Session#isOpen() */ + @Override public boolean isOpen() { - if (!smbShare.isOpened()) { + if (!this.smbShare.isOpened()) { return false; } try { - smbShare.listFiles(); - } catch (Exception _ex) { + this.smbShare.listFiles(); + } + catch (Exception _ex) { close(); } - return smbShare.isOpened(); + return this.smbShare.isOpened(); } /** @@ -389,17 +454,18 @@ public class SmbSession implements Session { final String cleanedPath = StringUtils.cleanPath(path); if (!StringUtils.hasText(cleanedPath)) { - return smbShare; + return this.smbShare; } - SmbFile smbFile = new SmbFile(smbShare, cleanedPath); + SmbFile smbFile = new SmbFile(this.smbShare, cleanedPath); boolean appendFileSeparator = !cleanedPath.endsWith(SMB_FILE_SEPARATOR); if (appendFileSeparator) { try { - appendFileSeparator = smbFile.isDirectory() || (isDirectory != null && isDirectory); - } catch (SmbException ex) { - appendFileSeparator = false; + appendFileSeparator = smbFile.isDirectory() || (isDirectory != null && isDirectory); + } + catch (SmbException ex) { + appendFileSeparator = false; } } if (appendFileSeparator) { @@ -413,6 +479,9 @@ public class SmbSession implements Session { /** * Creates an SMB file object pointing to a remote file. + * @param _path the remote file path + * @return the {@link SmbFile} for remote path + * @throws IOException the IO exception */ public SmbFile createSmbFileObject(String _path) throws IOException { return createSmbFileObject(_path, null); @@ -420,6 +489,9 @@ public class SmbSession implements Session { /** * Creates an SMB file object pointing to a remote directory. + * @param _path the remote directory path + * @return the {@link SmbFile} for remote path + * @throws IOException the IO exception */ public SmbFile createSmbDirectoryObject(String _path) throws IOException { return createSmbFileObject(_path, true); @@ -441,9 +513,11 @@ public class SmbSession implements Session { Log log = LogFactory.getLog(SmbSession.class); if (log.isTraceEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "N"); - } else if (log.isDebugEnabled()) { + } + else if (log.isDebugEnabled()) { jcifs.Config.setProperty(sysPropLogLevel, "3"); - } else { + } + else { jcifs.Config.setProperty(sysPropLogLevel, "1"); } } diff --git a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java index 58ec31b..5454f98 100644 --- a/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java +++ b/spring-integration-smb/src/main/java/org/springframework/integration/smb/session/SmbSessionFactory.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,16 +13,18 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.session; import java.io.IOException; -import jcifs.smb.SmbFile; - import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; + import org.springframework.integration.file.remote.session.SessionFactory; +import jcifs.smb.SmbFile; + /** * The SMB session factory. * @@ -31,7 +33,7 @@ import org.springframework.integration.file.remote.session.SessionFactory; */ public class SmbSessionFactory extends SmbConfig implements SessionFactory { - private final Log logger = LogFactory.getLog(this.getClass()); + private static Log logger = LogFactory.getLog(SmbSessionFactory.class); public SmbSessionFactory() { logger.debug("New " + getClass().getName() + " created."); @@ -40,17 +42,20 @@ public class SmbSessionFactory extends SmbConfig implements SessionFactory Java Implementation - Each of the provided components will use the - org.springframework.smb.core.SmbExecutor + Each of the provided components use the + org.springframework.integration.smb.session.SmbSession class... diff --git a/spring-integration-smb/src/reference/docbook/index.xml b/spring-integration-smb/src/reference/docbook/index.xml index 53bc084..37060f4 100644 --- a/spring-integration-smb/src/reference/docbook/index.xml +++ b/spring-integration-smb/src/reference/docbook/index.xml @@ -23,7 +23,7 @@ Markus Spann - © SpringSource Inc., 2012 + Pivotal Software, Inc. All Rights Reserved., 2012-2017 @@ -35,7 +35,7 @@ For those who are already familiar with Spring Integration, this chapter - provides a brief overview of the new features of version 2.2. If you are + provides a brief overview of the new features of version 0.5. If you are interested in the changes and features, that were introduced in earlier versions, please take a look at chapter: diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTest.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java similarity index 88% rename from spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTest.java rename to spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java index ca75631..14bb03d 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTest.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/AbstractBaseTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb; import static org.junit.Assert.assertNotNull; @@ -31,6 +32,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Rule; import org.junit.rules.TestName; + import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; @@ -39,16 +41,16 @@ import org.springframework.util.StringUtils; * Assorted test utils for the library. * @author Markus Spann */ -public abstract class AbstractBaseTest { +public abstract class AbstractBaseTests { /** Instance logger. */ - private final Log logger = LogFactory.getLog(this.getClass()); + private final Log logger = LogFactory.getLog(this.getClass()); protected final Log getLogger() { return logger; } - @Rule // requires JUnit 4.7 or later + @Rule public final TestName testMethodName = new TestName(); private String getTestMethodName() { @@ -102,7 +104,8 @@ public abstract class AbstractBaseTest { FileOutputStream fos = new FileOutputStream(_path); try { FileCopyUtils.copy(_inputStream, fos); - } finally { + } + finally { fos.close(); } } @@ -230,7 +233,8 @@ public abstract class AbstractBaseTest { assertNotNull("File object is null.", _file); if (_exists) { assertTrue("File [" + _file.getAbsolutePath() + "] does not exist.", _file.exists()); - } else { + } + else { assertTrue("File [" + _file.getAbsolutePath() + "] exists.", !_file.exists()); } return _file; @@ -246,34 +250,23 @@ public abstract class AbstractBaseTest { * @param _testClass test class object * @param _methodNames String method names to invoke in order, no parameters expected */ - protected static void runTests(Class _testClass, String... _methodNames) { - AbstractBaseTest test; + protected static void runTests(Class _testClass, String... _methodNames) + throws Exception { + AbstractBaseTests test; Method[] methods = new Method[_methodNames.length]; String methodName = null; - try { - test = _testClass.newInstance(); - for (int i = 0; i < _methodNames.length; i++) { - methodName = _methodNames[i]; - methods[i] = _testClass.getMethod(methodName, (Class[]) null); - } - } catch (Exception _ex) { - System.err.println("Test setup failed for " + _testClass + "." + methodName + "()."); - _ex.printStackTrace(); - return; + test = _testClass.newInstance(); + for (int i = 0; i < _methodNames.length; i++) { + methodName = _methodNames[i]; + methods[i] = _testClass.getMethod(methodName, (Class[]) null); } Method method = null; - try { - for (int i = 0; i < methods.length; i++) { - method = methods[i]; - method.invoke(test, (Object[]) null); - } - - } catch (Exception _ex) { - System.err.println("Test execution failed for " + _testClass + "." + method.getName() + "."); - _ex.printStackTrace(); + for (int i = 0; i < methods.length; i++) { + method = methods[i]; + method.invoke(test, (Object[]) null); } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java index fd7e034..570dc5e 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbMessageHistoryTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,21 +13,25 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb; import static org.junit.Assert.assertEquals; import org.junit.Test; + import org.springframework.integration.endpoint.SourcePollingChannelAdapter; /** * @author Markus Spann * */ -public class SmbMessageHistoryTests extends AbstractBaseTest { +public class SmbMessageHistoryTests extends AbstractBaseTests { + @Test public void testMessageHistory() throws Exception { - SourcePollingChannelAdapter adapter = getApplicationContext().getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class); + SourcePollingChannelAdapter adapter = getApplicationContext() + .getBean("smbInboundChannelAdapter", SourcePollingChannelAdapter.class); assertEquals("smbInboundChannelAdapter", adapter.getComponentName()); assertEquals("smb:inbound-channel-adapter", adapter.getComponentType()); } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java index 291d1dd..9498ae5 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/SmbParserInboundTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb; import java.io.File; @@ -20,6 +21,7 @@ import java.io.File; import org.junit.After; import org.junit.Before; import org.junit.Test; + import org.springframework.beans.factory.BeanCreationException; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -27,7 +29,7 @@ import org.springframework.context.support.ClassPathXmlApplicationContext; * @author Markus Spann * */ -public class SmbParserInboundTests extends AbstractBaseTest { +public class SmbParserInboundTests extends AbstractBaseTests { @Before public void prepare() { @@ -46,7 +48,8 @@ public class SmbParserInboundTests extends AbstractBaseTest { @Test(expected = BeanCreationException.class) public void testLocalFilesAutoCreationFalse() throws Exception { assertFileNotExists(new File("test-temp/local-6")); - new ClassPathXmlApplicationContext(getApplicationContextXmlFile("-fail"), this.getClass()); + new ClassPathXmlApplicationContext(getApplicationContextXmlFile("-fail"), this.getClass()) + .close(); } @After @@ -54,7 +57,7 @@ public class SmbParserInboundTests extends AbstractBaseTest { delete("test-temp/local-10", "test-temp/local-6"); } - public static void main(String[] _args) { + public static void main(String[] _args) throws Exception { new SmbParserInboundTests().cleanUp(); runTests(SmbParserInboundTests.class, "testLocalFilesAutoCreationTrue", "testLocalFilesAutoCreationFalse"); } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java index 208cfa1..eef2ea6 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,10 +13,13 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.config; +import static org.hamcrest.Matchers.instanceOf; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -26,11 +29,11 @@ import java.util.concurrent.PriorityBlockingQueue; import org.junit.Test; import org.junit.runner.RunWith; + import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; -import org.springframework.integration.file.remote.session.CachingSessionFactory; import org.springframework.integration.smb.filters.SmbSimplePatternFileListFilter; import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizer; import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMessageSource; @@ -43,6 +46,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Markus Spann * @author Gunnar Hillert + * @author Artem Bilan */ @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @@ -52,7 +56,7 @@ public class SmbInboundChannelAdapterParserTests { ApplicationContext applicationContext; @Test(timeout = 100000) - public void testSmbInboundChannelAdapterComplete() throws Exception{ + public void testSmbInboundChannelAdapterComplete() throws Exception { final SourcePollingChannelAdapter adapter = this.applicationContext.getBean("smbInbound", SourcePollingChannelAdapter.class); final PriorityBlockingQueue queue = TestUtils.getPropertyValue(adapter, "source.fileSource.toBeReceived", PriorityBlockingQueue.class); @@ -63,39 +67,39 @@ public class SmbInboundChannelAdapterParserTests { assertNotNull(TestUtils.getPropertyValue(adapter, "poller")); assertEquals(applicationContext.getBean("smbChannel"), TestUtils.getPropertyValue(adapter, "outputChannel")); SmbInboundFileSynchronizingMessageSource inbound = - (SmbInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source"); + (SmbInboundFileSynchronizingMessageSource) TestUtils.getPropertyValue(adapter, "source"); SmbInboundFileSynchronizer fisync = - (SmbInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer"); + (SmbInboundFileSynchronizer) TestUtils.getPropertyValue(inbound, "synchronizer"); assertEquals(".working.tmp", TestUtils.getPropertyValue(fisync, "temporaryFileSuffix", String.class)); String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator"); assertNotNull(remoteFileSeparator); assertEquals("", remoteFileSeparator); SmbSimplePatternFileListFilter filter = (SmbSimplePatternFileListFilter) TestUtils.getPropertyValue(fisync, "filter"); assertNotNull(filter); - Object sessionFactory = TestUtils.getPropertyValue(fisync, "sessionFactory"); + Object sessionFactory = TestUtils.getPropertyValue(fisync, "remoteFileTemplate.sessionFactory"); assertTrue(SmbSessionFactory.class.isAssignableFrom(sessionFactory.getClass())); } - @Test(timeout = 10000) - public void cachingSessionFactoryByDefault() throws Exception{ + @Test + public void testNoCachingSessionFactoryByDefault() throws Exception { SourcePollingChannelAdapter adapter = applicationContext.getBean("simpleAdapter", SourcePollingChannelAdapter.class); - Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.sessionFactory"); - assertEquals(CachingSessionFactory.class, sessionFactory.getClass()); + Object sessionFactory = TestUtils.getPropertyValue(adapter, "source.synchronizer.remoteFileTemplate.sessionFactory"); + assertThat(sessionFactory, instanceOf(SmbSessionFactory.class)); SmbInboundFileSynchronizer fisync = - TestUtils.getPropertyValue(adapter, "source.synchronizer", SmbInboundFileSynchronizer.class); + TestUtils.getPropertyValue(adapter, "source.synchronizer", SmbInboundFileSynchronizer.class); String remoteFileSeparator = (String) TestUtils.getPropertyValue(fisync, "remoteFileSeparator"); assertNotNull(remoteFileSeparator); assertEquals("/", remoteFileSeparator); } @Test(timeout = 10000) - public void testSmbInboundChannelAdapterCompleteNoId() throws Exception{ + public void testSmbInboundChannelAdapterCompleteNoId() throws Exception { Map spcas = applicationContext.getBeansOfType(SourcePollingChannelAdapter.class); SourcePollingChannelAdapter adapter = null; for (String key : spcas.keySet()) { - if (!key.equals("smbInbound") && !key.equals("simpleAdapter")){ + if (!key.equals("smbInbound") && !key.equals("simpleAdapter")) { adapter = spcas.get(key); } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java index d2b4468..16c6f21 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbInboundOutboundSample.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,25 +13,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.config; import static org.junit.Assert.assertTrue; import java.io.File; +import org.junit.Ignore; import org.junit.Test; + import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; -import org.springframework.integration.MessageChannel; import org.springframework.integration.endpoint.EventDrivenConsumer; import org.springframework.integration.endpoint.SourcePollingChannelAdapter; import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.smb.AbstractBaseTest; +import org.springframework.integration.smb.AbstractBaseTests; import org.springframework.integration.smb.inbound.SmbInboundFileSynchronizingMessageSource; import org.springframework.integration.smb.session.SmbSession; import org.springframework.integration.smb.session.SmbSessionFactory; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.MessageChannel; +import org.springframework.messaging.support.GenericMessage; /** * System tests that perform SMB access without any mocking. @@ -43,12 +46,12 @@ import org.springframework.integration.test.util.TestUtils; * @author Markus Spann * @author Gunnar Hillert */ -public class SmbInboundOutboundSample extends AbstractBaseTest { +public class SmbInboundOutboundSample extends AbstractBaseTests { private static final String INBOUND_APPLICATION_CONTEXT_XML = "SmbInboundChannelAdapterSample-context.xml"; private static final String OUTBOUND_APPLICATION_CONTEXT_XML = "SmbOutboundChannelAdapterSample-context.xml"; - @org.junit.Ignore("Actual SMB share must be configured in file [" + INBOUND_APPLICATION_CONTEXT_XML + "].") + @Ignore("Actual SMB share must be configured in file [" + INBOUND_APPLICATION_CONTEXT_XML + "].") @Test public void testSmbInboundChannelAdapter() throws Exception { String testLocalDir = "test-temp/local-4/"; @@ -71,7 +74,8 @@ public class SmbInboundOutboundSample extends AbstractBaseTest { String[] fileNames = createTestFileNames(5); for (int i = 0; i < fileNames.length; i++) { - smbSession.write(("File [" + fileNames[i] + "] written by test case [" + getMethodName() + "].").getBytes(), testRemoteDir + fileNames[i]); + smbSession.write(("File [" + fileNames[i] + "] written by test case [" + getMethodName() + "].").getBytes(), + testRemoteDir + fileNames[i]); } // allow time for the files to arrive locally @@ -84,7 +88,7 @@ public class SmbInboundOutboundSample extends AbstractBaseTest { } - @org.junit.Ignore("Actual SMB share must be configured in file [" + OUTBOUND_APPLICATION_CONTEXT_XML + "].") + @Ignore("Actual SMB share must be configured in file [" + OUTBOUND_APPLICATION_CONTEXT_XML + "].") @Test public void testSmbOutboundChannelAdapter() throws Exception { String testRemoteDir = "test-temp/remote-8/"; @@ -93,7 +97,8 @@ public class SmbInboundOutboundSample extends AbstractBaseTest { String[] fileNames = createTestFileNames(5); for (int i = 0; i < fileNames.length; i++) { - writeToFile(("File [" + fileNames[i] + "] written by test case [" + getMethodName() + "].").getBytes(), testLocalDir + fileNames[i]); + writeToFile(("File [" + fileNames[i] + "] written by test case [" + getMethodName() + "].").getBytes(), + testLocalDir + fileNames[i]); } ApplicationContext ac = new ClassPathXmlApplicationContext(OUTBOUND_APPLICATION_CONTEXT_XML, this.getClass()); @@ -131,7 +136,7 @@ public class SmbInboundOutboundSample extends AbstractBaseTest { return fileNames; } - public static void main(String[] _args) { + public static void main(String[] _args) throws Exception { runTests(SmbInboundOutboundSample.class, "testSmbOutboundChannelAdapter", "testSmbInboundChannelAdapter"); } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java index eaac811..9b73422 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/config/SmbOutboundChannelAdapterParserTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,33 +13,34 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.config; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.util.Iterator; import java.util.Set; import org.junit.Test; + import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.channel.PublishSubscribeChannel; -import org.springframework.integration.core.MessageHandler; import org.springframework.integration.endpoint.EventDrivenConsumer; -import org.springframework.integration.file.remote.session.CachingSessionFactory; -import org.springframework.integration.smb.AbstractBaseTest; +import org.springframework.integration.smb.AbstractBaseTests; import org.springframework.integration.smb.session.SmbSessionFactory; import org.springframework.integration.test.util.TestUtils; +import org.springframework.messaging.MessageHandler; /** * @author Markus Spann * @author Gunnar Hillert - * @since 1.0 + * @author Artem Bilan */ -public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTest { +public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTests { @Test public void testSmbOutboundChannelAdapterComplete() throws Exception { @@ -53,15 +54,14 @@ public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTest { assertEquals("smbOutboundChannelAdapter", ((EventDrivenConsumer) consumer).getComponentName()); Object messageHandler = TestUtils.getPropertyValue(consumer, "handler"); - String remoteFileSeparator = (String) TestUtils.getPropertyValue(messageHandler, "remoteFileSeparator"); + String remoteFileSeparator = (String) TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.remoteFileSeparator"); assertNotNull(remoteFileSeparator); - assertEquals(".working.tmp", TestUtils.getPropertyValue(messageHandler, "temporaryFileSuffix", String.class)); + assertEquals(".working.tmp", TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.temporaryFileSuffix", String.class)); assertEquals(".", remoteFileSeparator); - assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(messageHandler, "fileNameGenerator")); - assertEquals("UTF-8", TestUtils.getPropertyValue(messageHandler, "charset")); - assertNotNull(TestUtils.getPropertyValue(messageHandler, "temporaryDirectory")); + assertEquals(ac.getBean("fileNameGenerator"), TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.fileNameGenerator")); + assertEquals("UTF-8", TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.charset")); - Object sessionFactoryProp = TestUtils.getPropertyValue(messageHandler, "sessionFactory"); + Object sessionFactoryProp = TestUtils.getPropertyValue(messageHandler, "remoteFileTemplate.sessionFactory"); assertEquals(SmbSessionFactory.class, sessionFactoryProp.getClass()); SmbSessionFactory smbSessionFactory = (SmbSessionFactory) sessionFactoryProp; @@ -71,20 +71,20 @@ public class SmbOutboundChannelAdapterParserTests extends AbstractBaseTest { // verify subscription order @SuppressWarnings("unchecked") - Set handlers = (Set) TestUtils.getPropertyValue(TestUtils.getPropertyValue(channel, "dispatcher"), "handlers"); + Set handlers = (Set) TestUtils.getPropertyValue( + TestUtils.getPropertyValue(channel, "dispatcher"), "handlers"); Iterator iterator = handlers.iterator(); - assertSame(TestUtils.getPropertyValue(ac.getBean("smbOutboundChannelAdapter2"), "handler"), iterator.next()); + assertSame(TestUtils.getPropertyValue(ac.getBean("smbOutboundChannelAdapter2"), "handler"), + iterator.next()); assertSame(messageHandler, iterator.next()); } @Test - public void cachingByDefault() { + public void noCachingByDefault() { ApplicationContext ac = new ClassPathXmlApplicationContext(getApplicationContextXmlFile(), this.getClass()); Object adapter = ac.getBean("simpleAdapter"); - Object sfProperty = TestUtils.getPropertyValue(adapter, "handler.sessionFactory"); - assertEquals(CachingSessionFactory.class, sfProperty.getClass()); - Object innerSfProperty = TestUtils.getPropertyValue(sfProperty, "sessionFactory"); - assertEquals(SmbSessionFactory.class, innerSfProperty.getClass()); + Object sfProperty = TestUtils.getPropertyValue(adapter, "handler.remoteFileTemplate.sessionFactory"); + assertEquals(SmbSessionFactory.class, sfProperty.getClass()); } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTest.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java similarity index 90% rename from spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTest.java rename to spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java index 998cc05..c577d4d 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTest.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/inbound/SmbInboundRemoteFileSystemSynchronizerTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.inbound; import static org.mockito.Mockito.doAnswer; @@ -24,27 +25,31 @@ import java.io.OutputStream; import java.util.ArrayList; import java.util.List; -import jcifs.smb.SmbFile; - import org.junit.Before; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; -import org.springframework.integration.smb.AbstractBaseTest; + +import org.springframework.integration.smb.AbstractBaseTests; import org.springframework.integration.smb.session.SmbSession; import org.springframework.integration.smb.session.SmbSessionFactory; +import jcifs.smb.SmbFile; + /** * @author Markus Spann * @author Gunnar Hillert * @since 1.0 */ -public class SmbInboundRemoteFileSystemSynchronizerTest extends AbstractBaseTest { +public class SmbInboundRemoteFileSystemSynchronizerTests extends AbstractBaseTests { + + private SmbSession smbSession; - private SmbSession smbSession; private SmbSessionFactory smbSessionFactory; - private String testLocalDir = "test-temp/local-9/"; - private String testRemoteDir = "test-temp/remote-9/"; + + private String testLocalDir = "test-temp/local-9/"; + + private String testRemoteDir = "test-temp/remote-9/"; @Before public void prepare() { @@ -105,6 +110,7 @@ public class SmbInboundRemoteFileSystemSynchronizerTest extends AbstractBaseTest smbFiles.add(file); doAnswer(new Answer() { + public Object answer(InvocationOnMock _invocation) throws Throwable { String path = (String) _invocation.getArguments()[0]; OutputStream os = (OutputStream) _invocation.getArguments()[1]; @@ -114,11 +120,12 @@ public class SmbInboundRemoteFileSystemSynchronizerTest extends AbstractBaseTest }).when(smbSession).read(Mockito.eq(testRemoteDir + "/" + fileName), Mockito.any(OutputStream.class)); } - when(smbSession.list(testRemoteDir)).thenReturn(smbFiles.toArray(new SmbFile[] {})); + when(smbSession.list(testRemoteDir)).thenReturn(smbFiles.toArray(new SmbFile[] { })); when(smbSession.remove(Mockito.anyString())).thenReturn(true); return smbSession; - } catch (Exception _ex) { + } + catch (Exception _ex) { throw new RuntimeException("Failed to create mock session.", _ex); } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTest.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java similarity index 76% rename from spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTest.java rename to spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java index 4904535..d2b6007 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTest.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/outbound/SmbSendingMessageHandlerTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2012 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.outbound; import static org.mockito.Mockito.doAnswer; @@ -24,28 +25,30 @@ import java.io.File; import java.io.InputStream; import java.io.OutputStream; -import jcifs.smb.SmbFile; - import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; + +import org.springframework.beans.factory.BeanFactory; import org.springframework.expression.common.LiteralExpression; -import org.springframework.integration.Message; -import org.springframework.integration.file.FileNameGenerator; import org.springframework.integration.file.remote.handler.FileTransferringMessageHandler; -import org.springframework.integration.message.GenericMessage; -import org.springframework.integration.smb.AbstractBaseTest; +import org.springframework.integration.smb.AbstractBaseTests; import org.springframework.integration.smb.session.SmbSession; import org.springframework.integration.smb.session.SmbSessionFactory; +import org.springframework.messaging.support.GenericMessage; + +import jcifs.smb.SmbFile; /** * @author Markus Spann + * @author Artem Bilan */ -public class SmbSendingMessageHandlerTest extends AbstractBaseTest { +public class SmbSendingMessageHandlerTests extends AbstractBaseTests { + + private SmbSession smbSession; - private SmbSession smbSession; private SmbSessionFactory smbSessionFactory; @Before @@ -66,12 +69,9 @@ public class SmbSendingMessageHandlerTest extends AbstractBaseTest { File file = createNewFile("remote-target-dir/handlerContent.test"); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(smbSessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); - handler.setFileNameGenerator(new FileNameGenerator() { - public String generateFileName(Message message) { - return "handlerContent.test"; - } - }); + handler.setFileNameGenerator(message -> "handlerContent.test"); handler.setAutoCreateDirectory(true); + handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage("hello")); assertFileExists(file); @@ -82,11 +82,8 @@ public class SmbSendingMessageHandlerTest extends AbstractBaseTest { File file = createNewFile("remote-target-dir/handlerContent.test"); FileTransferringMessageHandler handler = new FileTransferringMessageHandler(smbSessionFactory); handler.setRemoteDirectoryExpression(new LiteralExpression("remote-target-dir")); - handler.setFileNameGenerator(new FileNameGenerator() { - public String generateFileName(Message message) { - return "handlerContent.test"; - } - }); + handler.setFileNameGenerator(message -> "handlerContent.test"); + handler.setBeanFactory(mock(BeanFactory.class)); handler.afterPropertiesSet(); handler.handleMessage(new GenericMessage("hello".getBytes())); assertFileExists(file); @@ -116,6 +113,7 @@ public class SmbSendingMessageHandlerTest extends AbstractBaseTest { when(smbSession.list(Mockito.anyString())).thenReturn(new SmbFile[0]); doAnswer(new Answer() { + public Object answer(InvocationOnMock _invocation) throws Throwable { String path = (String) _invocation.getArguments()[0]; OutputStream os = (OutputStream) _invocation.getArguments()[1]; @@ -124,20 +122,19 @@ public class SmbSendingMessageHandlerTest extends AbstractBaseTest { } }).when(smbSession).read(Mockito.anyString(), Mockito.any(OutputStream.class)); - doAnswer(new Answer() { - public Object answer(InvocationOnMock _invocation) throws Throwable { - InputStream inputStream = (InputStream) _invocation.getArguments()[0]; - String path = (String) _invocation.getArguments()[1]; - writeToFile(inputStream, path); - return null; - } - - }).when(smbSession).write(Mockito.any(InputStream.class), Mockito.anyString()); + doAnswer(_invocation -> { + InputStream inputStream = (InputStream) _invocation.getArguments()[0]; + String path = (String) _invocation.getArguments()[1]; + writeToFile(inputStream, path); + return null; + }).when(smbSession) + .write(Mockito.any(InputStream.class), Mockito.anyString()); // when(smbSession.write(Mockito.any(byte[].class), Mockito.anyString())).thenReturn(null); // when(smbSession.write(Mockito.any(File.class), Mockito.anyString())).thenReturn(null); doAnswer(new Answer() { + public Object answer(InvocationOnMock _invocation) throws Throwable { String path = (String) _invocation.getArguments()[0]; new File(path).mkdirs(); @@ -145,20 +142,20 @@ public class SmbSendingMessageHandlerTest extends AbstractBaseTest { } }).when(smbSession).mkdir(Mockito.anyString()); - doAnswer(new Answer() { - public Object answer(InvocationOnMock _invocation) throws Throwable { - String pathFrom = (String) _invocation.getArguments()[0]; - String pathTo = (String) _invocation.getArguments()[1]; - new File(pathFrom).renameTo(new File(pathTo)); - return null; - } - }).when(smbSession).rename(Mockito.anyString(), Mockito.anyString()); + doAnswer(_invocation -> { + String pathFrom = (String) _invocation.getArguments()[0]; + String pathTo = (String) _invocation.getArguments()[1]; + new File(pathFrom).renameTo(new File(pathTo)); + return null; + }).when(smbSession) + .rename(Mockito.anyString(), Mockito.anyString()); doNothing().when(smbSession).close(); when(smbSession.isOpen()).thenReturn(true); return smbSession; - } catch (Exception _ex) { + } + catch (Exception _ex) { throw new RuntimeException("Failed to create mock session.", _ex); } } diff --git a/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTest.java b/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTests.java similarity index 94% rename from spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTest.java rename to spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTests.java index 0127c9f..9a2e3b2 100644 --- a/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTest.java +++ b/spring-integration-smb/src/test/java/org/springframework/integration/smb/session/SmbSessionTests.java @@ -1,5 +1,5 @@ -/** - * Copyright 2002-2013 the original author or authors. +/* + * Copyright 2012-2017 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. @@ -13,26 +13,24 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package org.springframework.integration.smb.session; +import static org.junit.Assert.assertEquals; + import java.io.IOException; -import jcifs.smb.SmbFile; -import static org.junit.Assert.assertEquals; - import org.junit.Test; +import jcifs.smb.SmbFile; + /** * * @author Gunnar Hillert * */ -public class SmbSessionTest { +public class SmbSessionTests { - /** - * Test Case reproduces INTEXT-37 (https://jira.springsource.org/browse/INTEXT-37) - * @throws IOException - */ @Test public void testCreateSmbFileObjectWithBackSlash1() throws IOException { diff --git a/spring-integration-smb/src/test/resources/log4j.properties b/spring-integration-smb/src/test/resources/log4j.properties index 0f8376e..4e677ad 100644 --- a/spring-integration-smb/src/test/resources/log4j.properties +++ b/spring-integration-smb/src/test/resources/log4j.properties @@ -4,6 +4,5 @@ log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %t %c{2}:%L - %m%n -log4j.category.org.springframework=WARN -log4j.category.org.springframework.integration=DEBUG -log4j.category.org.springframework.integration.smb=DEBUG +log4j.category.org.springframework.integration=WARN +log4j.category.org.springframework.integration.smb=WARN