INTSAMPLES-34 Added sample for enriching a Map

This commit is contained in:
Gunnar Hillert
2011-11-07 17:22:02 -05:00
parent ac5693d310
commit e08a4a775d
4 changed files with 48 additions and 20 deletions

View File

@@ -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

View File

@@ -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<String, Object> userData = new HashMap<String, Object>();
userData.put("username", "foo_map");
final Map<String, Object> enrichedUserData = service.findUserWithUsernameInMap(userData);
final User fullUser = (User) enrichedUserData.get("user");
printUserInformation(fullUser);
} else {
LOGGER.info("\n\n Please enter '1' or '2' <enter>:\n\n");
}

View File

@@ -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<String, Object> findUserWithUsernameInMap(Map<String, Object> userdata);
}

View File

@@ -7,9 +7,7 @@
<int:channel id="findUserEnricherChannel"/>
<int:channel id="findUserByUsernameEnricherChannel"/>
<int:channel id="findUserInputChannel"/>
<int:channel id="findUserByUsernameInputChannel"/>
<int:channel id="findUserWithMapEnricherChannel"/>
<int:channel id="findUserServiceChannel"/>
<int:channel id="findUserByUsernameServiceChannel"/>
@@ -20,8 +18,9 @@
<int:gateway id="userGateway" default-request-timeout="5000"
default-reply-timeout="5000"
service-interface="org.springframework.integration.samples.enricher.service.UserService">
<int:method name="findUser" request-channel="findUserEnricherChannel"/>
<int:method name="findUserByUsername" request-channel="findUserByUsernameEnricherChannel"/>
<int:method name="findUser" request-channel="findUserEnricherChannel"/>
<int:method name="findUserByUsername" request-channel="findUserByUsernameEnricherChannel"/>
<int:method name="findUserWithUsernameInMap" request-channel="findUserWithMapEnricherChannel"/>
</int:gateway>
<int:enricher id="findUserEnricher"
@@ -39,6 +38,12 @@
<int:property name="password" expression="payload.password"/>
</int:enricher>
<int:enricher id="findUserWithMapEnricher"
input-channel="findUserWithMapEnricherChannel"
request-channel="findUserByUsernameServiceChannel"
request-payload-expression="payload.username">
<int:property name="user" expression="payload"/>
</int:enricher>
<int:service-activator id="findUserServiceActivator"
ref="systemService" method="findUser"