Commit Graph

290 Commits

Author SHA1 Message Date
Artem Bilan
71f74be1d1 GH-9297: Improve ImapIdleChannelAdapter.callIdle() for cause
Fixes: #9297

For a normal `jakarta.mail.StoreClosedException: * BYE Jakarta Mail Exception: java.net.SocketException: Connection reset`
 the `ImapIdleChannelAdapter.callIdle()` results in a resubmission (and reconnection)
 with logging 'Failed to execute IDLE task. Will attempt to resubmit in 10000 milliseconds.'`
However, when `selectorExpression` is in used and that one is based on mail `Message` object,
we may fail with `FolderClosedException` which is wrapped to the `SpelEvaluationException` and some
other stack traces.
So, `jakarta.mail.MessagingException` might be deep in the cause chain.

* Fix `ImapIdleChannelAdapter` via introducing `getJakartaMailMessagingExceptionFromCause()` utility
method which searches for the `jakarta.mail.MessagingException` in cause chain.
* Rework `ImapIdleChannelAdapter.callIdle()` logic to rely on this new method

(cherry picked from commit 272fcd044d)
2024-07-02 19:39:54 +00:00
Artem Bilan
bce72c66a4 Upgrade to com.icegreen:greenmail:2.1.0-rc-1
Fixes: #9200

# Conflicts:
#	build.gradle
2024-06-03 11:46:02 -04:00
Artem Bilan
e4c1851c07 Fix ImapIdleChA for scheduling race condition (#8670)
* Fix ImapIdleChA for scheduling race condition

The IMAP IDLE is long-lived process and can be blocked
waiting for any reply from the server.
This way it is not suited to be used in a `TaskScheduler`
especially when it has only one thread in its pool in Spring Boot by default.
Another concurrent scheduled task is exactly an `ImapMailReceiver.IdleCanceller`.
With a single thread in a `TaskScheduler` pool it cannot be reached
therefore we never cancel and IDLE task and cannot react to the connection loss properly

* Rework the `ImapIdleChannelAdapter` logic to use a regular `Executor` and `while()` loop
with a `Thread.sleep()` when we lose connection
* Clean up the `ImapMailReceiverTests` from `TaskScheduler` not used anymore.
* Expose new `taskExecutor` option in the `ImapIdleChannelAdapterSpec` for Java DSL
* Enable `ImapMailReceiverTests.testIdleWithMessageMapping()` with an attempt to see
if this fix covers an unclear problem exposed before

* * The `testIdleWithMessageMapping()` still fails on GH actions
2023-07-12 11:00:40 -04:00
abilan
019e96c925 Disable ImapMailTests.testIdleWithMessageMapping
It is not clear why IMAP GreenMail server closes its socket accidentally
2023-06-28 14:35:55 -04:00
abilan
1690be45fc Decrease read timeout for GreenMail tests
This may give a chance for IDLE to restart more often
to read the actual INBOX state during the test
2023-06-28 12:53:25 -04:00
abilan
8315b11494 Some tweaks for ImapMailReceiverTests 2023-06-15 13:10:51 -04:00
abilan
99122d7621 Diagnostic: Add LogLevels to ImapMailReceiverTest
* Fix `com.sun.mail` to `jakarta.mail` in Mail module `log4j2-test.xml`
2023-06-15 10:54:37 -04:00
abilan
95f1eb8c28 GH-8616: Upgrade to Angus Mail to 2.0.2
Fixes https://github.com/spring-projects/spring-integration/issues/8616

* And Greenmail to `2.1.0`
2023-06-08 13:42:16 -04:00
Artem Bilan
32e34bf2ec GH-5871: Add missed order attr to XSDs (#8624)
* GH-5871: Add missed `order` attr to XSDs

Fixes https://github.com/spring-projects/spring-integration/issues/5871

* * Fix `spring-integration-xml.xsd` for duplicates
2023-05-22 11:59:47 -04:00
abilan
75769ba883 Back to BEFORE_EACH for ImapMailReceiverTests
Looks like there are some leftovers after interactions with
channel adapters from config
2023-04-22 09:54:09 -04:00
abilan
33aaaba149 Some ImapMailReceiverTests improvements
* Increase reconnectTimeout to avoid race conditions
* Do not stub `protected` methods
* Rearrange properties settings before spying on object
2023-04-22 09:29:54 -04:00
abilan
e9cee2e08a Turn on DEBUG for Greenmail to diagnose test fail 2023-04-21 11:45:47 -04:00
abilan
1067075ec8 More ImapMailReceiverTests clean-ups 2023-04-20 20:47:21 -04:00
abilan
62179bfc90 Bring back IMAP server per unit test 2023-04-20 20:15:05 -04:00
abilan
20b6ea6728 Fix checkstyle violation in ImapMailReceiverTests 2023-04-20 16:35:50 -04:00
abilan
fa1f8a4eff Some ImapMailReceiverTests improvements
* Fix typo in the `ImapIdleChannelAdapter` log message for not reconnecting error
2023-04-20 16:16:41 -04:00
abilan
5e348091f0 Upgrade to Mockito-5.3.0
Fix `ImapMailReceiverTests` and `Pop3MailReceiverTests` to not use mocks for messages
2023-04-20 15:25:51 -04:00
abilan
d5181bf0d7 Add Nullability support into Java DSL 2023-04-14 14:16:36 -04:00
abilan
8f83be2a91 Move adjustments for ImapMailReceiverTests 2023-03-29 10:36:24 -04:00
abilan
22acf51caa Increase timeout in the ImapMailReceiverTests 2023-03-29 10:27:16 -04:00
Artem Bilan
4fdbdf180e GH-8577: Revise ImapIdleChannelAdapter logic (#8588)
* GH-8577: Revise `ImapIdleChannelAdapter` logic

Fixes https://github.com/spring-projects/spring-integration/issues/8577

When we process mail messages in async manner, it is possible that we end up
in a race condition situation where the next idle cycle closes the folder.

It is possible to reopen the folder, but feels better to block the current idle
cycle until we are done with the message and therefore keep folder opened.

* Deprecate `ImapIdleChannelAdapter.sendingTaskExecutor` in favor of an `ExecutorChannel`
as an output for this channel adapter or similar async hand-off downstream.
* Make use of `shouldReconnectAutomatically` as it is advertised for this channel adapter
* Optimize the proxy creation for message sending task

* * Remove `ImapIdleChannelAdapter.sendingTaskExecutor`

* Fix language in docs

Co-authored-by: Gary Russell <grussell@vmware.com>

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
2023-03-29 10:15:47 -04:00
abilan
4be99de1f4 Upgrade dependencies; prepare for release
* Fix mail tests for the latest Greenmail changes
2023-01-18 11:03:10 -05:00
abilan
19d6b7617f More Mockito fixes for test XML configs
Looks like sometime Spring Framework XML parser can properly determine the target factory method to chose,
but sometimes it does that in a wrong order.

* Add `type="java.lang.Class"` to the ctor args everywhere for `class="org.mockito.Mockito" factory-method="mock"`
`<bean>` definitions
2022-12-21 11:16:56 -05:00
abilan
097d3e54b7 Fix mail test XML config for latest Mockito 2022-12-20 17:36:52 -05:00
abilan
7864658d01 GH-3686: Apply SF editor config
Fixes https://github.com/spring-projects/spring-integration/issues/3686

* Add `src/idea` with respective editor config for IntelliJ IDEA.
Must be imported into an IDE
* Add `src/eclipse` with respective editor config for Eclipse/STS
* Reformat imports in source code according a new editor config
2022-11-14 10:55:21 -05:00
Artem Bilan
60f453e9ff Upgrade to Jakarta EE 10
* Fix mail module to fit to the latest mail API requirements
* Fix the last Sonar smell in the `SmbShare`
* Remove redundant dependency for `hamcrest-core` in various modules
2022-11-07 17:05:22 -05:00
Artem Bilan
cfeaecaae8 GH-3421: Resolve throws Exception; in the API
Fixes https://github.com/spring-projects/spring-integration/issues/3421

Remove `throws Exception;` from production code to honor
the rule `Generic exceptions should never be thrown` which is enabled on SonarQube

* Rework affected usages to `try..catch` with throwing respective runtime exception
or just logging
* Some other refactoring for the affected classes
2022-10-17 16:57:24 -04:00
freyan929
2e9beada0b GH-3858: Add ImapIdleChASpec.reconnectDelay()
Fixes https://github.com/spring-projects/spring-integration/issues/3858
2022-07-25 21:46:14 -04:00
Artem Bilan
e0f137905a Fix compatibility with the latest SF
* Mostly changes are related to the `TaskScheduler` and `Trigger` APIs
* Migrate to `micrometer-tracing` dependency
* Rework `SocketTestUtils` to use a `InetAddress.getLocalHost()`
for more stability and performance on Windows
* Fix docs for new `PeriodicTrigger` API
2022-07-08 17:36:15 -04:00
Artem Vozhdayenko
53dd050c5b GH-3623: Deprecarte an IntegrationFlows
Fixes https://github.com/spring-projects/spring-integration/issues/3623

* `IntegrationFlow` refactoring
* Apply several code style improvements and good practices
* Code style: no empty lines for methods javadocs
* make deprecated implementation reuse actual one instead of the copy-paste approach
* add whats-new comments
* Fix whats-new page according to standards
2022-07-05 15:47:30 -04:00
Artem Bilan
2022c40d55 Fix compatibility with the latest SF
* Upgrade Spring dependencies to the latest SNAPSHOTs
* Fix tests to verify against stack traces: the message
of the `NestedRuntimeException`  does not include the nested exception information.
Related to https://github.com/spring-projects/spring-framework/issues/25162
* Fix `JdbcMessageStore` and `DefaultLockRepository` to rely on the `DataIntegrityViolationException`
instead of only its `DuplicateKeyException` extension.
This is the current behavior of the SQL errors translation
* Disable `WebFluxDslTests.testValidation()` - doesn't subscribe to the reply somehow...
* Refine `SimplePool.PoolSemaphore.reducePermits()`
2022-06-27 20:30:14 -04:00
Artem Bilan
802d217a9a Close mail folder if no messages to produce
Related to https://stackoverflow.com/questions/71667731/spring-integration-mimemessage-gmail-folder-is-not-open-exception

If no mail messages pulled from the folder or all of them are filtered out,
there is nothing to produce downstream.
Therefore, always close the folder in the end of `AbstractMailReceiver.receive()`
when no messages and even if `autoCloseFolder == false`

**Cherry-pick to `5.5.x`**
2022-04-07 14:16:01 -04:00
Artem Bilan
a80b22638d Start 6.0 version
* Upgrade to Java 17, SF-6.0, Gradle 7.2
* Upgrade to Jakarta dependencies and respective namespaces
* Fix some tests for Java 17 compatibility
* Fix wrong Javadocs
* Add some missed Javadocs
* Fix more `jakarta` namespace
* Fix WS & XML modules to use Jakarta EE
* `--add-opens` in some modules for their reflection-based tests
* Disable Kafka tests which does not work on Windows; see Apache Kafka `3.0.1`
* Upgrade to JUnit `5.8.1`
* Migrate JMS tests to Artemis
* Remove RMI module as it was deprecated before
* Fix `pr-build-workflow.yml` for Java 17
* Fix JavaDocs warnings using `Xdoclint:syntax` per module, not in the top-level `api` task
* Move docs for version `6.0`
2022-01-18 14:38:50 -05:00
Artem Bilan
fe57fd281c Checkstyle changes
* Upgrade to Checkstyle 9.0
* apply some JavaDocs rules
* Fix JavaDocs rules violations
* Some other minor clean up in the affected classes
2021-09-28 11:55:25 -04:00
wangYX657211334
b8785e5f9c GH-3619: Fix Mail Receiver fetch redundant Messages
Fixes https://github.com/spring-projects/spring-integration/issues/3619

The `AbstractMailReceiver` fetche redundant messages, causing performance problems

* Use correct, already filtered, array of message to fetch

**Cherry-pick to `main` & `5.3.x`**
2021-09-02 10:49:43 -04:00
Dominik Simmen
c189a125a6 Safely read expunged IMAP messages
If application is connected to a Domino mail server via IMAP, it can happen from time to time that a message is expunged.
This leads to a `MessageRemovedException` when calling `IMAPMessage#getSubject`.
And although debug is set to false this again leads to a `MessageException` and the whole integration flow stops.

