5454import org .springframework .integration .handler .advice .IdempotentReceiverInterceptor ;
5555import org .springframework .integration .selector .MetadataStoreSelector ;
5656import org .springframework .integration .support .MessageBuilder ;
57- import org .springframework .integration .transformer .DecodingTransformer ;
5857import org .springframework .messaging .Message ;
5958import org .springframework .messaging .MessageChannel ;
6059import org .springframework .messaging .MessageHeaders ;
@@ -87,6 +86,11 @@ public class TransformerTests {
8786 @ Qualifier ("enricherInput3" )
8887 private FixedSubscriberChannel enricherInput3 ;
8988
89+ @ Autowired
90+ @ Qualifier ("enricherErrorChannel" )
91+ private PollableChannel enricherErrorChannel ;
92+
93+
9094
9195 @ Test
9296 public void testContentEnricher () {
@@ -104,6 +108,11 @@ public void testContentEnricher() {
104108 assertEquals ("Bar Bar" , result .getName ());
105109 assertNotNull (result .getDate ());
106110 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 );
107116 }
108117
109118 @ Test
@@ -237,10 +246,16 @@ public void transformWithHeader() {
237246 @ EnableIntegration
238247 public static class ContextConfiguration {
239248
249+ @ Bean
250+ public PollableChannel enricherErrorChannel () {
251+ return new QueueChannel ();
252+ }
253+
240254 @ Bean
241255 public IntegrationFlow enricherFlow () {
242256 return IntegrationFlows .from ("enricherInput" , true )
243257 .enrich (e -> e .requestChannel ("enrichChannel" )
258+ .errorChannel (enricherErrorChannel ())
244259 .requestPayloadExpression ("payload" )
245260 .shouldClonePayload (false )
246261 .propertyExpression ("name" , "payload['name']" )
@@ -275,7 +290,12 @@ public IntegrationFlow enricherFlow3() {
275290 @ Bean
276291 public IntegrationFlow enrichFlow () {
277292 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+ })
279299 .get ();
280300 }
281301
@@ -298,10 +318,8 @@ public IntegrationFlow encodingFlow() {
298318
299319 @ Bean
300320 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 );
303321 return f -> f
304- .transform (transformer )
322+ .transform (Transformers . decoding ( new MyCodec (), m -> Integer . class ) )
305323 .channel ("codecReplyChannel" );
306324 }
307325
0 commit comments