Java - Error with Spring Integration Mock SftpServer

I am following this post about making a mock sftp server for tests with spring. https://dzone.com/articles/spring-integration-mock-0. This consists of a setup of a mock sftp server, followed by putting a file there with a string as a content. The test is executed with the command:

$ mvn -Dtest=SftpRetrieveFileTest test

And the error I get is:

java.util.FormatFlagsConversionMismatchException: Conversion = s, Flags = #

By commenting blocks of code I determined that the error is caused when the file is put into the server, with these lines:

String uploadedFileName = "uploadFile";
sftpChannel.put(new ByteArrayInputStream(testFileContents.getBytes()), uploadedFileName);

I've already seen some workarounds that say that it may be a problem of the version of java (some said that it worked in 1.6 but not with 1.7, which I'm using). The complete project can be found and cloned from https://github.com/skprasadu/junit-testing-ftpflow-in-spring-integration.

Thank you.

Upvotes: 1

Views: 1004

Answers (1)

M. Rizzo
M. Rizzo

Reputation: 2271

I just pulled down the project and ran it under 1.6 and 1.8. The test runs fine under 1.6. It does not work under 1.8 and returns the same error you are seeing under 1.7. The workarounds are accurate. You should switch to using 1.6. It's a result of code using the String.fomat() method and # tag being passed to the format. There is actually a bug logged against the apache SSHD server project (RE: SSHD-104). This issue was addressed in version 0.6.0 of the project. So your other option is to change your maven dependency from

<dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-core</artifactId>
        <version>0.5.0</version>
</dependency>  

to

<dependency>
        <groupId>org.apache.sshd</groupId>
        <artifactId>sshd-core</artifactId>
        <version>0.6.0</version>
</dependency>

Then the project/test should work fine under JDK 1.7 as well.

Upvotes: 1

Related Questions