Skip to content

Commit 9ae0eb2

Browse files
artembilangaryrussell
authored andcommitted
INT-4540: Use MessageHeaders in GenericHandler (#2589)
* INT-4540: Use MessageHeaders in GenericHandler JIRA: https://jira.spring.io/browse/INT-4540 For better end-user experience use a `MessageHeaders` in the `GenericHandler` instead of plain `Map<String, Object>` * * Fix `IntegrationFlowEventsTests`
1 parent 716494c commit 9ae0eb2

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

spring-integration-core/src/main/java/org/springframework/integration/handler/GenericHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2016 the original author or authors.
2+
* Copyright 2016-2018 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.
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.integration.handler;
1818

19-
import java.util.Map;
19+
import org.springframework.messaging.MessageHeaders;
2020

2121
/**
2222
* A functional interface to specify {@link org.springframework.messaging.MessageHandler}
@@ -36,6 +36,6 @@
3636
@FunctionalInterface
3737
public interface GenericHandler<P> {
3838

39-
Object handle(P payload, Map<String, Object> headers);
39+
Object handle(P payload, MessageHeaders headers);
4040

4141
}

spring-integration-event/src/test/java/org/springframework/integration/event/dsl/IntegrationFlowEventsTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import static org.junit.Assert.assertNull;
2323
import static org.junit.Assert.assertThat;
2424

25-
import java.util.Map;
2625
import java.util.concurrent.atomic.AtomicReference;
2726

2827
import org.junit.BeforeClass;
@@ -49,6 +48,7 @@
4948
import org.springframework.integration.store.SimpleMessageStore;
5049
import org.springframework.messaging.Message;
5150
import org.springframework.messaging.MessageChannel;
51+
import org.springframework.messaging.MessageHeaders;
5252
import org.springframework.messaging.PollableChannel;
5353
import org.springframework.messaging.support.GenericMessage;
5454
import org.springframework.test.annotation.DirtiesContext;
@@ -148,7 +148,7 @@ public void setFoo(Integer foo) {
148148
}
149149

150150
@Override
151-
public Object handle(Integer p, Map<String, Object> h) {
151+
public Object handle(Integer p, MessageHeaders h) {
152152
return p * 2;
153153
}
154154

spring-integration-webflux/src/test/java/org/springframework/integration/webflux/dsl/WebFluxDslTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ public IntegrationFlow sseFlow() {
370370
.requestMapping(m -> m.produces(MediaType.TEXT_EVENT_STREAM_VALUE))
371371
.mappedResponseHeaders("*"))
372372
.enrichHeaders(Collections.singletonMap("aHeader", new String[] { "foo", "bar", "baz" }))
373-
.handle((p, h) -> Flux.fromArray((String[]) h.get("aHeader")))
373+
.handle((p, h) -> Flux.fromArray(h.get("aHeader", String[].class)))
374374
.get();
375375
}
376376

src/reference/asciidoc/dsl.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ Similar lambda configurations are provided for the `resequence()` EIP method.
476476
The `.handle()` EIP method's goal is to invoke any `MessageHandler` implementation or any method on some POJO.
477477
Another option is to define an "`activity`" by using lambda expressions.
478478
Consequently, we introduced a generic `GenericHandler<P>` functional interface.
479-
Its `handle` method requires two arguments: `P payload` and `Map<String, Object> headers`.
479+
Its `handle` method requires two arguments: `P payload` and `MessageHeaders headers` (starting with version 5.1).
480480
Having that, we can define a flow as follows:
481481

482482
====

src/reference/asciidoc/whats-new.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ This avoid confusion with `log()` which is treated as a one-way end flow compone
4141

4242
A generated bean name for any `NamedComponent` within an integration flow is now based on the component type for better readability from visual tools, logs analyzers and metrics collectors.
4343

44+
The `GenericHandler.handle()` now excepts a `MessageHeaders` type for the second argument.
45+
4446
[[x5.1-dispatcher-exceptions]]
4547
==== Dispatcher Exceptions
4648

0 commit comments

Comments
 (0)