Upgrade dependencies and various fixes

* Remove usage of removed `org.springframework.util.SocketUtils`
in favor of OS-selected port
* Migrate mail tests to Greenmail instead of already obsolete (and soon to be removed)
`org.springframework.integration.test.mail.TestMailServer`
This commit is contained in:
Artem Bilan
2022-03-24 12:02:16 -04:00
parent db9db657a3
commit 1aa24b6577
78 changed files with 283 additions and 573 deletions

View File

@@ -137,14 +137,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -138,14 +138,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -159,14 +159,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -156,14 +156,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -131,14 +131,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -117,6 +117,12 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.icegreen</groupId>
<artifactId>greenmail</artifactId>
<version>2.0.0-alpha-2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
@@ -159,14 +165,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,7 +26,6 @@ import org.apache.commons.net.ftp.FTPFile;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.mail.MailProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.dsl.IntegrationFlow;
@@ -34,6 +33,7 @@ import org.springframework.integration.dsl.IntegrationFlows;
import org.springframework.integration.dsl.Pollers;
import org.springframework.integration.file.FileHeaders;
import org.springframework.integration.file.FileWritingMessageHandler;
import org.springframework.integration.file.dsl.FileWritingMessageHandlerSpec;
import org.springframework.integration.file.dsl.Files;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.file.splitter.FileSplitter;
@@ -67,11 +67,11 @@ public class Application {
@Bean
public IntegrationFlow fromFile() {
return IntegrationFlows.from(
Files.inboundAdapter(new File("/tmp/in"))
.preventDuplicates(false)
.patternFilter("*.txt"), e -> e.poller(Pollers.fixedDelay(5000)
.errorChannel("tfrErrors.input"))
.id("fileInboundChannelAdapter"))
Files.inboundAdapter(new File("/tmp/in"))
.preventDuplicates(false)
.patternFilter("*.txt"), e -> e.poller(Pollers.fixedDelay(5000)
.errorChannel("tfrErrors.input"))
.id("fileInboundChannelAdapter"))
.handle(Files.splitter(true, true))
.<Object, Class<?>>route(Object::getClass, m -> m
.channelMapping(FileSplitter.FileMarker.class, "markers.input")
@@ -90,11 +90,10 @@ public class Application {
}
@Bean
public FileWritingMessageHandler fileOut() {
public FileWritingMessageHandlerSpec fileOut() {
return Files.outboundAdapter("'/tmp/out'")
.appendNewLine(true)
.fileNameExpression("payload.substring(1, 4) + '.txt'")
.get();
.fileNameExpression("payload.substring(1, 4) + '.txt'");
}
/**
@@ -106,7 +105,7 @@ public class Application {
@Bean
public IntegrationFlow markers() {
return f -> f.<FileSplitter.FileMarker>filter(m -> m.getMark().equals(FileSplitter.FileMarker.Mark.END),
e -> e.id("markerFilter"))
e -> e.id("markerFilter"))
.publishSubscribeChannel(s -> s
// first trigger file flushes
@@ -133,7 +132,7 @@ public class Application {
.enrichHeaders(Mail.headers()
.subject("File successfully split and transferred")
.from("foo@bar")
.toFunction(m -> new String[] { "bar@baz" }))
.toFunction(m -> new String[]{ "bar@baz" }))
.enrichHeaders(h -> h.header(EMAIL_SUCCESS_SUFFIX, ".success"))
.channel("toMail.input")));
}
@@ -176,12 +175,12 @@ public class Application {
.enrichHeaders(Mail.headers()
.subject("File split and transfer failed")
.from("foo@bar")
.toFunction(m -> new String[] { "bar@baz" }))
.toFunction(m -> new String[]{ "bar@baz" }))
.enrichHeaders(h -> h.header(EMAIL_SUCCESS_SUFFIX, ".failed")
.headerExpression(FileHeaders.ORIGINAL_FILE, "payload.failedMessage.headers['"
+ FileHeaders.ORIGINAL_FILE + "']"))
.<MessagingException, String>transform(p ->
p.getFailedMessage().getPayload().toString() + "\n" + getStackTraceAsString(p))
p.getFailedMessage().getPayload() + "\n" + getStackTraceAsString(p))
.channel("toMail.input");
}
@@ -189,7 +188,7 @@ public class Application {
public IntegrationFlow toMail() {
return f -> f
.handle(Mail.outboundAdapter(this.mailProperties.getHost())
// .javaMailProperties(b -> b.put("mail.debug", "true"))
// .javaMailProperties(b -> b.put("mail.debug", "true"))
.port(this.mailProperties.getPort())
.credentials(this.mailProperties.getUsername(), this.mailProperties.getPassword()),
e -> e.id("mailOut").advice(afterMailAdvice()));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -30,15 +30,14 @@ import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import org.apache.commons.io.FileUtils;
import org.apache.commons.net.ftp.FTPFile;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
@@ -49,19 +48,22 @@ import org.springframework.integration.endpoint.SourcePollingChannelAdapter;
import org.springframework.integration.file.remote.session.Session;
import org.springframework.integration.file.remote.session.SessionFactory;
import org.springframework.integration.test.context.SpringIntegrationTest;
import org.springframework.integration.test.mail.TestMailServer;
import org.springframework.integration.test.mail.TestMailServer.SmtpServer;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.junit4.SpringRunner;
@RunWith(SpringRunner.class)
import com.icegreen.greenmail.store.FolderException;
import com.icegreen.greenmail.util.GreenMail;
import com.icegreen.greenmail.util.ServerSetup;
import com.icegreen.greenmail.util.ServerSetupTest;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeMessage;
@SpringBootTest(properties = "spring.main.allow-bean-definition-overriding=true")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
@SpringIntegrationTest(noAutoStartup = "fileInboundChannelAdapter")
public class ApplicationTests {
private static final SmtpServer smtpServer = TestMailServer.smtp(0);
private static GreenMail mailServer;
@Autowired
private Session<FTPFile> session;
@@ -69,23 +71,31 @@ public class ApplicationTests {
@Autowired
private SourcePollingChannelAdapter fileInboundChannelAdapter;
@BeforeClass
@BeforeAll
public static void setup() {
ServerSetup smtp = ServerSetupTest.SMTP.dynamicPort();
smtp.setServerStartupTimeout(10000);
mailServer = new GreenMail(smtp);
mailServer.setUser("bar@bar@baz", "user", "pw");
mailServer.start();
// Configure the boot property to send email to the test email server.
System.setProperty("spring.mail.port", Integer.toString(smtpServer.getPort()));
System.setProperty("spring.mail.port", Integer.toString(mailServer.getSmtp().getPort()));
}
@Before
public void beforeTest() throws IOException {
smtpServer.getMessages().clear();
tearDown();
@AfterAll
static void tearDown() {
mailServer.stop();
}
@BeforeEach
public void beforeTest() throws FolderException, IOException {
mailServer.purgeEmailFromAllMailboxes();
cleanup();
this.fileInboundChannelAdapter.start();
}
@After
public void tearDown() throws IOException {
@AfterEach
public void cleanup() throws IOException {
File inDir = new File("/tmp/in");
if (inDir.exists()) {
FileUtils.cleanDirectory(inDir);
@@ -97,22 +107,21 @@ public class ApplicationTests {
}
}
@SuppressWarnings("unchecked")
@Test
public void testSuccess() throws Exception {
String message = runTest(false);
assertThat(message).contains("File successfully split and transferred");
assertThat(message).contains(TestUtils.applySystemFileSeparator("/tmp/in/foo.txt"));
MimeMessage message = runTest(false);
assertThat(message.getSubject()).isEqualTo("File successfully split and transferred");
assertThat(message.getContent()).asString().contains(TestUtils.applySystemFileSeparator("/tmp/in/foo.txt"));
}
@Test
public void testFailure() throws Exception {
willThrow(new RuntimeException("fail test exception"))
.given(this.session).write(any(InputStream.class), eq("foo/002.txt.writing"));
String message = runTest(true);
assertThat(message).contains("File split and transfer failed");
assertThat(message).contains("fail test exception");
assertThat(message).contains(TestUtils.applySystemFileSeparator("/tmp/out/002.txt"));
MimeMessage message = runTest(true);
assertThat(message.getSubject()).isEqualTo("File split and transfer failed");
assertThat(message.getContent()).asString().contains("fail test exception");
assertThat(message.getContent()).asString().contains(TestUtils.applySystemFileSeparator("/tmp/out/002.txt"));
}
/*
@@ -121,7 +130,7 @@ public class ApplicationTests {
* Verify the input file was renamed based on success/failure.
* Verify the email was sent.
*/
private String runTest(boolean fail) throws Exception {
private MimeMessage runTest(boolean fail) throws Exception {
File in = new File("/tmp/in/", "foo");
FileOutputStream fos = new FileOutputStream(in);
fos.write("*002,foo,bar\n*006,baz,qux\n*009,fiz,buz\n".getBytes());
@@ -175,20 +184,18 @@ public class ApplicationTests {
verify(this.session).rename("foo/009.txt.writing", "foo/009.txt");
}
String message = verifyMail();
assertThat(message).contains("From: foo@bar");
assertThat(message).contains("To: bar@baz");
MimeMessage message = verifyMail();
assertThat(message.getFrom()).containsOnly(new InternetAddress("foo@bar"));
assertThat(message.getRecipients(MimeMessage.RecipientType.TO)).containsOnly(new InternetAddress("bar@baz"));
return message;
}
public String verifyMail() throws Exception {
List<String> messages = smtpServer.getMessages();
int n = 0;
while (n++ < 100 && messages.size() < 1) {
Thread.sleep(100);
}
assertThat(messages).hasSize(1);
return messages.get(0);
public MimeMessage verifyMail() {
mailServer.waitForIncomingEmail(10000, 1);
MimeMessage[] mail = mailServer.getReceivedMessagesForDomain("baz");
assertThat(mail).hasSize(1);
MimeMessage message = mail[0];
return message;
}
/**

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -325,14 +325,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -148,14 +148,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -137,14 +137,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -153,14 +153,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -150,14 +150,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -186,14 +186,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -155,14 +155,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -131,14 +131,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -155,14 +155,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -155,14 +155,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -137,14 +137,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -143,14 +143,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -143,14 +143,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -143,14 +143,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2018 the original author or authors.
* Copyright 2018-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -98,7 +98,7 @@ public class TcpBroadcastApplication {
}
/*
* Excutor for clients.
* Executor for clients.
*/
@Bean
public ThreadPoolTaskExecutor exec() {

View File

@@ -137,14 +137,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,15 +16,14 @@
package org.springframework.integration.samples.tcpclientserver;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import org.springframework.context.support.GenericXmlApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.util.SocketUtils;
/**
* Demonstrates the use of a gateway as an entry point into the integration flow.
@@ -50,12 +49,11 @@ import org.springframework.util.SocketUtils;
*/
public final class Main {
private static final String AVAILABLE_SERVER_SOCKET = "availableServerSocket";
/**
* Prevent instantiation.
*/
private Main() {}
private Main() {
}
/**
* Load the Spring Integration Application Context
@@ -66,22 +64,28 @@ public final class Main {
final Scanner scanner = new Scanner(System.in);
System.out.println("\n========================================================="
+ "\n "
+ "\n Welcome to the Spring Integration "
+ "\n TCP-Client-Server Sample! "
+ "\n "
+ "\n For more information please visit: "
+ "\n https://www.springsource.org/spring-integration/ "
+ "\n "
+ "\n=========================================================");
System.out.println("""
final GenericXmlApplicationContext context = Main.setupContext();
=========================================================
\s
Welcome to the Spring Integration \s
TCP-Client-Server Sample! \s
\s
For more information please visit: \s
https://www.springsource.org/spring-integration/ \s
\s
=========================================================""");
final ConfigurableApplicationContext context = Main.setupContext();
final SimpleGateway gateway = context.getBean(SimpleGateway.class);
final AbstractServerConnectionFactory crLfServer = context.getBean(AbstractServerConnectionFactory.class);
final AbstractClientConnectionFactory client = context.getBean(AbstractClientConnectionFactory.class);
final AbstractEndpoint outGateway = context.getBean("outGateway", AbstractEndpoint.class);
System.out.print("Waiting for server to accept connections...");
TestingUtilities.waitListening(crLfServer, 10000L);
client.setPort(crLfServer.getPort());
outGateway.start();
System.out.println("running.\n\n");
System.out.println("Please enter some text and press <enter>: ");
@@ -107,32 +111,13 @@ public final class Main {
}
System.out.println("Exiting application...bye.");
context.close();
System.exit(0);
}
public static GenericXmlApplicationContext setupContext() {
final GenericXmlApplicationContext context = new GenericXmlApplicationContext();
if (System.getProperty(AVAILABLE_SERVER_SOCKET) == null) {
System.out.print("Detect open server socket...");
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
final Map<String, Object> sockets = new HashMap<>();
sockets.put(AVAILABLE_SERVER_SOCKET, availableServerSocket);
final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);
context.getEnvironment().getPropertySources().addLast(propertySource);
}
System.out.println("using port " + context.getEnvironment().getProperty(AVAILABLE_SERVER_SOCKET));
context.load("classpath:META-INF/spring/integration/tcpClientServerDemo-context.xml");
context.registerShutdownHook();
context.refresh();
return context;
public static ConfigurableApplicationContext setupContext() {
return new ClassPathXmlApplicationContext("META-INF/spring/integration/tcpClientServerDemo-context.xml");
}
}

View File

@@ -27,6 +27,7 @@
<int:channel id="input"/>
<int-ip:tcp-outbound-gateway id="outGateway"
auto-startup="false"
request-channel="input"
reply-channel="clientBytes2StringChannel"
connection-factory="client"
@@ -40,7 +41,7 @@
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
port="${availableServerSocket:0}"/>
port="0"/>
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"

View File

@@ -57,7 +57,7 @@
<int-ip:tcp-connection-factory id="crLfServer"
type="server"
port="${availableServerSocket:0}"/>
port="0"/>
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="crLfServer"

View File

@@ -48,7 +48,7 @@
formatted with the Stx-Etx bytes. -->
<int-ip:tcp-connection-factory id="serverConnectionFactory"
type="server"
port="${availableServerSocket:0}"
port="0"
serializer="connectionSerializeDeserialize"
deserializer="connectionSerializeDeserialize"/>

View File

@@ -17,7 +17,7 @@
formatted with the Stx-Etx bytes. -->
<int-ip:tcp-connection-factory id="serverConnectionFactory"
type="server"
port="${availableServerSocket:0}"
port="0"
single-use="true"
so-linger="10000"
serializer="connectionSerializeDeserialize"

View File

@@ -143,14 +143,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -141,14 +141,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -127,14 +127,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -138,14 +138,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -168,14 +168,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -131,14 +131,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -38,7 +38,7 @@ allprojects {
maven { url 'https://repo.spring.io/release' }
maven { url 'https://repo.spring.io/milestone' }
maven { url 'https://repo.spring.io/snapshot' }
// maven { url 'https://repo.spring.io/libs-staging-local' }
maven { url 'https://repo.spring.io/libs-staging-local' }
}
}
@@ -260,11 +260,11 @@ subprojects { subproject ->
postgresVersion = '42.2.14'
slf4jVersion = '1.7.30'
springCloudVersion = '2022.0.0-SNAPSHOT'
springIntegrationVersion = '6.0.0-M1'
springIntegrationVersion = '6.0.0-M2'
springIntegrationSocialTwiterVersion = '1.0.1.BUILD-SNAPSHOT'
springIntegrationSplunkVersion = '1.2.0.BUILD-SNAPSHOT'
springVersion = '6.0.0-M2'
springSecurityVersion = '6.0.0-M1'
springVersion = '6.0.0-M3'
springSecurityVersion = '6.0.0-M2'
springWebFlowVersion = '2.3.3.RELEASE'
testcontainersVersion = '1.16.2'
tilesJspVersion = '2.2.1'
@@ -1494,6 +1494,7 @@ project('file-split-ftp') {
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.springframework.integration:spring-integration-test'
testImplementation "com.icegreen:greenmail:2.0.0-alpha-2"
}
springBoot {

View File

@@ -149,14 +149,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -149,14 +149,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -171,14 +171,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -143,14 +143,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -1,236 +0,0 @@
/*
* Copyright 2002-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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.mailattachments;
import org.springframework.integration.samples.mailattachments.support.EmailFragment;
/**
* Test to verify the correct parsing of Email Messages.
*
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.2
*/
public class MimeMessageParsingTest {
/*
private static final Log LOGGER = LogFactory.getLog(MimeMessageParsingTest.class);
private Wiser wiser;
private int wiserPort;
@Before
public void startWiser() {
this.wiserPort = SocketUtils.findAvailableTcpPort(2500);
wiser = new Wiser();
wiser.setPort(this.wiserPort);
wiser.start();
LOGGER.info("Wiser was started.");
}
*/
/**
* This test will create a Mime Message that contains an Attachment, send it
* to an SMTP Server (Using Wiser) and retrieve and process the Mime Message.
*
* This test verifies that the parsing of the retrieved Mime Message is
* successful and that the correct number of {@link EmailFragment}s is created.
*//*
@Test
public void testProcessingOfEmailAttachments() {
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(this.wiserPort);
final MimeMessage message = mailSender.createMimeMessage();
final String pictureName = "picture.png";
final ByteArrayResource byteArrayResource = getFileData(pictureName);
try {
final MimeMessageHelper helper = new MimeMessageHelper(message, true);
helper.setFrom("testfrom@springintegration.org");
helper.setTo("testto@springintegration.org");
helper.setSubject("Parsing of Attachments");
helper.setText("Spring Integration Rocks!");
helper.addAttachment(pictureName, byteArrayResource, "image/png");
}
catch (MessagingException e) {
throw new MailParseException(e);
}
mailSender.send(message);
final List<WiserMessage> wiserMessages = wiser.getMessages();
Assert.assertTrue(wiserMessages.size() == 1);
boolean foundTextMessage = false;
boolean foundPicture = false;
for (WiserMessage wiserMessage : wiserMessages) {
final List<EmailFragment> emailFragments = new ArrayList<>();
try {
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
}
catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving Mime Message.");
}
Assert.assertTrue(emailFragments.size() == 2);
for (EmailFragment emailFragment : emailFragments) {
if ("picture.png".equals(emailFragment.getFilename())) {
foundPicture = true;
}
if ("message.txt".equals(emailFragment.getFilename())) {
foundTextMessage = true;
}
}
Assert.assertTrue(foundPicture);
Assert.assertTrue(foundTextMessage);
}
}
*/
/**
* This test will create a Mime Message that in return contains another
* mime message. The nested mime message contains an attachment.
*
* The root message consist of both HTML and Text message.
*
*//*
@Test
public void testProcessingOfNestedEmailAttachments() {
final JavaMailSenderImpl mailSender = new JavaMailSenderImpl();
mailSender.setPort(this.wiserPort);
final MimeMessage rootMessage = mailSender.createMimeMessage();
try {
final MimeMessageHelper messageHelper = new MimeMessageHelper(rootMessage, true);
messageHelper.setFrom("testfrom@springintegration.org");
messageHelper.setTo("testto@springintegration.org");
messageHelper.setSubject("Parsing of Attachments");
messageHelper.setText("Spring Integration Rocks!", "Spring Integration <b>Rocks</b>!");
final String pictureName = "picture.png";
final ByteArrayResource byteArrayResource = getFileData(pictureName);
messageHelper.addInline("picture12345", byteArrayResource, "image/png");
}
catch (MessagingException e) {
throw new MailParseException(e);
}
mailSender.send(rootMessage);
final List<WiserMessage> wiserMessages = wiser.getMessages();
Assert.assertTrue(wiserMessages.size() == 1);
boolean foundTextMessage = false;
boolean foundPicture = false;
boolean foundHtmlMessage = false;
for (WiserMessage wiserMessage : wiserMessages) {
List<EmailFragment> emailFragments = new ArrayList<>();
try {
final MimeMessage mailMessage = wiserMessage.getMimeMessage();
EmailParserUtils.handleMessage(null, mailMessage, emailFragments);
} catch (MessagingException e) {
throw new IllegalStateException("Error while retrieving Mime Message.");
}
Assert.assertTrue(emailFragments.size() == 3);
for (EmailFragment emailFragment : emailFragments) {
if ("<picture12345>".equals(emailFragment.getFilename())) {
foundPicture = true;
}
if ("message.txt".equals(emailFragment.getFilename())) {
foundTextMessage = true;
}
if ("message.html".equals(emailFragment.getFilename())) {
foundHtmlMessage = true;
}
}
Assert.assertTrue(foundPicture);
Assert.assertTrue(foundTextMessage);
Assert.assertTrue(foundHtmlMessage);
}
}
private ByteArrayResource getFileData(String filename) {
final InputStream attachmentInputStream = MimeMessageParsingTest.class.getResourceAsStream(filename);
Assert.assertNotNull("Resource not found: " + filename, attachmentInputStream);
ByteArrayResource byteArrayResource = null;
try {
byteArrayResource = new ByteArrayResource(IOUtils.toByteArray(attachmentInputStream));
attachmentInputStream.close();
}
catch (IOException e1) {
Assert.fail();
}
return byteArrayResource;
}
@After
public void stopWiser() {
wiser.stop();
LOGGER.info("Wiser stopped.");
}
*/
}

View File

@@ -180,14 +180,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -180,14 +180,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -95,13 +95,13 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>compile</scope>
</dependency>
<dependency>
@@ -211,14 +211,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -159,14 +159,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -138,14 +138,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -132,14 +132,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -144,14 +144,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -138,14 +138,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2020 the original author or authors.
* Copyright 2020-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -33,9 +33,11 @@ import org.springframework.lang.Nullable;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.ChannelInterceptor;
import org.springframework.test.annotation.DirtiesContext;
@SpringBootTest
@SpringIntegrationTest(noAutoStartup = { "client1Adapter", "client2Adapter" })
@DirtiesContext
class TcpAsyncBiDirectionalApplicationTests {
@Autowired

View File

@@ -126,14 +126,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -36,7 +36,7 @@
<ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="${availableServerSocket}"
port="#{server.port}"
single-use="false"
serializer="fastestWireFormatSerializer"
deserializer="fastestWireFormatSerializer"
@@ -47,6 +47,7 @@
<ip:tcp-outbound-channel-adapter id="outAdapter.client"
order="2"
channel="input"
auto-startup="false"
connection-factory="client" /> <!-- Collaborator -->
<!-- Also send a copy to the custom aggregator for correlation and
@@ -56,9 +57,10 @@
<bridge input-channel="input" output-channel="toAggregator.client"
order="1"/>
<!-- Asynch receive reply -->
<!-- Async receive reply -->
<ip:tcp-inbound-channel-adapter id="inAdapter.client"
channel="toAggregator.client"
auto-startup="false"
connection-factory="client" /> <!-- Collaborator -->
<!-- dataType attribute invokes the conversion service, if necessary -->
@@ -84,7 +86,7 @@
<ip:tcp-connection-factory id="server"
type="server"
port="${availableServerSocket}"
port="0"
using-nio="true"
serializer="fastestWireFormatSerializer"
deserializer="fastestWireFormatSerializer" />

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2018 the original author or authors.
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,31 +16,28 @@
package org.springframework.integration.samples.tcpclientserver;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.integration.endpoint.AbstractEndpoint;
import org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.AbstractServerConnectionFactory;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.samples.tcpclientserver.support.CustomTestContextLoader;
import org.springframework.messaging.MessagingException;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
/**
@@ -56,9 +53,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
* @since 2.1
*
*/
@ContextConfiguration(loader = CustomTestContextLoader.class,
locations = { "/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml" })
@RunWith(SpringJUnit4ClassRunner.class)
@SpringJUnitConfig(locations = "/META-INF/spring/integration/tcpClientServerDemo-conversion-context.xml")
@DirtiesContext
public class TcpClientServerDemoTest {
@@ -68,15 +63,31 @@ public class TcpClientServerDemoTest {
@Autowired
AbstractServerConnectionFactory crLfServer;
@Before
@Autowired
AbstractClientConnectionFactory client;
@Autowired
@Qualifier("outAdapter.client")
AbstractEndpoint outAdapterClient;
@Autowired
@Qualifier("inAdapter.client")
AbstractEndpoint inAdapterClient;
@BeforeEach
public void setup() {
TestingUtilities.waitListening(this.crLfServer, 10000L);
if (!this.outAdapterClient.isRunning()) {
TestingUtilities.waitListening(this.crLfServer, 10000L);
this.client.setPort(this.crLfServer.getPort());
this.outAdapterClient.start();
this.inAdapterClient.start();
}
}
@Test
public void testHappyDay() {
String result = gw.send("999Hello world!"); // first 3 bytes is correlationid
assertEquals("999Hello world!:echo", result);
assertThat(result).isEqualTo("999Hello world!:echo");
}
@Test
@@ -88,36 +99,28 @@ public class TcpClientServerDemoTest {
results.add(i);
final int j = i;
executor.execute(() -> {
String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationid
assertEquals(j + "Hello world!:echo", result);
String result = gw.send(j + "Hello world!"); // first 3 bytes is correlationId
assertThat(result).isEqualTo(j + "Hello world!:echo");
results.remove(j);
latch.countDown();
});
}
assertTrue(latch.await(60, TimeUnit.SECONDS));
assertEquals(0, results.size());
assertThat(latch.await(60, TimeUnit.SECONDS)).isTrue();
assertThat(results).hasSize(0);
}
@Test
public void testTimeoutThrow() {
try {
gw.send("TIMEOUT_TEST_THROW");
fail("expected exception");
}
catch (MessagingException e) {
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
}
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> gw.send("TIMEOUT_TEST_THROW"))
.withMessageContaining("No response received for TIMEOUT_TEST");
}
@Test
public void testTimeoutReturn() {
try {
gw.send("TIMEOUT_TEST_RETURN");
fail("expected exception");
}
catch (MessagingException e) {
assertThat(e.getMessage(), containsString("No response received for TIMEOUT_TEST"));
}
assertThatExceptionOfType(MessagingException.class)
.isThrownBy(() -> gw.send("TIMEOUT_TEST_RETURN"))
.withMessageContaining("No response received for TIMEOUT_TEST");
}
}

View File

@@ -1,60 +0,0 @@
/*
* Copyright 2002-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
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.integration.samples.tcpclientserver.support;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.core.env.MapPropertySource;
import org.springframework.util.SocketUtils;
import org.springframework.test.context.MergedContextConfiguration;
import org.springframework.test.context.support.GenericXmlContextLoader;
/**
*
* @author Gunnar Hillert
* @author Gary Russell
* @author Artem Bilan
*
*/
public class CustomTestContextLoader extends GenericXmlContextLoader {
private static final Log LOGGER = LogFactory.getLog(CustomTestContextLoader.class);
@Override
protected void loadBeanDefinitions(GenericApplicationContext context,
MergedContextConfiguration mergedConfig) {
int availableServerSocket = SocketUtils.findAvailableTcpPort(5678);
final Map<String, Object> sockets = new HashMap<String, Object>();
sockets.put("availableServerSocket", availableServerSocket);
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Available Server Socket: " + availableServerSocket);
}
final MapPropertySource propertySource = new MapPropertySource("sockets", sockets);
context.getEnvironment().getPropertySources().addLast(propertySource);
super.loadBeanDefinitions(context, mergedConfig);
}
}

View File

@@ -172,14 +172,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -136,14 +136,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>

View File

@@ -137,14 +137,14 @@
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>6.0.0-M2</version>
<version>6.0.0-M3</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-bom</artifactId>
<version>6.0.0-M1</version>
<version>6.0.0-M2</version>
<scope>import</scope>
<type>pom</type>
</dependency>