diff --git a/basic/enricher/README.md b/basic/enricher/README.md index e862836c..e03919b3 100644 --- a/basic/enricher/README.md +++ b/basic/enricher/README.md @@ -14,19 +14,19 @@ You can run the sample application by either - mvn package - mvn exec:java -This example illustrates the usage of the Content Enricher by covering 2 use-cases. -Once the application is started, you can execute each individual use case by: - +This example illustrates the usage of the Content Enricher. + +Once the application has started, lease execute the various Content Enricher examples by + * entering 1 + Enter * entering 2 + Enter - -Each use case will trigger slightly different Spring Integration message flows. For -both flows a **User** object containing only the **username** is passed in through a *Gateway*. - -However the Enrichment is executed differently for each flow: - -* 1: In the *Enricher*, pass the full **User** object to the **request channel**. -* 2: In the *Enricher*, pass only the **username** to the **request channel** by using the **request-payload-expression** attribute. +* entering 3 + Enter + +3 different message flows are triggered. For use-cases 1+2 a **User** object containing only the **username** is passed in. For use-case 3 a Map with the **username** key is passed in and enriched with the **User** object using the **user** key: + +* 1: In the *Enricher*, pass the full **User** object to the **request channel**. +* 2: In the *Enricher*, pass only the **username** to the **request channel** by using the **request-payload-expression** attribute. +* 3: In the *Enricher*, pass only the username to the **request channel**, executing the same Service Activator as in **2**. # Resources diff --git a/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/Main.java b/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/Main.java index 7bc7ea50..92f67e0c 100644 --- a/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/Main.java +++ b/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/Main.java @@ -15,6 +15,8 @@ */ package org.springframework.integration.samples.enricher; +import java.util.HashMap; +import java.util.Map; import java.util.Scanner; import org.slf4j.Logger; @@ -73,15 +75,16 @@ public final class Main { + EMPTY_LINE + "\n This example illustrates the usage of the Content Enricher. " + EMPTY_LINE - + "\n Usage: Please enter 1 + Enter or 2 + Enter " + + "\n Usage: Please enter 1 or 2 or 3 + Enter " + EMPTY_LINE - + "\n 2 different message flows are triggered. For both flows a " + + "\n 3 different message flows are triggered. For sample 1+2 a " + "\n user object containing only the username is passed in. " - + EMPTY_LINE - + "\n However the Enrichment is executed differently: " + + "\n For sample 3 a Map with the 'username' key is passed in and enriched " + + "\n with the user object using the 'user' key. " + EMPTY_LINE + "\n 1: In the Enricher, pass the full User object to the request channel. " + "\n 2: In the Enricher, pass only the username to the request channel. " + + "\n 3: In the Enricher, pass only the username to the request channel. " + EMPTY_LINE + LINE_SEPARATOR); @@ -101,6 +104,17 @@ public final class Main { final User fullUser = service.findUserByUsername(user); printUserInformation(fullUser); + } else if ("3".equals(input)) { + + final Map userData = new HashMap(); + userData.put("username", "foo_map"); + + final Map enrichedUserData = service.findUserWithUsernameInMap(userData); + + final User fullUser = (User) enrichedUserData.get("user"); + + printUserInformation(fullUser); + } else { LOGGER.info("\n\n Please enter '1' or '2' :\n\n"); } diff --git a/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/service/UserService.java b/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/service/UserService.java index d26a0c45..3b2cdcac 100644 --- a/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/service/UserService.java +++ b/basic/enricher/src/main/java/org/springframework/integration/samples/enricher/service/UserService.java @@ -15,6 +15,8 @@ */ package org.springframework.integration.samples.enricher.service; +import java.util.Map; + import org.springframework.integration.samples.enricher.User; /** @@ -34,4 +36,11 @@ public interface UserService { */ User findUserByUsername(User user); + /** + * Retrieves a user based on the provided username that is provided as a Map + * entry using the mapkey 'username'. Map object is routed to the + * "findUserWithMapChannel" channel. + */ + Map findUserWithUsernameInMap(Map userdata); + } diff --git a/basic/enricher/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/basic/enricher/src/main/resources/META-INF/spring/integration/spring-integration-context.xml index 8c55e18f..b9b57f57 100644 --- a/basic/enricher/src/main/resources/META-INF/spring/integration/spring-integration-context.xml +++ b/basic/enricher/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -7,9 +7,7 @@ - - - + @@ -20,8 +18,9 @@ - - + + + + + +