Introduce HeaderFilterSpec to streamline DSL API (#8636)
* Introduce HeaderFilterSpec to streamline DSL API The concern has been driven by the discussion from: https://github.com/spring-projects/spring-integration/issues/8625 The point is that Java method arguments are not so descriptive when we read the code. Therefore, it is better to design DSL the way it would be cleaner from reading perspective. Plus less choice of methods to chain would give a better end-user experience from coding. * Add a `HeaderFilterSpec` which can accept `headersToRemove` and `patternMatch` as individual options instead of top-level deprecated `headerFilter(headersToRemove, patternMatch)` `IntegrationFlow` method. This way Kotlin and Groovy DSLs get a gain from their "inner section" style. * Such a `Consumer<HeaderFilterSpec>` way to configure an endpoint is similar to already existing `aggregate(Consumer<AggregatorSpec>)`, `resequence(Consumer<ResequencerSpec>)` etc. In other words those components which has a dedicated `ConsumerEndpointSpec` extension are OK from an idiomatic DSL style perspective * Expose a `HeaderFilter.setHeadersToRemove()` to make it working smoothly with this new DSL requirements * Apply a new `headerFilter()` style into Kotlin and Groovy DSLs This is just an initial work to surface an idea. If it is OK, I'll slow continue with others to realign and simplify the paradox of choice. * * Fix asterisk imports in the `KotlinIntegrationFlowDefinition`
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2022 the original author or authors.
|
||||
* Copyright 2016-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,7 +60,6 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
/**
|
||||
* @author Artem Bilan
|
||||
* @author Gary Russell
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@@ -241,7 +240,7 @@ public class CorrelationHandlerTests {
|
||||
.enrichHeaders(h ->
|
||||
h.headerFunction(IntegrationMessageHeaderAccessor.SEQUENCE_NUMBER, Message::getPayload))
|
||||
.resequence(r -> r.releasePartialSequences(true).correlationExpression("'foo'"))
|
||||
.headerFilter("foo", false);
|
||||
.headerFilter(headerFilterSpec -> headerFilterSpec.headersToRemove("foo").patternMatch(false));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -182,11 +182,16 @@ class KotlinDslTests {
|
||||
@Test
|
||||
fun `flow from lambda`() {
|
||||
val replyChannel = QueueChannel()
|
||||
val message = MessageBuilder.withPayload("test").setReplyChannel(replyChannel).build()
|
||||
val message = MessageBuilder.withPayload("test")
|
||||
.setHeader("headerToRemove", "no value")
|
||||
.setReplyChannel(replyChannel)
|
||||
.build()
|
||||
|
||||
this.flowLambdaInput.send(message)
|
||||
|
||||
assertThat(replyChannel.receive(10_000)?.payload).isNotNull().isEqualTo("TEST")
|
||||
val receive = replyChannel.receive(10_000)
|
||||
assertThat(receive?.payload).isNotNull().isEqualTo("TEST")
|
||||
assertThat(receive.headers).doesNotContain("headerToRemove", null)
|
||||
assertThat(this.wireTapChannel.receive(10_000)?.payload).isNotNull().isEqualTo("test")
|
||||
}
|
||||
|
||||
@@ -308,6 +313,10 @@ class KotlinDslTests {
|
||||
fun flowLambda() =
|
||||
integrationFlow {
|
||||
filter<String>({ it === "test" }) { id("filterEndpoint") }
|
||||
headerFilter {
|
||||
patternMatch(false)
|
||||
headersToRemove("notAHeader", "headerToRemove")
|
||||
}
|
||||
wireTap {
|
||||
channel { queue("wireTapChannel") }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user