Skip to content

Commit ffaa4ee

Browse files
garyrussellartembilan
authored andcommitted
Log error for class cast exception on lambda
**cherry-pick to 5.0.x** * Fix test * Polish log message. * Polishing - docs and javadocs. # Conflicts: # spring-integration-core/src/main/java/org/springframework/integration/dsl/IntegrationFlowDefinition.java
1 parent 47a4b28 commit ffaa4ee

File tree

4 files changed

+140
-46
lines changed

4 files changed

+140
-46
lines changed

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

Lines changed: 86 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ public B controlBus() {
460460
* @see GenericEndpointSpec
461461
*/
462462
public B controlBus(Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) {
463-
return this.handle(new ServiceActivatingHandler(new ExpressionCommandMessageProcessor(
463+
return handle(new ServiceActivatingHandler(new ExpressionCommandMessageProcessor(
464464
new ControlBusMethodFilter())), endpointConfigurer);
465465
}
466466

@@ -537,7 +537,9 @@ public B transform(Object service, String methodName,
537537
}
538538

539539
/**
540-
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}.
540+
* Populate the {@link MessageTransformingHandler} instance for the provided
541+
* {@link GenericTransformer}. Use {@link #transform(Class, GenericTransformer)} if
542+
* you need to access the entire message.
541543
* @param genericTransformer the {@link GenericTransformer} to populate.
542544
* @param <S> the source type - 'transform from'.
543545
* @param <T> the target type - 'transform to'.
@@ -589,11 +591,16 @@ public B transform(MessageProcessorSpec<?> messageProcessorSpec,
589591
}
590592

591593
/**
592-
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}
593-
* for the specific {@code payloadType} to convert at runtime.
594-
* @param payloadType the {@link Class} for expected payload type.
594+
* Populate the {@link MessageTransformingHandler} instance for the provided
595+
* {@link GenericTransformer} for the specific {@code payloadType} to convert at
596+
* runtime.
597+
* Use {@link #transform(Class, GenericTransformer)} if you need access to the
598+
* entire message.
599+
* @param payloadType the {@link Class} for expected payload type. It can also be
600+
* {@code Message.class} if you wish to access the entire message in the transformer.
601+
* Conversion to this type will be attempted, if necessary.
595602
* @param genericTransformer the {@link GenericTransformer} to populate.
596-
* @param <P> the payload type - 'transform from'.
603+
* @param <P> the payload type - 'transform from' or {@code Message.class}.
597604
* @param <T> the target type - 'transform to'.
598605
* @return the current {@link IntegrationFlowDefinition}.
599606
* @see MethodInvokingTransformer
@@ -604,10 +611,14 @@ public <P, T> B transform(Class<P> payloadType, GenericTransformer<P, T> generic
604611
}
605612

606613
/**
607-
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}.
608-
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
614+
* Populate the {@link MessageTransformingHandler} instance for the provided
615+
* {@link GenericTransformer}. In addition accept options for the integration endpoint
616+
* using {@link GenericEndpointSpec}. Use
617+
* {@link #transform(Class, GenericTransformer, Consumer)} if you need to access the
618+
* entire message.
609619
* @param genericTransformer the {@link GenericTransformer} to populate.
610-
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
620+
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint
621+
* options.
611622
* @param <S> the source type - 'transform from'.
612623
* @param <T> the target type - 'transform to'.
613624
* @return the current {@link IntegrationFlowDefinition}.
@@ -617,17 +628,20 @@ public <P, T> B transform(Class<P> payloadType, GenericTransformer<P, T> generic
617628
*/
618629
public <S, T> B transform(GenericTransformer<S, T> genericTransformer,
619630
Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
620-
return this.transform(null, genericTransformer, endpointConfigurer);
631+
632+
return transform(null, genericTransformer, endpointConfigurer);
621633
}
622634

623635
/**
624636
* Populate the {@link MessageTransformingHandler} instance for the provided {@link GenericTransformer}
625637
* for the specific {@code payloadType} to convert at runtime.
626638
* In addition accept options for the integration endpoint using {@link GenericEndpointSpec}.
627-
* @param payloadType the {@link Class} for expected payload type.
639+
* @param payloadType the {@link Class} for expected payload type. It can also be
640+
* {@code Message.class} if you wish to access the entire message in the transformer.
641+
* Conversion to this type will be attempted, if necessary.
628642
* @param genericTransformer the {@link GenericTransformer} to populate.
629643
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
630-
* @param <P> the payload type - 'transform from'.
644+
* @param <P> the payload type - 'transform from', or {@code Message.class}.
631645
* @param <T> the target type - 'transform to'.
632646
* @return the current {@link IntegrationFlowDefinition}.
633647
* @see MethodInvokingTransformer
@@ -724,6 +738,8 @@ public B filter(Object service, String methodName, Consumer<FilterEndpointSpec>
724738
* .filter("World"::equals)
725739
* }
726740
* </pre>
741+
* Use {@link #filter(Class, GenericSelector)} if you need to access the entire
742+
* message.
727743
* @param genericSelector the {@link GenericSelector} to use.
728744
* @param <P> the source payload type.
729745
* @return the current {@link IntegrationFlowDefinition}.
@@ -779,14 +795,16 @@ public B filter(MessageProcessorSpec<?> messageProcessorSpec, Consumer<FilterEnd
779795
* .filter(Date.class, p -> p.after(new Date()))
780796
* }
781797
* </pre>
782-
* @param payloadType the {@link Class} for desired {@code payload} type.
798+
* @param payloadType the {@link Class} for expected payload type. It can also be
799+
* {@code Message.class} if you wish to access the entire message in the selector.
800+
* Conversion to this type will be attempted, if necessary.
783801
* @param genericSelector the {@link GenericSelector} to use.
784-
* @param <P> the source payload type.
802+
* @param <P> the source payload type or {@code Message.class}.
785803
* @return the current {@link IntegrationFlowDefinition}.
786804
* @see LambdaMessageProcessor
787805
*/
788806
public <P> B filter(Class<P> payloadType, GenericSelector<P> genericSelector) {
789-
return this.filter(payloadType, genericSelector, null);
807+
return filter(payloadType, genericSelector, null);
790808
}
791809

792810
/**
@@ -799,6 +817,8 @@ public <P> B filter(Class<P> payloadType, GenericSelector<P> genericSelector) {
799817
* .filter("World"::equals, e -> e.autoStartup(false))
800818
* }
801819
* </pre>
820+
* Use {@link #filter(Class, GenericSelector, Consumer)} if you need to access the entire
821+
* message.
802822
* @param genericSelector the {@link GenericSelector} to use.
803823
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
804824
* @param <P> the source payload type.
@@ -819,10 +839,12 @@ public <P> B filter(GenericSelector<P> genericSelector, Consumer<FilterEndpointS
819839
* .filter(Date.class, p -> p.after(new Date()), e -> e.autoStartup(false))
820840
* }
821841
* </pre>
822-
* @param payloadType the {@link Class} for desired {@code payload} type.
842+
* @param payloadType the {@link Class} for expected payload type. It can also be
843+
* {@code Message.class} if you wish to access the entire message in the selector.
844+
* Conversion to this type will be attempted, if necessary.
823845
* @param genericSelector the {@link GenericSelector} to use.
824846
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
825-
* @param <P> the source payload type.
847+
* @param <P> the source payload type or {@code Message.class}.
826848
* @return the current {@link IntegrationFlowDefinition}.
827849
* @see LambdaMessageProcessor
828850
* @see FilterEndpointSpec
@@ -880,7 +902,7 @@ public B handle(MessageHandler messageHandler) {
880902
* @return the current {@link IntegrationFlowDefinition}.
881903
*/
882904
public B handle(String beanName, String methodName) {
883-
return this.handle(beanName, methodName, null);
905+
return handle(beanName, methodName, null);
884906
}
885907

886908
/**
@@ -955,6 +977,8 @@ public B handle(Object service, String methodName,
955977
* .<Integer>handle((p, h) -> p / 2)
956978
* }
957979
* </pre>
980+
* Use {@link #handle(Class, GenericHandler)} if you need to access the entire
981+
* message.
958982
* @param handler the handler to invoke.
959983
* @param <P> the payload type to expect.
960984
* @return the current {@link IntegrationFlowDefinition}.
@@ -975,6 +999,8 @@ public <P> B handle(GenericHandler<P> handler) {
975999
* .<Integer>handle((p, h) -> p / 2, e -> e.autoStartup(false))
9761000
* }
9771001
* </pre>
1002+
* Use {@link #handle(Class, GenericHandler, Consumer)} if you need to access the entire
1003+
* message.
9781004
* @param handler the handler to invoke.
9791005
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
9801006
* @param <P> the payload type to expect.
@@ -984,7 +1010,7 @@ public <P> B handle(GenericHandler<P> handler) {
9841010
*/
9851011
public <P> B handle(GenericHandler<P> handler,
9861012
Consumer<GenericEndpointSpec<ServiceActivatingHandler>> endpointConfigurer) {
987-
return this.handle(null, handler, endpointConfigurer);
1013+
return handle(null, handler, endpointConfigurer);
9881014
}
9891015

9901016
/**
@@ -997,15 +1023,16 @@ public <P> B handle(GenericHandler<P> handler,
9971023
* .handle(Integer.class, (p, h) -> p / 2)
9981024
* }
9991025
* </pre>
1000-
* @param payloadType the expected payload type.
1001-
* The accepted payload can be converted to this one at runtime
1026+
* @param payloadType the {@link Class} for expected payload type. It can also be
1027+
* {@code Message.class} if you wish to access the entire message in the handler.
1028+
* Conversion to this type will be attempted, if necessary.
10021029
* @param handler the handler to invoke.
1003-
* @param <P> the payload type to expect.
1030+
* @param <P> the payload type to expect, or {@code Message.class}.
10041031
* @return the current {@link IntegrationFlowDefinition}.
10051032
* @see LambdaMessageProcessor
10061033
*/
10071034
public <P> B handle(Class<P> payloadType, GenericHandler<P> handler) {
1008-
return this.handle(payloadType, handler, null);
1035+
return handle(payloadType, handler, null);
10091036
}
10101037

10111038
/**
@@ -1019,11 +1046,12 @@ public <P> B handle(Class<P> payloadType, GenericHandler<P> handler) {
10191046
* .handle(Integer.class, (p, h) -> p / 2, e -> e.autoStartup(false))
10201047
* }
10211048
* </pre>
1022-
* @param payloadType the expected payload type.
1023-
* The accepted payload can be converted to this one at runtime
1049+
* @param payloadType the {@link Class} for expected payload type. It can also be
1050+
* {@code Message.class} if you wish to access the entire message in the handler.
1051+
* Conversion to this type will be attempted, if necessary.
10241052
* @param handler the handler to invoke.
10251053
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
1026-
* @param <P> the payload type to expect.
1054+
* @param <P> the payload type to expect or {@code Message.class}.
10271055
* @return the current {@link IntegrationFlowDefinition}.
10281056
* @see LambdaMessageProcessor
10291057
*/
@@ -1036,7 +1064,7 @@ public <P> B handle(Class<P> payloadType, GenericHandler<P> handler,
10361064
else {
10371065
serviceActivatingHandler = new ServiceActivatingHandler(handler, ClassUtils.HANDLER_HANDLE_METHOD);
10381066
}
1039-
return this.handle(serviceActivatingHandler, endpointConfigurer);
1067+
return handle(serviceActivatingHandler, endpointConfigurer);
10401068
}
10411069

10421070
/**
@@ -1241,9 +1269,9 @@ public B enrichHeaders(MapBuilder<?, String, Object> headers,
12411269

12421270
/**
12431271
* Accept a {@link Map} of values to be used for the
1244-
* {@link org.springframework.messaging.Message} header enrichment.
1272+
* {@link Message} header enrichment.
12451273
* {@code values} can apply an {@link org.springframework.expression.Expression}
1246-
* to be evaluated against a request {@link org.springframework.messaging.Message}.
1274+
* to be evaluated against a request {@link Message}.
12471275
* @param headers the Map of headers to enrich.
12481276
* @return the current {@link IntegrationFlowDefinition}.
12491277
*/
@@ -1253,9 +1281,9 @@ public B enrichHeaders(Map<String, Object> headers) {
12531281

12541282
/**
12551283
* Accept a {@link Map} of values to be used for the
1256-
* {@link org.springframework.messaging.Message} header enrichment.
1284+
* {@link Message} header enrichment.
12571285
* {@code values} can apply an {@link org.springframework.expression.Expression}
1258-
* to be evaluated against a request {@link org.springframework.messaging.Message}.
1286+
* to be evaluated against a request {@link Message}.
12591287
* @param headers the Map of headers to enrich.
12601288
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
12611289
* @return the current {@link IntegrationFlowDefinition}.
@@ -1296,7 +1324,7 @@ public B enrichHeaders(Consumer<HeaderEnricherSpec> headerEnricherConfigurer) {
12961324
* @return the current {@link IntegrationFlowDefinition}.
12971325
*/
12981326
public B split() {
1299-
return this.split((Consumer<SplitterEndpointSpec<DefaultMessageSplitter>>) null);
1327+
return split((Consumer<SplitterEndpointSpec<DefaultMessageSplitter>>) null);
13001328
}
13011329

13021330
/**
@@ -1314,7 +1342,7 @@ public B split() {
13141342
* @see SplitterEndpointSpec
13151343
*/
13161344
public B split(Consumer<SplitterEndpointSpec<DefaultMessageSplitter>> endpointConfigurer) {
1317-
return this.split(new DefaultMessageSplitter(), endpointConfigurer);
1345+
return split(new DefaultMessageSplitter(), endpointConfigurer);
13181346
}
13191347

13201348
/**
@@ -1398,7 +1426,7 @@ public B split(Object service, String methodName,
13981426
* @return the current {@link IntegrationFlowDefinition}.
13991427
*/
14001428
public B split(String beanName, String methodName) {
1401-
return this.split(beanName, methodName, null);
1429+
return split(beanName, methodName, null);
14021430
}
14031431

14041432
/**
@@ -1474,9 +1502,11 @@ public B split(MessageProcessorSpec<?> messageProcessorSpec,
14741502
* new Foo(rs.getInt(1), rs.getString(2)))))
14751503
* }
14761504
* </pre>
1477-
* @param payloadType the expected payload type. Used at runtime to convert received payload type to.
1505+
* @param payloadType the {@link Class} for expected payload type. It can also be
1506+
* {@code Message.class} if you wish to access the entire message in the splitter.
1507+
* Conversion to this type will be attempted, if necessary.
14781508
* @param splitter the splitter {@link Function}.
1479-
* @param <P> the payload type.
1509+
* @param <P> the payload type or {@code Message.class}.
14801510
* @return the current {@link IntegrationFlowDefinition}.
14811511
* @see LambdaMessageProcessor
14821512
*/
@@ -1528,20 +1558,23 @@ public <P> B split(Function<P, ?> splitter,
15281558
* , e -> e.applySequence(false))
15291559
* }
15301560
* </pre>
1531-
* @param payloadType the expected payload type. Used at runtime to convert received payload type to.
1561+
* @param payloadType the {@link Class} for expected payload type. It can also be
1562+
* {@code Message.class} if you wish to access the entire message in the splitter.
1563+
* Conversion to this type will be attempted, if necessary.
15321564
* @param splitter the splitter {@link Function}.
15331565
* @param endpointConfigurer the {@link Consumer} to provide integration endpoint options.
1534-
* @param <P> the payload type.
1566+
* @param <P> the payload type or {@code Message.class}.
15351567
* @return the current {@link IntegrationFlowDefinition}.
15361568
* @see LambdaMessageProcessor
15371569
* @see SplitterEndpointSpec
15381570
*/
15391571
public <P> B split(Class<P> payloadType, Function<P, ?> splitter,
15401572
Consumer<SplitterEndpointSpec<MethodInvokingSplitter>> endpointConfigurer) {
1573+
15411574
MethodInvokingSplitter split = isLambda(splitter)
15421575
? new MethodInvokingSplitter(new LambdaMessageProcessor(splitter, payloadType))
15431576
: new MethodInvokingSplitter(splitter, ClassUtils.FUNCTION_APPLY_METHOD);
1544-
return this.split(split, endpointConfigurer);
1577+
return split(split, endpointConfigurer);
15451578
}
15461579

15471580
/**
@@ -1631,7 +1664,7 @@ public B headerFilter(String headersToRemove, boolean patternMatch) {
16311664
*/
16321665
public B headerFilter(HeaderFilter headerFilter,
16331666
Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
1634-
return this.transform(headerFilter, endpointConfigurer);
1667+
return transform(headerFilter, endpointConfigurer);
16351668
}
16361669

16371670
/**
@@ -1655,7 +1688,7 @@ public B claimCheckIn(MessageStore messageStore) {
16551688
*/
16561689
public B claimCheckIn(MessageStore messageStore,
16571690
Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
1658-
return this.transform(new ClaimCheckInTransformer(messageStore), endpointConfigurer);
1691+
return transform(new ClaimCheckInTransformer(messageStore), endpointConfigurer);
16591692
}
16601693

16611694
/**
@@ -1696,7 +1729,7 @@ public B claimCheckOut(MessageStore messageStore, boolean removeMessage,
16961729
Consumer<GenericEndpointSpec<MessageTransformingHandler>> endpointConfigurer) {
16971730
ClaimCheckOutTransformer claimCheckOutTransformer = new ClaimCheckOutTransformer(messageStore);
16981731
claimCheckOutTransformer.setRemoveMessage(removeMessage);
1699-
return this.transform(claimCheckOutTransformer, endpointConfigurer);
1732+
return transform(claimCheckOutTransformer, endpointConfigurer);
17001733
}
17011734

17021735
/**
@@ -1861,6 +1894,7 @@ public <T> B route(String expression, Consumer<RouterSpec<T, ExpressionEvaluatin
18611894
* .route(p -> p.equals("foo") || p.equals("bar") ? new String[] {"foo", "bar"} : null)
18621895
* }
18631896
* </pre>
1897+
* Use {@link #route(Class, Function)} if you need to access the entire message.
18641898
* @param router the {@link Function} to use.
18651899
* @param <S> the source payload type.
18661900
* @param <T> the target result type.
@@ -1879,9 +1913,11 @@ public <S, T> B route(Function<S, T> router) {
18791913
* .route(Integer.class, p -> p % 2 == 0)
18801914
* }
18811915
* </pre>
1882-
* @param payloadType the expected payload type.
1916+
* @param payloadType the {@link Class} for expected payload type. It can also be
1917+
* {@code Message.class} if you wish to access the entire message in the splitter.
1918+
* Conversion to this type will be attempted, if necessary.
18831919
* @param router the {@link Function} to use.
1884-
* @param <S> the source payload type.
1920+
* @param <S> the source payload type or {@code Message.class}.
18851921
* @param <T> the target result type.
18861922
* @return the current {@link IntegrationFlowDefinition}.
18871923
* @see LambdaMessageProcessor
@@ -1904,6 +1940,7 @@ public <S, T> B route(Class<S> payloadType, Function<S, T> router) {
19041940
* .applySequence(false))
19051941
* }
19061942
* </pre>
1943+
* Use {@link #route(Class, Function, Consumer)} if you need to access the entire message.
19071944
* @param router the {@link Function} to use.
19081945
* @param routerConfigurer the {@link Consumer} to provide {@link MethodInvokingRouter} options.
19091946
* @param <S> the source payload type.
@@ -1928,16 +1965,19 @@ public <S, T> B route(Function<S, T> router, Consumer<RouterSpec<T, MethodInvoki
19281965
* .applySequence(false))
19291966
* }
19301967
* </pre>
1931-
* @param payloadType the expected payload type.
1968+
* @param payloadType the {@link Class} for expected payload type. It can also be
1969+
* {@code Message.class} if you wish to access the entire message in the splitter.
1970+
* Conversion to this type will be attempted, if necessary.
19321971
* @param router the {@link Function} to use.
19331972
* @param routerConfigurer the {@link Consumer} to provide {@link MethodInvokingRouter} options.
1934-
* @param <P> the source payload type.
1973+
* @param <P> the source payload type or {@code Message.class}.
19351974
* @param <T> the target result type.
19361975
* @return the current {@link IntegrationFlowDefinition}.
19371976
* @see LambdaMessageProcessor
19381977
*/
19391978
public <P, T> B route(Class<P> payloadType, Function<P, T> router,
19401979
Consumer<RouterSpec<T, MethodInvokingRouter>> routerConfigurer) {
1980+
19411981
MethodInvokingRouter methodInvokingRouter = isLambda(router)
19421982
? new MethodInvokingRouter(new LambdaMessageProcessor(router, payloadType))
19431983
: new MethodInvokingRouter(router, ClassUtils.FUNCTION_APPLY_METHOD);

0 commit comments

Comments
 (0)