Commit Graph

2398 Commits

Author SHA1 Message Date
Artem Bilan
a9ab4827a9 Fix tests for the previous commit - new behavior 2019-12-18 17:06:59 -05:00
Artem Bilan
887a0896ef Fix Messaging Annotations for ReplyProdMHWrapper
To ensure advice-chain applicability the provided plain
`MessageHandler` is wrapped into a `ReplyProducingMessageHandlerWrapper`
with its particular `.wrapper` bean name.
When we build a graph for integration components, we use a
`componentName` from the `IntegrationObjectSupport` to represent a
node for endpoint in the graph.
In most cases the component name is an endpoint id around a `MessageHandler`

* Populate the missed component name in a `ReplyProducingMessageHandlerWrapper`
in the `AbstractMethodAnnotationPostProcessor` so nodes in the graph has
a proper name for their endpoint in the application context
2019-12-18 16:14:51 -05:00
Artem Bilan
aa895e7365 Upgrade dependencies; prepare for release
* Fix MongoDB tests for changed return type from Spring Data MongoDB
2019-12-04 13:07:56 -05:00
Artem Bilan
94e08169a5 Use EmitterProcessor in the FluxMessageChannel (#3104)
* Use EmitterProcessor in the FluxMessageChannel

The `EmitterProcessor` has a good logic to block upstream producer
when its downstream subscriber cannot keep up with overproducing.

* Rework `FluxMessageChannel` logic to rely on the `EmitterProcessor`
instead of `Flux.create()`
* Cancel `FluxMessageChannel` internal subscriptions in the `destroy()`
* Fix `ReactiveStreamsTests.testFluxTransform()` for the splitter's
delimiter
* Ensure in the `FluxMessageChannelTests.testFluxMessageChannel`
that we can have several concurrent subscribers to the
`FluxMessageChannel`

* * Use `flux.onComplete()` instead of iteration over subscribers
* Change `subscribers` list into just `AtomicInteger` count marker
* fix `DefaultSplitterTests` according a new logic in the `FluxMessageChannel`

* GH-3107: Add errorOnTimeout for TcpInboundGateway

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

The `MessagingGatewaySupport` has an `errorOnTimeout` option to throw
a `MessageTimeoutException` when downstream reply doesn't come back in
time for configured reply timeout

* Expose an `errorOnTimeout` option as a `TcpInboundGateway` ctor
property
* Add new factory methods into a `Tcp` factory for Java DSL
* Ensure a property works as expected in the `IpIntegrationTests`
* Document a new option

* * Use `delaySubscription()` for subscribing publishers in the `FluxMessageChannel`
to wait until this one subscribed.
* Use an `EmitterProcessor` to catch subscriptions and pass them as a
signal to delayed upstream publishers
* Fix  `FluxMessageChannelTests.testFluxMessageChannelCleanUp` to
verify an actual property instead of removed.
* Fix `RSocketOutboundGatewayIntegrationTests` for the proper subscription
into a `FluxMessageChannel` before actual interaction with an RSocket
gateway.
This should help us also to avoid some race conditions in the future

* Revert "GH-3107: Add errorOnTimeout for TcpInboundGateway"

This reverts commit fa6119ddc4e423e8b15ca3fdc9fc4c79ea9d56af.

* * Refactor `FluxMessageChannel` to use `ReplayProcessor` for `subscribedSignal`.
This one is used `delaySubscription` for the upstream publishers
* Use a `AtomicBoolean` for subscription state since `doOnSubscribe()`
is called before `EmitterProcessor` adds subscribers for its `downstreams`
* Use `publishOn(Schedulers.boundedElastic())` for upstream publishers
to avoid blocking over there when our `EmitterProcessor` doesn't have
enough demand
* Refactor reactive tests to have a subscription into the `FluxMessageChannel`
earlier than emission happens for it

* * Use `Flux.subscribe(Consumer)` instead of `doOnNext(Consumer).subscribe()`

* * Emit `subscribedSignal` value after `.subscribe(subscriber)`
instead of `doOnSubscribe`
* Check for `this.processor.hasDownstreams()` before emitting such an event

* * Use `this.processor.hasDownstreams()` as a value to emit for `subscribedSignal`.
This way we are less vulnerable race conditions when subscribers are changed
actively
2019-12-03 12:19:14 -05:00
Artem Bilan
8e7c1067f3 Fix pub/sub race conditions in Reactive tests 2019-12-02 14:03:12 -05:00
Artem Bilan
516ecbcf8b GH-3114: Honor SpEL contract in ExpressionEvalMap
Fixes https://github.com/spring-projects/spring-integration/issues/3114

The contract of SpEL with its
`getValue(EvaluationContext context, @Nullable Object rootObject)` is
that we need to deal with provided `rootObject` even if it is `null`
and don't consult with `context.getRootObject()`

* Fix `ExpressionEvalMap` to have an internal `rootExplicitlySet`
to indicate that `root` explicitly provided by consumer, even if it is null.
According this flag call respective `Expression.getValue()`
* Add `@Nullable` to methods and their arguments into `ExpressionEvalMap`
& `FunctionExpression` to honor `Expression` contracts
* Populate an `HttpEntity` explicitly into `ExpressionEvalMap` from the
`HttpRequestHandlingEndpointSupport` and `WebFluxInboundEndpoint` for
full picture

* Fix JavaDocs indentations in the `ExpressionEvalMap`
2019-11-25 13:03:33 -05:00
Artem Bilan
0ec9859c0f Refactor some tests into JUnit 5
* Improve their interaction with Reactor Test
2019-11-19 15:28:55 -05:00
Artem Bilan
0f5bd4a40a INT-3494: Resolve dir for writing as a Resource (#3109)
* INT-3494: Resolve dir for writing as a Resource

JIRA: https://jira.spring.io/browse/INT-3494

The expression for local directory can be resolved into a `Resource`
or resource location.
* Fix `ExpressionUtils.expressionToFile()` to support `Resource` and
also use `ResourceUtils.getFile(path)` when expression result is a string
* Modify tests to ensure that resource is resolved properly
* Upgrade affected tests to JUnit 5
* Mention an new functionality in docs

* * Improve Java doc for `ExpressionUtils.expressionToFile()`
* Finish the sentence in the `file.adoc`
2019-11-14 16:27:59 -05:00
Artem Bilan
72f7c72392 GH-3107: Add errorOnTimeout for TcpInboundGateway
Fixes https://github.com/spring-projects/spring-integration/issues/3107

The `MessagingGatewaySupport` has an `errorOnTimeout` option to throw
a `MessageTimeoutException` when downstream reply doesn't come back in
time for configured reply timeout

* Expose an `errorOnTimeout` option as a `TcpInboundGateway` ctor
property
* Add new factory methods into a `Tcp` factory for Java DSL
* Ensure a property works as expected in the `IpIntegrationTests`
* Document a new option

* Add a setter for MessagingGatewaySupport.errorOnTimeout option
* Expose an `errorOnTimeout` option on the DSL's `MessagingGatewaySpec`
making all the out-of-the-box inbound gateways possible to react to the
`MessageTimeoutException` when no reply during reply timeout
* Propagate properly `errorOnTimeout` in the `JmsInboundGateway`
* Modify docs respectively

* Improve docs about `errorOnTimeout`
2019-11-14 09:07:46 -05:00
Artem Bilan
d9e09b93fc Test that Kotlin synthetic classes work in SpEL
Related to https://github.com/spring-projects/spring-framework/issues/23812

* Modify `FunctionsTests.kt` test to be sure that fall back to SpEL
invocation in case of Kotlin lambda works as expected.
This is like an additional test to the fix in Spring Framework
2019-11-13 10:09:08 -05:00
Artem Bilan
a6fb891a81 Fix MMIH to check for Advised in getTargetClass()
* Currently `MessagingMethodInvokerHelper.getTargetClass()` logs a
debug message when it can't cast a `targetObject` into an `Advised`.
Such a message is misleading and really unnecessary noise in the target
applications
* Fix the logic of the method to check `targetObject instanceof Advised`
before trying to extract interfaces from proxy.
This way we don't need to catch any exceptions at all.
If something will fail, it should be bubbled upstream for possible fixes
* Convert `MethodInvokingMessageProcessorTests` to JUnit 5 and restore
a couple tests
2019-11-10 10:44:17 -05:00
Artem Bilan
dd1d65bb23 Refinement for ResolvableType JSON header
Fix a logic in the `JsonToObjectTransformer.obtainResolvableTypeFromHeadersIfAny`
when we have both `JsonHeaders.RESOLVABLE_TYPE` and `JsonHeaders.TYPE_ID`
and `JsonHeaders.RESOLVABLE_TYPE` header is valid `ResolvableType`, so
`JsonHeaders.TYPE_ID` doesn't override its value to return
2019-11-01 15:54:12 -04:00
Artem Bilan
ad97f818cf GH-3096: Skip RESOLVABLE_TYPE header in mapping (#3098)
* GH-3096: Skip RESOLVABLE_TYPE header in mapping

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

When we sent an AMQP message we should not map a
`JsonHeaders.RESOLVABLE_TYPE` header which is a `ResolvableType` and
isn not compatible after converting to string

Also improve `JsonToObjectTransformer` to ignore a
`JsonHeaders.RESOLVABLE_TYPE` when it is type of String

* * Fix `obtainResolvableTypeFromHeadersIfAny()` logic
2019-11-01 15:28:06 -04:00
Artem Bilan
845a39653e Revert testReactiveStreamsConsumerPollableChannel
https://build.spring.io/browse/INT-MASTER-1776/

Looks like there is a race condition between subscribers
2019-11-01 15:03:06 -04:00
Artem Bilan
36c9f72a9d Use EmitterProcessor for Channels adaptation (#3100)
* Use `EmitterProcessor` for Channels adaptation

Related https://github.com/spring-cloud/spring-cloud-stream/issues/1835

To honor a back-pressure after `MessageChannel` adaptation it is better
to use an `EmitterProcessor.create(1)` instead of `Flux.create()`.
This way whenever an emitter buffer is full, we block upstream producer
and don't allow it to produce more messages

**Cherry-pick to 5.1.x**

* * Wrap every new subscription into a `Flux.defer()`
* Fix `ReactiveStreamsConsumerTests` to use a new `Subscription` after
each `stop()/start()` on the `ReactiveStreamsConsumer`

* * Remove unused imports
2019-11-01 14:49:29 -04:00
Sergei Egorov
69401c263c Back-pressure tests for SubscribableChPubAdapter
* Add back-pressure tests for SubscribableChannelPublisherAdapter
2019-11-01 12:13:11 -04:00
Artem Bilan
66c3eff2ba Fix new Sonar smells 2019-10-29 08:11:31 -04:00
Artem Bilan
ca56a0eb80 Extract BaseIntegrationFlowDefinition (#3087)
* Extract `BaseIntegrationFlowDefinition`

Kotlin inline reified functions cannot override as syntax sugar generic
Java methods.

* Extract a `BaseIntegrationFlowDefinition` with strong typed methods,
plus those which doesn't have a syntax sugar variants
* Leave in the `IntegrationFlowDefinition` only those generic methods
which are just a syntax sugar without any types requirements

This way we can write Kotlin inline reified functions as an extension
 with the same names to make a Kotlin DSL much cleaner

* * Override methods in the IntegrationFlowDefinition for bytecode compatibility
* Extract `protected` getters and setters for `BaseIntegrationFlowDefinition`
properties to allow a proper extension
* Use those getters and setters in the code

* * Add // NOSONAR for overridden methods
2019-10-28 10:11:15 -04:00
Artem Bilan
1a2907eeb3 Upgrade dependencies; fix deprecations 2019-10-25 15:25:14 -04:00
Artem Bilan
375f3c1317 Ensure that dynamic routes are included into graph (#3085)
* Ensure that dynamic routes are included into graph

Modify an `IntegrationGraphServerTests` to be sure that dynamic routes
are included into the graph (with links) after sending a message to the
router and rebuilding a graph

* * Fix test for the actual numbers to expect
2019-10-21 15:19:17 -04:00
Artem Bilan
1e50707370 Fix new Sonar smells 2019-10-17 10:09:55 -04:00
Artem Bilan
33667884a7 GH-3079: Use getMostSpecificMethod for SpEL calls (#3082)
* GH-3079: Use getMostSpecificMethod for SpEL calls

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

It turns out that we need to use a *most specific* method for the target
to be called reflectively from the SpEL

NOTE: We drop a *Method not found* error in case of wrong method source
since now we find a right source via `ClassUtils.getMostSpecificMethod()`

**Cherry-pick to 5.1.x**

* * `@Ignore` `MethodInvokingMessageProcessorTests.testProcessMessageMethodNotFound()`
instead of removal
2019-10-16 15:57:33 -04:00
Gary Russell
87af95ee7a GH-3083: Support @Header with dotted literals
Fixes https://github.com/spring-projects/spring-integration/issues/3083

`@Header("foo.bar")` means extract property `bar` from header `foo`.

Support `@Header("'foo.bar'")`, meaning get the value of header `foo.bar`.

**cherry-pick to 5.1.x, 4.3.x**
2019-10-16 11:13:19 -04:00
Artem Bilan
911cdc86b5 Refinement for gateway Mono processing (#3075)
* Refinement for gateway Mono processing

* Introduce a `MessagingGatewaySupport.MonoReplyChannel` instead of
`FutureReplyChannel` for better on demand handling and reusing a
`Mono` returned from the target handler
* Refactor `GatewayProxyFactoryBean` to identify a target return type
(including generics for `Function`) during initialization
* Handle a `Mono` return type via
`MessagingGatewaySupport.sendAndReceiveMessageReactive()`
* Some `@Nullable` in the `GatewayProxyFactoryBean` and `ExpressionUtils`
* Add `MonoFunction` test-case into the `FunctionsTests.kt`

* * Deprecate `GatewayProxyFactoryBean.setServiceInterface()` in favor of
ctor initialization
* Fix `GatewayProxyFactoryBean.setServiceInterface()` usage in tests
2019-10-14 15:31:04 -04:00
Artem Bilan
2a8615539f Deprecate IntFlows.from(service, methodName)
The method reference together with a `IntegrationFlows.frm(Supplier<?>)`
do the trick to avoid a method name resolution and also gives us a code
navigation in the IDE
2019-10-02 10:58:03 -04:00
Artem Bilan
007e1a0924 Improve in generics for some Publisher API 2019-09-30 15:17:36 -04:00
Artem Bilan
ad96ca49f1 Add Reactive Stream chapter into docs
* Improve `channel.adoc`: polishing, new channels, java config
* Make `LoadBalancingStrategy` in the `DirectChannel` ctor as
`@Nullable` to reflect the real logic behind

* More Dos and polishing according PR comments
* Mention WebFlux and RSocket endpoints in the `endpoint-summary.adoc`
table

* More reactive streams docs
* `SourcePollingChannelAdapter` polishing
* Wrap multi-value publisher into `Mono.just()` in the `AbstractMessageProducingHandler`
instead of emitting just only a first item for the standard reply

Doc polishing
2019-09-30 14:36:33 -04:00
Artem Bilan
eeb951b0da Fix new Sonar Smells
* Change `whats-new.adoc#x5.2-behavior` to point for the whole
`5.1-to-5.2-Migration-Guide`
2019-09-29 10:28:09 -04:00
Gary Russell
9994997917 GH-3067: Use default NullChannel instance if poss.
Resolves https://github.com/spring-projects/spring-integration/issues/3067

Also add missing receive counter.

* Late binding of null discard channel; checkstyle

* Fix test; fall back to new NullChannel(); always evaluate tx expressions
2019-09-27 17:14:51 -04:00
Gary Russell
0c7cae15da Upgrade to Jackson 2.10
* Remove extraneous code

* Realign white listing with similar implementation in Spring Security: c0b48338f4

* 2.10 GA
2019-09-27 12:25:41 -04:00
Artem Bilan
c4aceb6bb5 Hide toReactivePublisher() from lambdas (#3065)
* Hide `toReactivePublisher()` from lambdas

When an `IntegrationFlow` is declared via lambda, it is impossible
to materialize it as a `Publisher` since we lose a Lambda context and
finish with a `NoSuchBeanException` when we would like to inject that
`Publisher`

* Make `IntegrationFlowDefinition.toReactivePublisher()` as `protected`
and expose it on the `IntegrationFlowBuilder` level
* Use `Channels` as a singleton: no reason in overhead for its instances
* Some code style polishing for `IntegrationFlowDefinition`

* Restore `Channels.super()` call
2019-09-26 15:08:58 -04:00
Artem Bilan
b12657c599 Document RSocket support
* Fix some typos in `webflux.adoc` and `dsl.adoc`
* Make `FunctionsTests.kt` more Kotlin friendly
* Improve RSocket components and tests for them,
especially rely on the default `RSocketStrategies` in the
target SF RSocket components
* Rework `ServerRSocketConnector.setClientRSocketKeyStrategy` to use the whole `MessageHeaders` for consultation.
It turns out that just destination is not enough since it can be used from different clients
* Make the key based on the provided `setupData` by default
* Include all the `MessageHeaders` into the `RSocketConnectedEvent`

* Improve Docs according review feedback and Docs in SF

Doc polishing
2019-09-24 14:55:04 -04:00
Artem Bilan
21335812a3 Remove IntegrationNode.Stats.deprecated const 2019-09-22 09:34:48 -04:00
Gary Russell
a550ebfaad Fix test after previous commit
- the deprecated field is now last instead of first
2019-09-21 11:34:47 -04:00
Gary Russell
7d949f7f8a Fix Sonar issues 2019-09-21 09:40:25 -04:00
Gary Russell
58c0b9885b Add failure counter to AbstractMessageSource
* Clear timers in AMH.destroy()
2019-09-20 10:53:18 -04:00
Artem Bilan
aa29bb15e3 Guard Micrometer stats for NPE: no Micrometer
If there is no Micrometer in classpath, the `timers` and `counters`
are not populated into Graph

* Check for `null` before calling `Supplier`
2019-09-20 09:45:04 -04:00
Artem Bilan
c4ec73f9a0 Fix Checkstyle violation 2019-09-20 09:30:22 -04:00
Gary Russell
87840bcfe4 GH-3056: Add Micrometer Metrics to Runtime Graph
Resolves https://github.com/spring-projects/spring-integration/issues/3056

* Retrieve meters each time the graph is rendered, not just when it is built.
2019-09-20 09:15:55 -04:00
Artem Bilan
9272782a48 GH-3052: Fix custom converters for lambdas
Fixes https://github.com/spring-projects/spring-integration/issues/3052

Starting with version `5.1`, a `LambdaMessageProcessor` is based on the
`MessageConverter` instead of plain `ConversionService`.
(A `ConfigurableCompositeMessageConverter` is used from the application
context.)
However a type conversion based on the `@IntegrationConverter` is lost
in the `GenericMessageConverter`  because it doesn't use an
`integrationConversionService` from the application context

* Change `ConfigurableCompositeMessageConverter` to configure a
 `GenericMessageConverter`  with an  `integrationConversionService`
 if any
* Fix `MessagingMethodInvokerHelper` to populate a `BeanFactory` into
its internal `ConfigurableCompositeMessageConverter`
* Ensure in the `LambdaMessageProcessorTests` that
`@IntegrationConverter` is applied for ``LambdaMessageProcessor` as well

**Cherry-pick to 5.1.x**
2019-09-13 18:37:33 +01:00
Artem Bilan
87f5409677 Fix more Sonar smells for GatewayProxyFactoryBean 2019-09-09 08:54:20 -04:00
Artem Bilan
f68cf28de7 Fix new Sonar smells for GatewayProxyFactoryBean 2019-09-07 10:58:21 -04:00
Artem Bilan
29bebdba97 GH-3047: Add GatewayProxySpec for Java DSL
Fixes https://github.com/spring-projects/spring-integration/issues/3047

* Improve `GatewayProxyFactoryBean` to determine the return type of the
method call from the interface generic types, when the `serviceInterface`
is a `java.util.function.Function`
* Propagate `MethodArgsHolder` as a `rootObject` for SpEL evaluations
* Deprecate `#gatewayMethod` and `#args` evaluation context variables
in favor of `MethodArgsHolder` as root object.
They will be removed in the future release and a single
`EvaluationContext` will be used for all the gateway expressions
* Introduce an
`IntegrationFlows.from(Class<?> serviceInterface, Consumer<GatewayProxySpec> endpointConfigurer)`
to allow to configure any valid gateway proxy options similar to what
we have with the `<gateway>` and `@MessagingGateway`.
This way we are very close to consistency between different approaches

* * Remove `default` prefix from `GatewayProxySpec` options
* Document the change
2019-09-06 13:46:16 -04:00
Frank Fiorante
5073da8a1b Fix Typo in Flow Validation 2019-08-22 15:47:32 -04:00
Gary Russell
69dd180d0c JUnit 5 Log Level Adjuster
* Fix copyright, javadoc.
2019-08-16 10:36:23 -04:00
Gary Russell
bf1d562c3b Fix MergedAnnotations.SearchStrategy deprecations
a6021cc968
2019-07-31 11:35:03 -04:00
Gary Russell
fc827e1f92 GH-3004: Revert scope of handler factories
See https://github.com/spring-projects/spring-integration/issues/3004

https://github.com/spring-projects/spring-framework/issues/23352
is now resolved so the `DefaultMessageHandlerMethodFactory` can be
singletons.
2019-07-31 10:14:02 -04:00
Gary Russell
f7fc3360cd Fix Sonar issues 2019-07-31 09:40:54 -04:00
Gary Russell
884db2c609 Checkstyle fix 2019-07-30 17:50:05 -04:00
Gary Russell
580ca865fe Test fixes for AssertJ changes 2019-07-30 17:38:29 -04:00