From b6fe6858738ec7a7f5f43fe6931f986ea04ab806 Mon Sep 17 00:00:00 2001 From: abilan Date: Fri, 28 Jul 2023 11:54:59 -0400 Subject: [PATCH] Fix some Kotlin <-> Java DSL interoperability * Remove generic argument from the `EnricherSpec.property()` which simply does nothing, but noise - `Object` is enough * Do the same for `EnricherSpec.header()` * Fix `KotlinEnricherSpec`, respectively: no generic argument - just `Any` * Make `KotlinIntegrationFlowDefinition.route()` to expect non-null for `router` arg * Add `& Any` to generic params of the `KotlinRouterSpec` methods - according compiler warning requirements --- .../integration/dsl/EnricherSpec.java | 16 ++++++---------- .../integration/dsl/KotlinEnricherSpec.kt | 6 +++--- .../dsl/KotlinIntegrationFlowDefinition.kt | 2 +- .../integration/dsl/KotlinRouterSpec.kt | 8 ++++---- 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EnricherSpec.java b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EnricherSpec.java index 7a8ed03808..d77917252b 100644 --- a/spring-integration-core/src/main/java/org/springframework/integration/dsl/EnricherSpec.java +++ b/spring-integration-core/src/main/java/org/springframework/integration/dsl/EnricherSpec.java @@ -182,11 +182,10 @@ public class EnricherSpec extends ConsumerEndpointSpec the value type. * @return the enricher spec. * @see ContentEnricher#setPropertyExpressions(Map) */ - public EnricherSpec property(String key, V value) { + public EnricherSpec property(String key, Object value) { this.propertyExpressions.put(key, new ValueExpression<>(value)); return _this(); } @@ -220,11 +219,10 @@ public class EnricherSpec extends ConsumerEndpointSpec the value type. * @return the enricher spec. * @see ContentEnricher#setHeaderExpressions(Map) */ - public EnricherSpec header(String name, V value) { + public EnricherSpec header(String name, Object value) { return header(name, value, null); } @@ -232,13 +230,12 @@ public class EnricherSpec extends ConsumerEndpointSpec the value type. * @return the enricher spec. * @see ContentEnricher#setHeaderExpressions(Map) */ - public EnricherSpec header(String name, V value, @Nullable Boolean overwrite) { - AbstractHeaderValueMessageProcessor headerValueMessageProcessor = - new StaticHeaderValueMessageProcessor(value); + public EnricherSpec header(String name, Object value, @Nullable Boolean overwrite) { + AbstractHeaderValueMessageProcessor headerValueMessageProcessor = + new StaticHeaderValueMessageProcessor<>(value); headerValueMessageProcessor.setOverwrite(overwrite); return header(name, headerValueMessageProcessor); } @@ -305,11 +302,10 @@ public class EnricherSpec extends ConsumerEndpointSpec the value type. * @return the enricher spec. * @see ContentEnricher#setHeaderExpressions(Map) */ - public EnricherSpec header(String headerName, HeaderValueMessageProcessor headerValueMessageProcessor) { + public EnricherSpec header(String headerName, HeaderValueMessageProcessor headerValueMessageProcessor) { Assert.hasText(headerName, "'headerName' must not be empty"); this.headerExpressions.put(headerName, headerValueMessageProcessor); return _this(); diff --git a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinEnricherSpec.kt b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinEnricherSpec.kt index a2bcb75a43..7cd1dd43c1 100644 --- a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinEnricherSpec.kt +++ b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinEnricherSpec.kt @@ -85,7 +85,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec) this.delegate.shouldClonePayload(shouldClonePayload) } - fun property(key: String, value: V) { + fun property(key: String, value: Any) { this.delegate.property(key, value) } @@ -97,7 +97,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec) this.delegate.propertyFunction(key, function) } - fun header(name: String, value: V, overwrite: Boolean?) { + fun header(name: String, value: Any, overwrite: Boolean?) { this.delegate.header(name, value, overwrite) } @@ -109,7 +109,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec) this.delegate.header(name, function, overwrite) } - fun header(headerName: String, headerValueMessageProcessor: HeaderValueMessageProcessor) { + fun header(headerName: String, headerValueMessageProcessor: HeaderValueMessageProcessor) { this.delegate.header(headerName, headerValueMessageProcessor) } diff --git a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt index 4ef28eb191..696369a09c 100644 --- a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt +++ b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinIntegrationFlowDefinition.kt @@ -1043,7 +1043,7 @@ class KotlinIntegrationFlowDefinition(@PublishedApi internal val delegate: Integ * current integration flow position. * In addition, accept options for the integration endpoint using [GenericEndpointSpec]. */ - fun route(router: R, endpointConfigurer: GenericEndpointSpec.() -> Unit = {}) { + fun route(router: R, endpointConfigurer: GenericEndpointSpec.() -> Unit = {}) { this.delegate.route(router, endpointConfigurer) } diff --git a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRouterSpec.kt b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRouterSpec.kt index 37b0149fd5..598894ba6e 100644 --- a/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRouterSpec.kt +++ b/spring-integration-core/src/main/kotlin/org/springframework/integration/dsl/KotlinRouterSpec.kt @@ -51,19 +51,19 @@ class KotlinRouterSpec(override val delegat this.delegate.channelKeyFallback(channelKeyFallback) } - fun channelMapping(key: K, channelName: String) { + fun channelMapping(key: K & Any, channelName: String) { this.delegate.channelMapping(key, channelName) } - fun channelMapping(key: K, channel: MessageChannel) { + fun channelMapping(key: K & Any, channel: MessageChannel) { this.delegate.channelMapping(key, channel) } - fun subFlowMapping(key: K, subFlow: KotlinIntegrationFlowDefinition.() -> Unit) { + fun subFlowMapping(key: K & Any, subFlow: KotlinIntegrationFlowDefinition.() -> Unit) { subFlowMapping(key) { definition -> subFlow(KotlinIntegrationFlowDefinition(definition)) } } - fun subFlowMapping(key: K, subFlow: IntegrationFlow) { + fun subFlowMapping(key: K & Any, subFlow: IntegrationFlow) { this.delegate.subFlowMapping(key, subFlow) }