Skip to content

Commit 10ea577

Browse files
artembilangaryrussell
authored andcommitted
GH-3615: Make log() as non-terminal in DSL
Fixes #3615 The `log()` operator for Java DSL in the end of flow causes a confusion for its different behavior and, therefore, inconsistency with expectations * Populate a `bridge()` in the end of flow instead of `nullChannel` when the current component is `WireTapSpec` (relevant to `wireTap()` and `log()`) * Deprecate a `logAndReply()` operator since its behavior is now included into the `log()` in the end if flow * Fix tests to use just `log()` in the end from now on * Fix `dsl.adoc` for the new `log()` behaviour in the end of flow
1 parent 802d217 commit 10ea577

File tree

5 files changed

+41
-51
lines changed

5 files changed

+41
-51
lines changed

spring-integration-core/src/main/java/org/springframework/integration/dsl/BaseIntegrationFlowDefinition.java

+27-40
Original file line numberDiff line numberDiff line change
@@ -2182,9 +2182,6 @@ public B gateway(IntegrationFlow flow, Consumer<GatewayEndpointSpec> endpointCon
21822182
* logging level and {@code org.springframework.integration.handler.LoggingHandler}
21832183
* as a default logging category.
21842184
* <p> The full request {@link Message} will be logged.
2185-
* <p> When this operator is used in the end of flow, it is treated
2186-
* as one-way handler without any replies to continue.
2187-
* The {@link #logAndReply()} should be used for request-reply configuration.
21882185
* @return the current {@link BaseIntegrationFlowDefinition}.
21892186
* @see #wireTap(WireTapSpec)
21902187
*/
@@ -2198,9 +2195,6 @@ public B log() {
21982195
* logging level and {@code org.springframework.integration.handler.LoggingHandler}
21992196
* as a default logging category.
22002197
* <p> The full request {@link Message} will be logged.
2201-
* <p> When this operator is used in the end of flow, it is treated
2202-
* as one-way handler without any replies to continue.
2203-
* The {@link #logAndReply()} should be used for request-reply configuration.
22042198
* @param level the {@link LoggingHandler.Level}.
22052199
* @return the current {@link BaseIntegrationFlowDefinition}.
22062200
* @see #wireTap(WireTapSpec)
@@ -2214,9 +2208,6 @@ public B log(LoggingHandler.Level level) {
22142208
* with the {@link LoggingHandler} subscriber for the provided logging category
22152209
* and {@code INFO} logging level.
22162210
* <p> The full request {@link Message} will be logged.
2217-
* <p> When this operator is used in the end of flow, it is treated
2218-
* as one-way handler without any replies to continue.
2219-
* The {@link #logAndReply()} should be used for request-reply configuration.
22202211
* @param category the logging category to use.
22212212
* @return the current {@link BaseIntegrationFlowDefinition}.
22222213
* @see #wireTap(WireTapSpec)
@@ -2230,9 +2221,6 @@ public B log(String category) {
22302221
* with the {@link LoggingHandler} subscriber for the provided
22312222
* {@link LoggingHandler.Level} logging level and logging category.
22322223
* <p> The full request {@link Message} will be logged.
2233-
* <p> When this operator is used in the end of flow, it is treated
2234-
* as one-way handler without any replies to continue.
2235-
* The {@link #logAndReply()} should be used for request-reply configuration.
22362224
* @param level the {@link LoggingHandler.Level}.
22372225
* @param category the logging category to use.
22382226
* @return the current {@link BaseIntegrationFlowDefinition}.
@@ -2247,9 +2235,6 @@ public B log(LoggingHandler.Level level, String category) {
22472235
* with the {@link LoggingHandler} subscriber for the provided
22482236
* {@link LoggingHandler.Level} logging level, logging category
22492237
* and SpEL expression for the log message.
2250-
* <p> When this operator is used in the end of flow, it is treated
2251-
* as one-way handler without any replies to continue.
2252-
* The {@link #logAndReply()} should be used for request-reply configuration.
22532238
* @param level the {@link LoggingHandler.Level}.
22542239
* @param category the logging category.
22552240
* @param logExpression the SpEL expression to evaluate logger message at runtime
@@ -2267,9 +2252,6 @@ public B log(LoggingHandler.Level level, String category, String logExpression)
22672252
* with the {@link LoggingHandler} subscriber for the {@code INFO} logging level,
22682253
* the {@code org.springframework.integration.handler.LoggingHandler}
22692254
* as a default logging category and {@link Function} for the log message.
2270-
* <p> When this operator is used in the end of flow, it is treated
2271-
* as one-way handler without any replies to continue.
2272-
* The {@link #logAndReply()} should be used for request-reply configuration.
22732255
* @param function the function to evaluate logger message at runtime
22742256
* @param <P> the expected payload type.
22752257
* against the request {@link Message}.
@@ -2287,9 +2269,6 @@ public <P> B log(Function<Message<P>, Object> function) {
22872269
* the {@code org.springframework.integration.handler.LoggingHandler}
22882270
* as a default logging category and SpEL expression to evaluate
22892271
* logger message at runtime against the request {@link Message}.
2290-
* <p> When this operator is used in the end of flow, it is treated
2291-
* as one-way handler without any replies to continue.
2292-
* The {@link #logAndReply()} should be used for request-reply configuration.
22932272
* @param logExpression the {@link Expression} to evaluate logger message at runtime
22942273
* against the request {@link Message}.
22952274
* @return the current {@link BaseIntegrationFlowDefinition}.
@@ -2306,9 +2285,6 @@ public B log(Expression logExpression) {
23062285
* the {@code org.springframework.integration.handler.LoggingHandler}
23072286
* as a default logging category and SpEL expression to evaluate
23082287
* logger message at runtime against the request {@link Message}.
2309-
* <p> When this operator is used in the end of flow, it is treated
2310-
* as one-way handler without any replies to continue.
2311-
* The {@link #logAndReply()} should be used for request-reply configuration.
23122288
* @param level the {@link LoggingHandler.Level}.
23132289
* @param logExpression the {@link Expression} to evaluate logger message at runtime
23142290
* against the request {@link Message}.
@@ -2325,9 +2301,6 @@ public B log(LoggingHandler.Level level, Expression logExpression) {
23252301
* {@link LoggingHandler.Level} logging level,
23262302
* the provided logging category and SpEL expression to evaluate
23272303
* logger message at runtime against the request {@link Message}.
2328-
* <p> When this operator is used in the end of flow, it is treated
2329-
* as one-way handler without any replies to continue.
2330-
* The {@link #logAndReply()} should be used for request-reply configuration.
23312304
* @param category the logging category.
23322305
* @param logExpression the {@link Expression} to evaluate logger message at runtime
23332306
* against the request {@link Message}.
@@ -2344,9 +2317,6 @@ public B log(String category, Expression logExpression) {
23442317
* {@link LoggingHandler.Level} logging level,
23452318
* the {@code org.springframework.integration.handler.LoggingHandler}
23462319
* as a default logging category and {@link Function} for the log message.
2347-
* <p> When this operator is used in the end of flow, it is treated
2348-
* as one-way handler without any replies to continue.
2349-
* The {@link #logAndReply()} should be used for request-reply configuration.
23502320
* @param level the {@link LoggingHandler.Level}.
23512321
* @param function the function to evaluate logger message at runtime
23522322
* @param <P> the expected payload type.
@@ -2363,9 +2333,6 @@ public <P> B log(LoggingHandler.Level level, Function<Message<P>, Object> functi
23632333
* with the {@link LoggingHandler} subscriber for the provided
23642334
* {@link LoggingHandler.Level} logging level,
23652335
* the provided logging category and {@link Function} for the log message.
2366-
* <p> When this operator is used in the end of flow, it is treated
2367-
* as one-way handler without any replies to continue.
2368-
* The {@link #logAndReply()} should be used for request-reply configuration.
23692336
* @param category the logging category.
23702337
* @param function the function to evaluate logger message at runtime
23712338
* @param <P> the expected payload type.
@@ -2382,9 +2349,6 @@ public <P> B log(String category, Function<Message<P>, Object> function) {
23822349
* with the {@link LoggingHandler} subscriber for the provided
23832350
* {@link LoggingHandler.Level} logging level, logging category
23842351
* and {@link Function} for the log message.
2385-
* <p> When this operator is used in the end of flow, it is treated
2386-
* as one-way handler without any replies to continue.
2387-
* The {@link #logAndReply()} should be used for request-reply configuration.
23882352
* @param level the {@link LoggingHandler.Level}.
23892353
* @param category the logging category.
23902354
* @param function the function to evaluate logger message at runtime
@@ -2403,9 +2367,6 @@ public <P> B log(LoggingHandler.Level level, String category, Function<Message<P
24032367
* with the {@link LoggingHandler} subscriber for the provided
24042368
* {@link LoggingHandler.Level} logging level, logging category
24052369
* and SpEL expression for the log message.
2406-
* <p> When this operator is used in the end of flow, it is treated
2407-
* as one-way handler without any replies to continue.
2408-
* The {@link #logAndReply()} should be used for request-reply configuration.
24092370
* @param level the {@link LoggingHandler.Level}.
24102371
* @param category the logging category.
24112372
* @param logExpression the {@link Expression} to evaluate logger message at runtime
@@ -2441,9 +2402,11 @@ public B log(LoggingHandler.Level level, String category, Expression logExpressi
24412402
* if the {@code replyChannel} header is present.
24422403
* <p> This operator can be used only in the end of flow.
24432404
* @return an {@link IntegrationFlow} instance based on this builder.
2405+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
24442406
* @see #log()
24452407
* @see #bridge()
24462408
*/
2409+
@Deprecated
24472410
public IntegrationFlow logAndReply() {
24482411
return logAndReply(LoggingHandler.Level.INFO);
24492412
}
@@ -2459,9 +2422,11 @@ public IntegrationFlow logAndReply() {
24592422
* <p> This operator can be used only in the end of flow.
24602423
* @param level the {@link LoggingHandler.Level}.
24612424
* @return an {@link IntegrationFlow} instance based on this builder.
2425+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
24622426
* @see #log()
24632427
* @see #bridge()
24642428
*/
2429+
@Deprecated
24652430
public IntegrationFlow logAndReply(LoggingHandler.Level level) {
24662431
return logAndReply(level, (String) null);
24672432
}
@@ -2476,9 +2441,11 @@ public IntegrationFlow logAndReply(LoggingHandler.Level level) {
24762441
* <p> This operator can be used only in the end of flow.
24772442
* @param category the logging category to use.
24782443
* @return an {@link IntegrationFlow} instance based on this builder.
2444+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
24792445
* @see #log()
24802446
* @see #bridge()
24812447
*/
2448+
@Deprecated
24822449
public IntegrationFlow logAndReply(String category) {
24832450
return logAndReply(LoggingHandler.Level.INFO, category);
24842451
}
@@ -2494,9 +2461,11 @@ public IntegrationFlow logAndReply(String category) {
24942461
* @param level the {@link LoggingHandler.Level}.
24952462
* @param category the logging category to use.
24962463
* @return an {@link IntegrationFlow} instance based on this builder.
2464+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
24972465
* @see #log()
24982466
* @see #bridge()
24992467
*/
2468+
@Deprecated
25002469
public IntegrationFlow logAndReply(LoggingHandler.Level level, String category) {
25012470
return logAndReply(level, category, (Expression) null);
25022471
}
@@ -2514,9 +2483,11 @@ public IntegrationFlow logAndReply(LoggingHandler.Level level, String category)
25142483
* @param logExpression the SpEL expression to evaluate logger message at runtime
25152484
* against the request {@link Message}.
25162485
* @return an {@link IntegrationFlow} instance based on this builder.
2486+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
25172487
* @see #log()
25182488
* @see #bridge()
25192489
*/
2490+
@Deprecated
25202491
public IntegrationFlow logAndReply(LoggingHandler.Level level, String category, String logExpression) {
25212492
Assert.hasText(logExpression, "'logExpression' must not be empty");
25222493
return logAndReply(level, category, PARSER.parseExpression(logExpression));
@@ -2534,9 +2505,11 @@ public IntegrationFlow logAndReply(LoggingHandler.Level level, String category,
25342505
* @param <P> the expected payload type.
25352506
* against the request {@link Message}.
25362507
* @return an {@link IntegrationFlow} instance based on this builder.
2508+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
25372509
* @see #log()
25382510
* @see #bridge()
25392511
*/
2512+
@Deprecated
25402513
public <P> IntegrationFlow logAndReply(Function<Message<P>, Object> function) {
25412514
Assert.notNull(function, FUNCTION_MUST_NOT_BE_NULL);
25422515
return logAndReply(new FunctionExpression<>(function));
@@ -2554,9 +2527,11 @@ public <P> IntegrationFlow logAndReply(Function<Message<P>, Object> function) {
25542527
* @param logExpression the {@link Expression} to evaluate logger message at runtime
25552528
* against the request {@link Message}.
25562529
* @return an {@link IntegrationFlow} instance based on this builder.
2530+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
25572531
* @see #log()
25582532
* @see #bridge()
25592533
*/
2534+
@Deprecated
25602535
public IntegrationFlow logAndReply(Expression logExpression) {
25612536
return logAndReply(LoggingHandler.Level.INFO, logExpression);
25622537
}
@@ -2575,9 +2550,11 @@ public IntegrationFlow logAndReply(Expression logExpression) {
25752550
* @param logExpression the {@link Expression} to evaluate logger message at runtime
25762551
* against the request {@link Message}.
25772552
* @return an {@link IntegrationFlow} instance based on this builder.
2553+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
25782554
* @see #log()
25792555
* @see #bridge()
25802556
*/
2557+
@Deprecated
25812558
public IntegrationFlow logAndReply(LoggingHandler.Level level, Expression logExpression) {
25822559
return logAndReply(level, null, logExpression);
25832560
}
@@ -2595,9 +2572,11 @@ public IntegrationFlow logAndReply(LoggingHandler.Level level, Expression logExp
25952572
* @param logExpression the {@link Expression} to evaluate logger message at runtime
25962573
* against the request {@link Message}.
25972574
* @return an {@link IntegrationFlow} instance based on this builder.
2575+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
25982576
* @see #log()
25992577
* @see #bridge()
26002578
*/
2579+
@Deprecated
26012580
public IntegrationFlow logAndReply(String category, Expression logExpression) {
26022581
return logAndReply(LoggingHandler.Level.INFO, category, logExpression);
26032582
}
@@ -2616,9 +2595,11 @@ public IntegrationFlow logAndReply(String category, Expression logExpression) {
26162595
* @param <P> the expected payload type.
26172596
* against the request {@link Message}.
26182597
* @return an {@link IntegrationFlow} instance based on this builder.
2598+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
26192599
* @see #log()
26202600
* @see #bridge()
26212601
*/
2602+
@Deprecated
26222603
public <P> IntegrationFlow logAndReply(LoggingHandler.Level level, Function<Message<P>, Object> function) {
26232604
return logAndReply(level, null, function);
26242605
}
@@ -2636,9 +2617,11 @@ public <P> IntegrationFlow logAndReply(LoggingHandler.Level level, Function<Mess
26362617
* @param <P> the expected payload type.
26372618
* against the request {@link Message}.
26382619
* @return an {@link IntegrationFlow} instance based on this builder.
2620+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
26392621
* @see #log()
26402622
* @see #bridge()
26412623
*/
2624+
@Deprecated
26422625
public <P> IntegrationFlow logAndReply(String category, Function<Message<P>, Object> function) {
26432626
return logAndReply(LoggingHandler.Level.INFO, category, function);
26442627
}
@@ -2657,9 +2640,11 @@ public <P> IntegrationFlow logAndReply(String category, Function<Message<P>, Obj
26572640
* @param <P> the expected payload type.
26582641
* against the request {@link Message}.
26592642
* @return an {@link IntegrationFlow} instance based on this builder.
2643+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
26602644
* @see #log()
26612645
* @see #bridge()
26622646
*/
2647+
@Deprecated
26632648
public <P> IntegrationFlow logAndReply(LoggingHandler.Level level, String category,
26642649
Function<Message<P>, Object> function) {
26652650

@@ -2680,9 +2665,11 @@ public <P> IntegrationFlow logAndReply(LoggingHandler.Level level, String catego
26802665
* @param logExpression the {@link Expression} to evaluate logger message at runtime
26812666
* against the request {@link Message}.
26822667
* @return an {@link IntegrationFlow} instance based on this builder.
2668+
* @deprecated since 6.0 in favor of {@link #log} in the end of flow.
26832669
* @see #log()
26842670
* @see #bridge()
26852671
*/
2672+
@Deprecated
26862673
public IntegrationFlow logAndReply(LoggingHandler.Level level, String category, Expression logExpression) {
26872674
return log(level, category, logExpression)
26882675
.bridge()
@@ -3103,7 +3090,7 @@ else if (currentChannel != null) {
31033090
.stream()
31043091
.reduce((first, second) -> second);
31053092
if (lastComponent.get() instanceof WireTapSpec) {
3106-
channel(IntegrationContextUtils.NULL_CHANNEL_BEAN_NAME);
3093+
bridge();
31073094
}
31083095
}
31093096

spring-integration-core/src/test/java/org/springframework/integration/dsl/extensions/IntegrationFlowExtensionTests.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2020 the original author or authors.
2+
* Copyright 2020-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -82,7 +82,8 @@ public IntegrationFlow customFlowDefinition() {
8282
.channel("innerChannel")
8383
.customAggregate(customAggregatorSpec ->
8484
customAggregatorSpec.expireGroupsUponCompletion(true))
85-
.logAndReply();
85+
.log()
86+
.get();
8687
}
8788

8889
}

spring-integration-core/src/test/java/org/springframework/integration/dsl/flowservices/FlowServiceTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016-2020 the original author or authors.
2+
* Copyright 2016-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -127,7 +127,7 @@ public static class ContextConfiguration {
127127
@Bean
128128
public IntegrationFlow testGateway() {
129129
return f -> f.gateway("processChannel", g -> g.replyChannel("replyChannel"))
130-
.logAndReply();
130+
.log();
131131
}
132132

133133
@Bean
@@ -152,7 +152,8 @@ public void configure(IntegrationFlowDefinition<?> f) {
152152
.log(LoggingHandler.Level.ERROR, m -> {
153153
resultOverLoggingHandler.set(m.getPayload());
154154
return m;
155-
});
155+
})
156+
.nullChannel();
156157
}
157158

158159
@Override

spring-integration-core/src/test/java/org/springframework/integration/dsl/transformers/TransformerTests.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017-2021 the original author or authors.
2+
* Copyright 2017-2022 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -297,7 +297,8 @@ public IntegrationFlow enricherFlow() {
297297
.propertyFunction("date", m -> new Date())
298298
.headerExpression("foo", "payload['name']")
299299
)
300-
.logAndReply();
300+
.log()
301+
.get();
301302
}
302303

303304
@Bean
@@ -463,7 +464,7 @@ public IntegrationFlow transformFlowWithError() {
463464
throw new RuntimeException("intentional");
464465
},
465466
e -> e.advice(expressionAdvice()))
466-
.logAndReply();
467+
.log();
467468
}
468469

469470
}

src/reference/asciidoc/dsl.adoc

+3-3
Original file line numberDiff line numberDiff line change
@@ -656,9 +656,9 @@ The following example shows how to use `LoggingHandler`:
656656

657657
In the preceding example, an `id` header is logged at the `ERROR` level onto `test.category` only for messages that passed the filter and before routing.
658658

659-
When this operator is used at the end of a flow, it is a one-way handler and the flow ends.
660-
To make it as a reply-producing flow, you can either use a simple `bridge()` after the `log()` or, starting with version 5.1, you can use a `logAndReply()` operator instead.
661-
`logAndReply` can only be used at the end of a flow.
659+
Starting with version 6.0, the behavior of this operator in the end of flow is aligned with its usage in the middle.
660+
In other words the behavior of the flow remains the same even if the `log()` operator is removed.
661+
So, if a reply is not expected to be produced in the end of the flow, the `nullChannel()` is recommended to be used after the last `log()`.
662662

663663
[[java-dsl-intercept]]
664664
=== Operator intercept()

0 commit comments

Comments
 (0)