* Check for `isExpunged()` before logging a filtered message

* Add `@author`
* Fix debug message for expunged to reflect reality
* Clean up new unit tests a bit

**Cherry-pick to `5.4.x`**
2021-08-09 11:23:26 -04:00
trungPa
9c718c37a6 GH-3424: Refactor to use logging methods from LogAccessor
Fixes https://github.com/spring-projects/spring-integration/issues/3424

* Use `LogMessage.format()` for lazily formatting

* Fix some logging statements in `JdbcChannelMessageStore`
2021-07-19 11:30:01 -04:00
Alexander Pinske
996daca228 GH-3451: Use GreenMail for testing instead
Fixes https://github.com/spring-projects/spring-integration/issues/3451

The GreenMail provides a comprehensive support for e-mail scenarios
testing.

* Use GreenMail instead our own `TestMailServer` for better and broader
support
* Convert SmtpTests and Pop3Tests to GreenMail
* Document that Pop3MailReceiver does not support autoCloseFolder=false
* Pop3MailReceiver uses `folder.getMessageCount()` to determine if there
are new messages.
This count only gets updated when opening the folder.
* Use GreenMail for remaining mail tests
* convert MailTests and ImapMailReceiverTests to GreenMail
* remove duplicate mail dependencies
* route com.sun.mail logging to log4j (via jul and slf4j)
2021-05-18 12:40:46 -04:00
Artem Bilan
b84b60c732 GH-3560 Parse mail FROM as comma-delimited header (#3562)
Fixes https://github.com/spring-projects/spring-integration/issues/3560

According RFC 5322 `FROM` and `REPLY-TO` received mail message can be
as an array of addresses.

* Fix `MailUtils` to present those arrays as comma-delimited strings for
Spring message headers
* Fix tests to deal already with several addresses for `FROM` mime header.

In the future we may change the logic to map those mime headers to arrays
as it states according the mentioned RFC

**Cherry-pick to `5.4.x` & `5.3.x`**
2021-05-05 16:56:01 -04:00
Alexander Pinske
3c27241d31 Improve IMAP IDLE tests
This forces the race condition that was fixed in #3535 consistently.
Before the `IdleCanceler` was used to cancel the `idle()` call in addition to the normal flow. 
That should not be necessary any more.
2021-04-09 15:57:04 -04:00
Alexander Pinske
07a6fb3a9a Fix IMAP race condition around idle()
`IMAPFolder.idle()` by default keeps idle-ing after each response.
We don't need that, because we want to fetch the new mails immediately (over the same connection).
To make `idle()` not keep on going, we called
`folder.isOpen()` which in most cases makes `idle()` stop by calling `noop()`
internally (to keep the connection alive) which leads to the current
`idle()`-call being canceled.

The problem this commits addresses is that the call to `noop()` only
happens if there were no calls in the last second.
There is a check for that in `com.sun.mail.imap.IMAPFolder.keepConnectionAlive`.
So if a new message appears less then a second after idle started, we will miss it.

This new way interrupts `idle()` more often than before, e.g. when there
is an expunge-message (i.e. a message was deleted), which we don't care about.
But the subsequent `receive()` in IdleTask will simply get no
messages and then turn around and start idle-ing again.

**Cherry-pick to `5.3.x` & `master`**
2021-04-06 14:04:36 -04:00
Artem Bilan
b4290dd2a5 GH-3492: Add ImapIdleChAdapterSpec.simpleContent
Fixes https://github.com/spring-projects/spring-integration/issues/3492

The `simpleContent` option is missed on the `ImapIdleChannelAdapterSpec`

* Add `ImapIdleChannelAdapterSpec.simpleContent(boolean)` option with
delegation to its internal `ImapMailReceiver`
* Convert all the `mail` tests to JUnit 5
2021-02-10 11:26:24 -05:00
Artem Bilan
3e501905e3 GH-3356: Add the way to not load mail message (#3402)
* GH-3356: Add the way to not load mail message

Fixes https://github.com/spring-projects/spring-integration/issues/3356

In some cases it is not necessary to have a whole mail message to be load
when it could be filtered out downstream

* Treat "no eager load" for `MimeMessage` in the `AbstractMailReceiver`
when no `headerMapper`, not `simpleContent` and no `autoCloseFolder`

* Fix language in Docs

Co-authored-by: Gary Russell <grussell@vmware.com>

Co-authored-by: Gary Russell <grussell@vmware.com>
2020-10-12 17:36:22 -04:00
Artem Bilan
20348ae38f Fix compatibility with the latest Reactor
* Fix missed long-running tests according components under testing changes
2020-10-08 12:41:35 -04:00
Artem Bilan
c7ff99a4e8 Use LogAccessor from SF
* Change main classes to use a `LogAccessor` API to simplify code flow
* Fix tests according `LogAccessor` property
* Fix some Sonar smells
2020-10-06 13:56:50 -04:00
Filip Hrisafov
9ad348b75f Log attempting to receive email under debug level instead of info (#3312) 2020-06-18 12:06:00 -04:00
Artem Bilan
bff891b7a9 Fix new Sonar smells 2020-03-26 10:31:32 -04:00
Artem Bilan
b6bd83d548 Fix deprecation for TX; fix JMS tests; Moore-SR6
* Upgrade to Spring Data Moore-SR6
* Fix `TransactionHandleMessageAdvice` and `TransactionInterceptorBuilder`
for deprecations in the `TransactionInterceptor`
* Fix `TransactionHandleMessageAdvice` and `TransactionInterceptorBuilder`
consumers to expose new `TransactionManager`-based options and
deprecate `PlatformTransactionManager`-based
* Fix failing JMS tests to reuse an ActiveMQ Connection Factory with a
`trustedPackaged(*)`

**Cherry-pick to master**

# Conflicts:
#	build.gradle
#	spring-integration-core/src/main/java/org/springframework/integration/dsl/ConsumerEndpointSpec.java
#	spring-integration-core/src/main/java/org/springframework/integration/dsl/PollerSpec.java
#	spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionHandleMessageAdvice.java
#	spring-integration-core/src/main/java/org/springframework/integration/transaction/TransactionInterceptorBuilder.java
2020-03-25 13:56:37 -04:00
Artem Bilan
867a8cf108 GH-3155: Add support for Java DSL extensions (#3167)
* GH-3155: Add support for Java DSL extensions

Fixes https://github.com/spring-projects/spring-integration/issues/3155

Provide an `IntegrationFlowExtension` for possible custom EI-operators
in the target project use-cases.

* * Move `IntegrationFlowExtension` tests ot its own test class
* Make all the `IntegrationComponentSpec` ctors as `protected` for possible custom extensions
* Make some `BaseIntegrationFlowDefinition` methods and properties as `protected` to get them
access from the `IntegrationFlowExtension` implementations
* Document the feature

* * Fix language and typos in docs

* * Add `protected` to one more `GatewayEndpointSpec` ctor
* Add JavaDocs to `GatewayEndpointSpec` methods

* * Add `protected` to one more `JmsPollableMessageChannelSpec` ctor
2020-02-07 13:40:39 -05:00
Artem Bilan
370e943428 Remove deprecations from previous versions
* Remove Boon dependency and its usage
* Remove overloaded methods from the `IntegrationFlowDefinition`
- we can simply rely now on the super class
* Remove (or rework) deprecated entities in the docs
* Fix tests for removed deprecated APIs
* Rework affected tests to JUnit 5
2020-01-09 15:54:04 -05:00