23
23
import java .util .function .Function ;
24
24
25
25
import org .springframework .expression .Expression ;
26
+ import org .springframework .integration .IntegrationMessageHeaderAccessor ;
26
27
import org .springframework .integration .config .ConsumerEndpointFactoryBean ;
27
28
import org .springframework .integration .context .IntegrationContextUtils ;
28
29
import org .springframework .integration .expression .FunctionExpression ;
38
39
import org .springframework .integration .transformer .support .HeaderValueMessageProcessor ;
39
40
import org .springframework .integration .transformer .support .StaticHeaderValueMessageProcessor ;
40
41
import org .springframework .messaging .Message ;
42
+ import org .springframework .messaging .MessageHeaders ;
41
43
import org .springframework .util .Assert ;
42
44
import org .springframework .util .StringUtils ;
43
45
@@ -290,6 +292,243 @@ public HeaderEnricherSpec headerExpressions(Map<String, String> headers, Boolean
290
292
return this ;
291
293
}
292
294
295
+ /**
296
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header.
297
+ * If the header exists, it will <b>not</b> be overwritten unless {@link #defaultOverwrite(boolean)} is true.
298
+ * @param correlationId the header value for {@link IntegrationMessageHeaderAccessor#CORRELATION_ID}.
299
+ * @return the header enricher spec.
300
+ * @since 5.2
301
+ */
302
+ public HeaderEnricherSpec correlationId (Object correlationId ) {
303
+ return correlationId (correlationId , null );
304
+ }
305
+
306
+ /**
307
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header.
308
+ * @param correlationId the header value for {@link IntegrationMessageHeaderAccessor#CORRELATION_ID}.
309
+ * @param overwrite true to overwrite an existing header.
310
+ * @return the header enricher spec.
311
+ * @since 5.2
312
+ */
313
+ public HeaderEnricherSpec correlationId (Object correlationId , Boolean overwrite ) {
314
+ return header (IntegrationMessageHeaderAccessor .CORRELATION_ID , correlationId , overwrite );
315
+ }
316
+
317
+ /**
318
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header
319
+ * where the value is a SpEL {@link Expression} evaluation result.
320
+ * If the header exists, it will <b>not</b> be overwritten
321
+ * unless {@link #defaultOverwrite(boolean)} is true.
322
+ * @param correlationIdExpression the expression for
323
+ * {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header.
324
+ * @return the header enricher spec.
325
+ * @since 5.2
326
+ */
327
+ public HeaderEnricherSpec correlationIdExpression (String correlationIdExpression ) {
328
+ return correlationIdExpression (correlationIdExpression , null );
329
+ }
330
+
331
+ /**
332
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header
333
+ * where the value is a SpEL {@link Expression} evaluation result.
334
+ * @param correlationIdExpression the expression for
335
+ * {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header.
336
+ * @param overwrite true to overwrite an existing header.
337
+ * @return the header enricher spec.
338
+ * @since 5.2
339
+ */
340
+ public HeaderEnricherSpec correlationIdExpression (String correlationIdExpression , Boolean overwrite ) {
341
+ return headerExpression (IntegrationMessageHeaderAccessor .CORRELATION_ID , correlationIdExpression , overwrite );
342
+ }
343
+
344
+ /**
345
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header where the
346
+ * value is obtained by invoking the {@link Function} callback.
347
+ * If the header exists, it will <b>not</b> be overwritten
348
+ * unless {@link #defaultOverwrite(boolean)} is true.
349
+ * @param correlationIdFunction the function.
350
+ * @param <P> the payload type.
351
+ * @return the header enricher spec.
352
+ * @see FunctionExpression
353
+ * @since 5.2
354
+ */
355
+ public <P > HeaderEnricherSpec correlationIdFunction (Function <Message <P >, Object > correlationIdFunction ) {
356
+ return correlationIdFunction (correlationIdFunction , null );
357
+ }
358
+
359
+ /**
360
+ * Add a {@link IntegrationMessageHeaderAccessor#CORRELATION_ID} header where the
361
+ * value is obtained by invoking the {@link Function} callback.
362
+ * @param correlationIdFunction the function.
363
+ * @param overwrite true to overwrite an existing header.
364
+ * @param <P> the payload type.
365
+ * @return the header enricher spec.
366
+ * @see FunctionExpression
367
+ * @since 5.2
368
+ */
369
+ public <P > HeaderEnricherSpec correlationIdFunction (Function <Message <P >, ?> correlationIdFunction ,
370
+ Boolean overwrite ) {
371
+
372
+ return headerFunction (IntegrationMessageHeaderAccessor .CORRELATION_ID , correlationIdFunction , overwrite );
373
+ }
374
+
375
+ /**
376
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header: bean name or instance.
377
+ * If the header exists, it will <b>not</b> be overwritten unless {@link #defaultOverwrite(boolean)} is true.
378
+ * @param replyChannel the header value for {@link MessageHeaders#REPLY_CHANNEL}.
379
+ * @return the header enricher spec.
380
+ * @since 5.2
381
+ */
382
+ public HeaderEnricherSpec replyChannel (Object replyChannel ) {
383
+ return replyChannel (replyChannel , null );
384
+ }
385
+
386
+ /**
387
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header: bean name or instance.
388
+ * @param replyChannel the header value for {@link MessageHeaders#REPLY_CHANNEL}.
389
+ * @param overwrite true to overwrite an existing header.
390
+ * @return the header enricher spec.
391
+ * @since 5.2
392
+ */
393
+ public HeaderEnricherSpec replyChannel (Object replyChannel , Boolean overwrite ) {
394
+ return header (MessageHeaders .REPLY_CHANNEL , replyChannel , overwrite );
395
+ }
396
+
397
+ /**
398
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header
399
+ * where the value is a SpEL {@link Expression} evaluation result.
400
+ * If the header exists, it will <b>not</b> be overwritten
401
+ * unless {@link #defaultOverwrite(boolean)} is true.
402
+ * @param replyChannelExpression the expression for {@link MessageHeaders#REPLY_CHANNEL} header.
403
+ * @return the header enricher spec.
404
+ * @since 5.2
405
+ */
406
+ public HeaderEnricherSpec replyChannelExpression (String replyChannelExpression ) {
407
+ return replyChannelExpression (replyChannelExpression , null );
408
+ }
409
+
410
+ /**
411
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header
412
+ * where the value is a SpEL {@link Expression} evaluation result.
413
+ * @param replyChannelExpression the expression for {@link MessageHeaders#REPLY_CHANNEL} header.
414
+ * @param overwrite true to overwrite an existing header.
415
+ * @return the header enricher spec.
416
+ * @since 5.2
417
+ */
418
+ public HeaderEnricherSpec replyChannelExpression (String replyChannelExpression , Boolean overwrite ) {
419
+ return headerExpression (MessageHeaders .REPLY_CHANNEL , replyChannelExpression , overwrite );
420
+ }
421
+
422
+ /**
423
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header where the
424
+ * value is obtained by invoking the {@link Function} callback.
425
+ * If the header exists, it will <b>not</b> be overwritten
426
+ * unless {@link #defaultOverwrite(boolean)} is true.
427
+ * @param replyChannelFunction the function.
428
+ * @param <P> the payload type.
429
+ * @return the header enricher spec.
430
+ * @see FunctionExpression
431
+ * @since 5.2
432
+ */
433
+ public <P > HeaderEnricherSpec replyChannelFunction (Function <Message <P >, Object > replyChannelFunction ) {
434
+ return replyChannelFunction (replyChannelFunction , null );
435
+ }
436
+
437
+ /**
438
+ * Add a {@link MessageHeaders#REPLY_CHANNEL} header where the
439
+ * value is obtained by invoking the {@link Function} callback.
440
+ * @param replyChannelFunction the function.
441
+ * @param overwrite true to overwrite an existing header.
442
+ * @param <P> the payload type.
443
+ * @return the header enricher spec.
444
+ * @see FunctionExpression
445
+ * @since 5.2
446
+ */
447
+ public <P > HeaderEnricherSpec replyChannelFunction (Function <Message <P >, ?> replyChannelFunction ,
448
+ Boolean overwrite ) {
449
+
450
+ return headerFunction (MessageHeaders .REPLY_CHANNEL , replyChannelFunction , overwrite );
451
+ }
452
+
453
+ /**
454
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header: bean name or instance.
455
+ * If the header exists, it will <b>not</b> be overwritten unless {@link #defaultOverwrite(boolean)} is true.
456
+ * @param errorChannel the header value for {@link MessageHeaders#ERROR_CHANNEL}.
457
+ * @return the header enricher spec.
458
+ * @since 5.2
459
+ */
460
+ public HeaderEnricherSpec errorChannel (Object errorChannel ) {
461
+ return errorChannel (errorChannel , null );
462
+ }
463
+
464
+ /**
465
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header: bean name or instance.
466
+ * @param errorChannel the header value for {@link MessageHeaders#ERROR_CHANNEL}.
467
+ * @param overwrite true to overwrite an existing header.
468
+ * @return the header enricher spec.
469
+ * @since 5.2
470
+ */
471
+ public HeaderEnricherSpec errorChannel (Object errorChannel , Boolean overwrite ) {
472
+ return header (MessageHeaders .ERROR_CHANNEL , errorChannel , overwrite );
473
+ }
474
+
475
+ /**
476
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header
477
+ * where the value is a SpEL {@link Expression} evaluation result.
478
+ * If the header exists, it will <b>not</b> be overwritten
479
+ * unless {@link #defaultOverwrite(boolean)} is true.
480
+ * @param errorChannelExpression the expression for {@link MessageHeaders#ERROR_CHANNEL} header.
481
+ * @return the header enricher spec.
482
+ * @since 5.2
483
+ */
484
+ public HeaderEnricherSpec errorChannelExpression (String errorChannelExpression ) {
485
+ return errorChannelExpression (errorChannelExpression , null );
486
+ }
487
+
488
+ /**
489
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header
490
+ * where the value is a SpEL {@link Expression} evaluation result.
491
+ * @param errorChannelExpression the expression for {@link MessageHeaders#ERROR_CHANNEL} header.
492
+ * @param overwrite true to overwrite an existing header.
493
+ * @return the header enricher spec.
494
+ * @since 5.2
495
+ */
496
+ public HeaderEnricherSpec errorChannelExpression (String errorChannelExpression , Boolean overwrite ) {
497
+ return headerExpression (MessageHeaders .ERROR_CHANNEL , errorChannelExpression , overwrite );
498
+ }
499
+
500
+ /**
501
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header where the
502
+ * value is obtained by invoking the {@link Function} callback.
503
+ * If the header exists, it will <b>not</b> be overwritten
504
+ * unless {@link #defaultOverwrite(boolean)} is true.
505
+ * @param errorChannelFunction the function.
506
+ * @param <P> the payload type.
507
+ * @return the header enricher spec.
508
+ * @see FunctionExpression
509
+ * @since 5.2
510
+ */
511
+ public <P > HeaderEnricherSpec errorChannelFunction (Function <Message <P >, Object > errorChannelFunction ) {
512
+ return errorChannelFunction (errorChannelFunction , null );
513
+ }
514
+
515
+ /**
516
+ * Add a {@link MessageHeaders#ERROR_CHANNEL} header where the
517
+ * value is obtained by invoking the {@link Function} callback.
518
+ * @param errorChannelFunction the function.
519
+ * @param overwrite true to overwrite an existing header.
520
+ * @param <P> the payload type.
521
+ * @return the header enricher spec.
522
+ * @see FunctionExpression
523
+ * @since 5.2
524
+ */
525
+ public <P > HeaderEnricherSpec errorChannelFunction (Function <Message <P >, ?> errorChannelFunction ,
526
+ Boolean overwrite ) {
527
+
528
+ return headerFunction (MessageHeaders .ERROR_CHANNEL , errorChannelFunction , overwrite );
529
+ }
530
+
531
+
293
532
/**
294
533
* Add a single header specification. If the header exists, it will <b>not</b> be
295
534
* overwritten unless {@link #defaultOverwrite(boolean)} is true.
@@ -352,7 +591,7 @@ public HeaderEnricherSpec headerExpression(String name, String expression, Boole
352
591
* @return the header enricher spec.
353
592
* @see FunctionExpression
354
593
*/
355
- public <P > HeaderEnricherSpec headerFunction (String name , Function <Message <P >, Object > function ) {
594
+ public <P > HeaderEnricherSpec headerFunction (String name , Function <Message <P >, ? > function ) {
356
595
return headerFunction (name , function , null );
357
596
}
358
597
@@ -366,7 +605,7 @@ public <P> HeaderEnricherSpec headerFunction(String name, Function<Message<P>, O
366
605
* @return the header enricher spec.
367
606
* @see FunctionExpression
368
607
*/
369
- public <P > HeaderEnricherSpec headerFunction (String name , Function <Message <P >, Object > function ,
608
+ public <P > HeaderEnricherSpec headerFunction (String name , Function <Message <P >, ? > function ,
370
609
Boolean overwrite ) {
371
610
372
611
return headerExpression (name , new FunctionExpression <>(function ), overwrite );
0 commit comments