Skip to content

Commit

Permalink
Fix some Kotlin <-> Java DSL interoperability
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
artembilan committed Jul 28, 2023
1 parent abcc115 commit b6fe685
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -182,11 +182,10 @@ public EnricherSpec shouldClonePayload(boolean shouldClonePayload) {
/**
* @param key the key.
* @param value the value.
* @param <V> the value type.
* @return the enricher spec.
* @see ContentEnricher#setPropertyExpressions(Map)
*/
public <V> EnricherSpec property(String key, V value) {
public EnricherSpec property(String key, Object value) {
this.propertyExpressions.put(key, new ValueExpression<>(value));
return _this();
}
Expand Down Expand Up @@ -220,25 +219,23 @@ public <P> EnricherSpec propertyFunction(String key, Function<Message<P>, Object
* Set a header with the value if it is not already present.
* @param name the header name.
* @param value the value.
* @param <V> the value type.
* @return the enricher spec.
* @see ContentEnricher#setHeaderExpressions(Map)
*/
public <V> EnricherSpec header(String name, V value) {
public EnricherSpec header(String name, Object value) {
return header(name, value, null);
}

/**
* @param name the header name.
* @param value the value.
* @param overwrite true to overwrite the header if already present.
* @param <V> the value type.
* @return the enricher spec.
* @see ContentEnricher#setHeaderExpressions(Map)
*/
public <V> EnricherSpec header(String name, V value, @Nullable Boolean overwrite) {
AbstractHeaderValueMessageProcessor<V> headerValueMessageProcessor =
new StaticHeaderValueMessageProcessor<V>(value);
public EnricherSpec header(String name, Object value, @Nullable Boolean overwrite) {
AbstractHeaderValueMessageProcessor<Object> headerValueMessageProcessor =
new StaticHeaderValueMessageProcessor<>(value);
headerValueMessageProcessor.setOverwrite(overwrite);
return header(name, headerValueMessageProcessor);
}
Expand Down Expand Up @@ -305,11 +302,10 @@ private EnricherSpec headerExpression(String name, Expression expression, @Nulla
* Set a header value using an explicit {@link HeaderValueMessageProcessor}.
* @param headerName the header name.
* @param headerValueMessageProcessor the headerValueMessageProcessor.
* @param <V> the value type.
* @return the enricher spec.
* @see ContentEnricher#setHeaderExpressions(Map)
*/
public <V> EnricherSpec header(String headerName, HeaderValueMessageProcessor<V> headerValueMessageProcessor) {
public EnricherSpec header(String headerName, HeaderValueMessageProcessor<Object> headerValueMessageProcessor) {
Assert.hasText(headerName, "'headerName' must not be empty");
this.headerExpressions.put(headerName, headerValueMessageProcessor);
return _this();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec)
this.delegate.shouldClonePayload(shouldClonePayload)
}

fun <V> property(key: String, value: V) {
fun property(key: String, value: Any) {
this.delegate.property(key, value)
}

Expand All @@ -97,7 +97,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec)
this.delegate.propertyFunction(key, function)
}

fun <V> header(name: String, value: V, overwrite: Boolean?) {
fun header(name: String, value: Any, overwrite: Boolean?) {
this.delegate.header(name, value, overwrite)
}

Expand All @@ -109,7 +109,7 @@ class KotlinEnricherSpec(override val delegate: EnricherSpec)
this.delegate.header(name, function, overwrite)
}

fun <V> header(headerName: String, headerValueMessageProcessor: HeaderValueMessageProcessor<V>) {
fun header(headerName: String, headerValueMessageProcessor: HeaderValueMessageProcessor<Any>) {
this.delegate.header(headerName, headerValueMessageProcessor)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <R : AbstractMessageRouter?> route(router: R, endpointConfigurer: GenericEndpointSpec<R>.() -> Unit = {}) {
fun <R : AbstractMessageRouter> route(router: R, endpointConfigurer: GenericEndpointSpec<R>.() -> Unit = {}) {
this.delegate.route(router, endpointConfigurer)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,19 @@ class KotlinRouterSpec<K, R : AbstractMappingMessageRouter>(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)
}

Expand Down

0 comments on commit b6fe685

Please sign in to comment.