54
54
import org .springframework .integration .handler .advice .IdempotentReceiverInterceptor ;
55
55
import org .springframework .integration .selector .MetadataStoreSelector ;
56
56
import org .springframework .integration .support .MessageBuilder ;
57
- import org .springframework .integration .transformer .DecodingTransformer ;
58
57
import org .springframework .messaging .Message ;
59
58
import org .springframework .messaging .MessageChannel ;
60
59
import org .springframework .messaging .MessageHeaders ;
@@ -87,6 +86,11 @@ public class TransformerTests {
87
86
@ Qualifier ("enricherInput3" )
88
87
private FixedSubscriberChannel enricherInput3 ;
89
88
89
+ @ Autowired
90
+ @ Qualifier ("enricherErrorChannel" )
91
+ private PollableChannel enricherErrorChannel ;
92
+
93
+
90
94
91
95
@ Test
92
96
public void testContentEnricher () {
@@ -104,6 +108,11 @@ public void testContentEnricher() {
104
108
assertEquals ("Bar Bar" , result .getName ());
105
109
assertNotNull (result .getDate ());
106
110
assertThat (new Date (), Matchers .greaterThanOrEqualTo (result .getDate ()));
111
+
112
+ this .enricherInput .send (new GenericMessage <>(new TestPojo ("junk" )));
113
+
114
+ Message <?> errorMessage = this .enricherErrorChannel .receive (10_000 );
115
+ assertNotNull (errorMessage );
107
116
}
108
117
109
118
@ Test
@@ -237,10 +246,16 @@ public void transformWithHeader() {
237
246
@ EnableIntegration
238
247
public static class ContextConfiguration {
239
248
249
+ @ Bean
250
+ public PollableChannel enricherErrorChannel () {
251
+ return new QueueChannel ();
252
+ }
253
+
240
254
@ Bean
241
255
public IntegrationFlow enricherFlow () {
242
256
return IntegrationFlows .from ("enricherInput" , true )
243
257
.enrich (e -> e .requestChannel ("enrichChannel" )
258
+ .errorChannel (enricherErrorChannel ())
244
259
.requestPayloadExpression ("payload" )
245
260
.shouldClonePayload (false )
246
261
.propertyExpression ("name" , "payload['name']" )
@@ -275,7 +290,12 @@ public IntegrationFlow enricherFlow3() {
275
290
@ Bean
276
291
public IntegrationFlow enrichFlow () {
277
292
return IntegrationFlows .from ("enrichChannel" )
278
- .<TestPojo , Map <?, ?>>transform (p -> Collections .singletonMap ("name" , p .getName () + " Bar" ))
293
+ .<TestPojo , Map <?, ?>>transform (p -> {
294
+ if ("junk" .equals (p .getName ())) {
295
+ throw new RuntimeException ("intentional" );
296
+ }
297
+ return Collections .singletonMap ("name" , p .getName () + " Bar" );
298
+ })
279
299
.get ();
280
300
}
281
301
@@ -298,10 +318,8 @@ public IntegrationFlow encodingFlow() {
298
318
299
319
@ Bean
300
320
public IntegrationFlow decodingFlow () {
301
- // TODO: Stored in an unnecessary variable to work around an eclipse type inference issue.
302
- DecodingTransformer <Integer > transformer = Transformers .decoding (new MyCodec (), m -> Integer .class );
303
321
return f -> f
304
- .transform (transformer )
322
+ .transform (Transformers . decoding ( new MyCodec (), m -> Integer . class ) )
305
323
.channel ("codecReplyChannel" );
306
324
}
307
325
0 commit comments