Commit Graph

11249 Commits

Author SHA1 Message Date
Gary Russell
e8a9f95ca1 GH-4013: TCP DSL Improvements
Resolves https://github.com/spring-projects/spring-integration/issues/4013

Add Net/NIO specific Server/Client connection factory specs.

* Shorten DSL method names, as suggested.
2023-02-08 17:01:44 -05:00
Ivan Zaitsev
e6d0a4f826 GH-4008: ZK: Add leader and participants support
Fixes https://github.com/spring-projects/spring-integration/issues/4008

Impossible to retrieve current leader id from ZK `LeaderInitiator`

* change return type of `LeaderInitiator.getContext()` from `Context` to `CuratorContext`
* add `getLeader()` method to `CuratorContext`
* add `getParticipants()` method to `CuratorContext`
2023-02-07 10:36:29 -05:00
Artem Bilan
6a2ff0cd99 GH-4001: Doc for cooperation with some HZ objects (#4003)
* GH-4001: Doc for cooperation with some HZ objects

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

The `IQueue`, `ITopic` and `IExecutorService` can be used with Spring Integration
channel as is without any extra component implementations.

* Document the cooperation feature with Hazelcast objects via samples

* * Add a sample about an Inbound Channel Adapter on the `IQueue`

* Fix language in docs

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

---------

Co-authored-by: Gary Russell <grussell@vmware.com>
2023-02-06 12:20:42 -05:00
Artem Bilan
44000b9606 GH-4002: Deprecate ConsumerStopAction in MQTT (#4006)
Fixes https://github.com/spring-projects/spring-integration/issues/4002

Turns out the `ConsumerStopAction` was introduced in a point version to mitigate an unsubscription bug
and let to preserve a previous behaviour.

* Deprecate `ConsumerStopAction` in favor of just `cleanSession` flag in the `MqttConnectOptions`

**Cherry-pick to `5.5.x`**
2023-02-06 11:58:41 -05:00
Artem Bilan
d9d7c49aac Propagate and Observation from Reactive context (#3999)
To propagate an `Observation` from reactive stream (e.g. WebFlux)
we have to capture its context and set it into the current thread scope.

* Add a `io.micrometer:context-propagation` dependency to support reactive context propagation
* Populate a `parentObservation` in the `IntegrationObservation.PRODUCER.observation()`
since it is not available for tracing on `Observation.onStart()`.
Might be tentative until upcoming fix in Micrometer Observation
* Populate from reactive context in the `WebFluxInboundEndpoint` where we use just `send()` operation downstream
* Populate from reactive context in the `MessagingGatewaySupport` where we use `send()` operation downstream or `FluxMessageChannel.subscribeTo()`
* Use `contextCapture()` in the `FluxMessageChannel` to gather a `ThreadLocal` info into a Reactor context
and then set back to `ThreadLocal` in the `transformDeferredContextual()` which really happens on a different thread
* Verify a trace propagation from WebFlux to an integration flow via Brave instrumentation in the `WebFluxObservationPropagationTests`
2023-02-01 14:13:40 -05:00
Artem Bilan
841289002c GH-3998: Fix gateway docs for @Payload (#4000)
* GH-3998: Fix gateway docs for `@Payload`

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

The `GatewayProxyFactoryBean` now deals only with a `MethodArgsHolder` as a root evaluation context object.
There is no `#args` and `#method` SpEL variables anymore.
However, the `gateway.adoc` still refer to those.

* Fix `gateway.adoc` for a proper expressions and actual wording

* * Cross link to `gateway-expressions` paragraph for better context
2023-02-01 14:05:20 -05:00
Artem Bilan
f01e2b8553 GH-3994: Register native hints for Graph model (#3996)
Fixes https://github.com/spring-projects/spring-integration/issues/3994

Essentially, migrate those hints from Spring Boot Actuator:
an `IntegrationGraphServer` can be used without Spring Boot

* Introduce `IntegrationGraphRuntimeHints` - implementation of `RuntimeHintsRegistrar`
to register reflection hints for `Graph` and top-level `IntegrationNode` types.
* Use `@ImportRuntimeHints` on the `IntegrationGraphServer` to make those hints
conditional.
2023-01-23 14:22:42 -05:00
Artem Bilan
ebba37497f GH-3993: Fix async race condition in TcpOutGateway (#3995)
* GH-3993: Fix async race condition in TcpOutGateway

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

When `TcpOutboundGateway` is in an `async` mode and `CCF` is configured
not for `singleUse` an `Semaphore` around an obtained `TcpConnection` is involved.
If we fail on `TcpConnection.send()`, resources are not clean up, including the
mentioned `Semaphore`: in async mode this happens only when we receive a reply.

* Catch an exception on the `TcpConnection.send()` and perform `cleanUp()` in async mode.
* Add `cleanUp()` into a scheduled task from the `TcpOutboundGateway.AsyncReply`
when no reply arrives in time.
* Optimize `TcpOutboundGateway.AsyncReply` behavior to cancel no-reply scheduled task
when reply arrives into a `CompletableFuture`

**Cherry-pick to `5.5.x`**

* * Call `cleanUp()` from no response scheduled task
only if `future.completeExceptionally()` is `true`
2023-01-23 11:07:19 -05:00
Spring Builds
f8c0779964 [artifactory-release] Next development version 2023-01-18 18:20:29 +00:00
Spring Builds
480a9735bf [artifactory-release] Release version 6.0.2 2023-01-18 18:20:26 +00:00
abilan
330f1cdb7e Increase group timeout for AggregatorIntTests
https://build.spring.io/browse/INT-MAIN-561/
2023-01-18 12:24:09 -05:00
abilan
298b2403d9 Exclude org.glassfish.jaxb from spring-ws-core
The `spring-integration-ws` modules relies on the `com.sun.xml.bind:jaxb-impl`
as `provided` dependency
2023-01-18 11:51:40 -05: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
05659301df Fix race condition in TcpOutGateTests.testAsync
The `ChannelInterceptor.postSend()` may be called when
`MessageChannel.receive()` has already done its job polling from
the queue where message appears in the `MessageChannel.doSend()`

* Use `ChannelInterceptor.preSend()` contract instead to obtaine info about the current thread
2023-01-18 09:14:13 -05:00
abilan
a1f57e40cd Fix reactive error handling for request-reply
Related to https://stackoverflow.com/questions/75109345/spring-integration-webflux-inboundgateway-replychannel-for-error-response

The `MessagingGatewaySupport.doSendAndReceiveMessageReactive()` uses `MutableMessageBuilder`
to build a new message for next `send` operation.
Even if this is an error flow, the provided `ErrorMessage` becomes a plain `MutableMessage`.
This may break some downstream logics, like `TracingChannelInterceptor` from Spring Cloud Sleuth,
which checks for the `Message` class to rebuild or reuse a message content.
Therefore, an error handling flow is not able to extract error info because it is just lost.

* Fix `MessagingGatewaySupport.doSendAndReceiveMessageReactive()` to check for message type before
choosing an `AbstractIntegrationMessageBuilder` impl for building a new message.
The regular `MessageBuilder` just builds a new `ErrorMessage` for an exception payload.
* Add `filter()` into a `WebFluxDslTests` error handling flow to be sure that message for
error sub-flow is really an `ErrorMessage`
2023-01-17 14:50:27 -05:00
abilan
2c722851fe GH-3990: Fix JsonPath native hint registration
Fixes https://github.com/spring-projects/spring-integration/issues/3990

Turns out just being on the classpath doesn’t make the type reachable.
If it’s only accessed reflectively then it’s not reachable.
This is exaclt what happened with our `JsonPathUtils` which is used via
reflection from SpEL when that calls its method via function reference

* Change `onReachableType()` logic for `com.jayway.jsonpath.JsonPath` type
to `ClassUtils.isPresent()` on `JsonPathUtils` reflection hint registration.
2023-01-14 13:36:01 -05:00
abilan
9dd9f08181 Use switch expression; some other clean up 2023-01-13 16:00:19 -05:00
abilan
fc3b95ea79 Debug not resolved channel in Router
Currently, when `!resolutionRequired` not resolved channel name
is ignored silently, and we go ahead to `defaultOutputChannel` or
exception thrown

* For better end-user experience `DEBUG` not resolved and ignored channel name if `!resolutionRequired`
2023-01-13 15:12:44 -05:00
Artem Bilan
d298df8d0f Revise JS support for regular JVM (#3989)
* Revise JS support for regular JVM

Turns out that we just need to have `org.graalvm.sdk:graal-sdk` and `org.graalvm.js:js`
dependencies for regular JVM to enable JavaScript support for Spring Integration Scripting module

* Add respective `providedImplementation` dependencies
* Remove `@EnabledIfSystemProperty` from unit tests
* Mention those dependencies in the doc

* Rework sentence in the doc for better English

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

Co-authored-by: Gary Russell <grussell@vmware.com>
2023-01-11 13:34:28 -05:00
abilan
74320381ba Some tweaks for SimpleMessageGroupTests
**Cherry-pick to `5.5.x`**
2023-01-09 16:27:06 -05:00
abilan
4283a5532a GH-3986: Integration mock: fix ReactiveMH support
Fixes https://github.com/spring-projects/spring-integration/issues/3986

The `ReactiveStreamsConsumer` in addition to plain `Subscriber` and `MessageHandler`
also supports a `ReactiveMessageHandler`, but `MockIntegrationContext` doesn't
handle a scenario when `ReactiveMessageHandler` is provided for consumer

* Rework the logic in the `MockIntegrationContext` to substitute a `ReactiveMessageHandler`
in the `ReactiveStreamsConsumer` which has a precedence in its logic over plain `Subscriber`.
* Wrap a plain `MessageHandler` mock into a `ReactiveMessageHandler` before substitution
in the `ReactiveStreamsConsumer`
* Reset `ReactiveStreamsConsumer.reactiveMessageHandler` with source `ReactiveMessageHandler`
or `null` respectively to an original `ReactiveStreamsConsumer` configuration
* Mention `ReactiveMessageHandler` use-case in the `testing.adoc`

**Cherry-pick to `5.5.x`**
2023-01-09 15:37:06 -05:00
Artem Bilan
308f3fadeb Do not build exception instances in advance (#3983)
* Do not build exception instances in advance

When no `cause` and no clean context of the exception thrown,
the code place where an exception has been created is confusing.

* Fix `SimpleMessageStore` to create an `out of capacity` exception in the
`addMessagesToGroup()` exactly at the point where it is thrown
* Fix `FunctionExpression` and `SupplierExpression` do not pre-create `readOnlyException`:
it is unlikely these kind of expressions are going to be used in the SpEL `write` context,
so we save some time and memory not creating extra object and the plain call `throw new`
gives us a clean context what method call has ended up with such an exception

* * Extract `outOfCapacityException` to the method in the `SimpleMessageStore`
to avoid duplication.
Even if we got in the end extra line in th stack trace, it is still clear from
where it is thrown:

```
org.springframework.messaging.MessagingException: SimpleMessageStore was out of capacity (1) for group 'foo', try constructing it with a larger number.

	at org.springframework.integration.store.SimpleMessageStore.outOfCapacityException(SimpleMessageStore.java:324)
	at org.springframework.integration.store.SimpleMessageStore.addMessagesToGroup(SimpleMessageStore.java:302)
	at org.springframework.integration.store.AbstractMessageGroupStore.addMessageToGroup(AbstractMessageGroupStore.java:189)
	at org.springframework.integration.store.SimpleMessageStoreTests.shouldNotHoldMoreThanGroupCapacity(SimpleMessageStoreTests.java:128)
```
2023-01-05 11:35:24 -05:00
abilan
cf5f218449 Fix new Sonar smells 2023-01-05 10:19:26 -05:00
kdebski85
854e555e4e GH-3980: Fix DefaultSftpSFactory for concurrency
Fixes https://github.com/spring-projects/spring-integration/issues/3980

When not `isSharedSession`, the `initClient()` is called for every session
we request from the factory and in concurrent calls we end up with not initialized SSH client
in some threads.

* Add `synchronized` double check logic to the `initClient()` to block other threads while the first one
initialize the client
* Use `volatile boolean` instead of `AtomicBoolean` and change its state when `SshClient` is created and started
2023-01-05 10:01:48 -05:00
abilan
f8fff81886 Fix new Sonar smells 2022-12-21 13:39:18 -05:00
abilan
679ce6ff36 Upgrade to Gradle 7.6
* Fix `pr-build-workflow.yml` removing unused services: now they are pulled by Testcontainers
* Use official `rabbitmq:management` image instead of `MQTT`-based.
The `MQTT` is now tested with Testcontainers and Mosquitto broker image
2022-12-21 13:04:17 -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
Spring Builds
e74393f995 [artifactory-release] Next development version 2022-12-21 15:42:34 +00:00
Spring Builds
e990486025 [artifactory-release] Release version 6.0.1 2022-12-21 15:42:31 +00:00
abilan
033cb7695b Migrate Mockito-effected test classes to JUnit 5 2022-12-21 09:42:18 -05:00
abilan
eb570ec447 More test XML configs for latest Mockito 2022-12-20 21:14:02 -05:00
abilan
376d5dfc16 Fix Rsocket test XML configs for latest Mockito 2022-12-20 17:57:46 -05:00
abilan
30c0ea2791 Fix JPA test XML configs for latest Mockito 2022-12-20 17:52:41 -05:00
abilan
097d3e54b7 Fix mail test XML config for latest Mockito 2022-12-20 17:36:52 -05:00
abilan
5c926e84ba Add missed type="java.lang.Class" to IdRecTests 2022-12-20 17:19:25 -05:00
abilan
aa761b44b4 Fix more test XML configs for latest Mockito 2022-12-20 17:08:34 -05:00
abilan
80115d33b1 Fix more test XML configs for latest Mockito 2022-12-20 16:52:48 -05:00
abilan
cd0b44dff6 Fix ServiceActivatorOnMockitoMockTests-context 2022-12-20 16:47:11 -05:00
abilan
4a4ce22ec3 Fix Cassandra XML configs for latest Mockito 2022-12-20 16:35:33 -05:00
abilan
52d43ea8ed Upgrade dependencies; prepare for release
Fix XML configs for new `Mockito.mock()` factory method
2022-12-20 16:25:06 -05:00
Artem Bilan
49a9b7e314 Obtain observed timers in the Integration Graph (#3967)
* Obtain observed timers in the Integration Graph

The `Observation` populates slightly different Micrometer timer names and their tags

* Fix `MicrometerNodeEnhancer` to search timers in the registry according to the `Observation`
convention if the provided component is observed
* For that purpose expose an `IntegrationManagement.isObserved()` option to check
of component is instrumented with an `Observation`
* Improve the logic in the `IntegrationGraphServer` to delegate into a `Function`
to call `micrometerEnhancer.enhance()` instead of `static` property which might not
be OK in the environment where several integration applications are ran in the same JVM

* * Collect times into graph for inbound gateways & producers

* Fix language in javadoc of new `IntegrationManagement.isObserved()`

* Add `@Nullable` to `MicrometerNodeEnhancer.buildTimerStats()` param to satisfy this method contract

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

Co-authored-by: Gary Russell <grussell@vmware.com>
2022-12-20 11:46:48 -05:00
Artem Bilan
d38e0d8720 GH-3962: Support SFTP < v5 for rename (#3964)
* GH-3962: Support SFTP < v5 for rename

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

Turns out the `SftpClient.CopyMode` options are supported only starting SFTP v5

* Check for the version from the client and fallback to the logic we had before with JSsch:
try to rename, delete existing file if such an exception status is thrown and retry to rename

* * Fix `SftpOutboundTests` with answering an explicit SFTP version for an `SftpClient` mock
2022-12-20 11:46:02 -05:00
abilan
3a743802c0 GH-3974: Fix SftpSession for absolute paths
Fixes https://github.com/spring-projects/spring-integration/issues/3974

* Treat a leading `/` as an indicator of absolute path request in the `SftpSession.doList()`
* Call `sftpClient.canonicalPath()` for path without a leading `/` to resolve it as relative path in the user home
* Add a note in docs for `LS` command
2022-12-16 12:59:07 -05:00
Otto Laitila
7adaaafd40 Replace javadoc mentions of JSch with MINA SSHD
JSch was replaced with MINA SSHD in v6 upgrade.
2022-12-16 10:57:18 -05:00
Artem Bilan
4cd0029579 GH-3954: Fix WebFlux XML config for ambiguity (#3973)
* GH-3954: Fix WebFlux XML config for ambiguity

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

When `web-client` attribute is provided for the WebFlux outbound components configuration via XML,
the `encoding-mode` is silently ignored

* Check for `encoding-mode` attribute presence in the `WebFluxOutboundChannelAdapterParser`
when `web-client` is provided and throw respective exception to reject such a config

**Cherry-pick to `5.5.x`**

* * Improve error messages in the `WebFluxOutboundChannelAdapterParser`
2022-12-15 13:05:35 -05:00
abilan
ab1254dcf8 GH-3966: Kafka XML config: Expose more attributes
Fixes https://github.com/spring-projects/spring-integration/issues/3966

Exposed setters in the `KafkaInboundGateway` and `KafkaMessageDrivenChannelAdapter`
as an XML attributes for `kafka` namespace

**Cherry-pick to `5.5.x`**
2022-12-12 16:00:40 -05:00
abilan
1c836f0698 GH-3969: SFTP: Bring back support for empty path
Fixes https://github.com/spring-projects/spring-integration/issues/3969

In previous version for SFTP client (Jsch), the empty path for `LS` command
has meant a `user home`.
Turns out the MINA `SftpClient` does not support automatic user home resolution
from the empty path.

* Fix `SftpSession` to resolve an empty path into a user home via `canicalPath()` operation
2022-12-12 11:43:01 -05:00
Artem Bilan
6fd4fd3dd9 GH-3959: MqttConFailedEvent for normal disconnect (#3961)
* GH-3959: MqttConFailedEvent for normal disconnect

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

The `MqttCallback.disconnected(MqttDisconnectResponse)` in Paho v5 client is also
called when server initiates a disconnection.
In this case that `MqttDisconnectResponse` does not have a `cause` value

* Modify `MqttConnectionFailedEvent` to make a `cause` property optional
* Fix `Mqttv5PahoMessageDrivenChannelAdapter` & `Mqttv5PahoMessageHandler`
to not check for `cause`, but emit an `MqttConnectionFailedEvent` for any `disconnected()` calls

Unfortunately current Paho v3 client does not call `connectionLost()` for normal disconnections
and we cannot react for this callback with an `MqttConnectionFailedEvent`

**Cherry-pick to `5.5.x`**

* Fix language in doc

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

Co-authored-by: Gary Russell <grussell@vmware.com>
2022-12-07 08:56:40 -05:00
abilan
a1e4827bbe More percentages increase in DelayerUsageTests
Even `20` is not enough:
https://build.spring.io/browse/INT-MAIN-521/
2022-12-05 11:29:28 -05:00
abilan
03825c5625 Increase percentage in DelayerUsageTests
Turns out CI may be slow enough to catch in time, so increase percentage to `20`
for delays in async tasks
2022-12-05 10:37:35 -05:00