Enterprise Integration Zone is brought to you in partnership with:

Willie Wheeler is a Principal Applications Engineer with Expedia, working on continuous delivery, including build automation, test automation, configuration management and application performance management. He's also the lead author of the book Spring in Practice (Manning). Willie is a DZone MVB and is not an employee of DZone and has posted 23 posts at DZone. You can read more from them at their website. View Full User Profile

Spring Integration: A Hands-On Tutorial Part 2

08.26.2009
| 54229 views |
  • submit to reddit

This is the second of a two-part series of tutorials on Spring Integration. The first tutorial provided a high-level overview of Spring Integration along with a quick introduction to the lead management domain. It also showed how to take some initial steps into the world of Spring Integration, and we built a simple lead entry form with a confirmation e-mail. In this second installment we'll continue building the message bus we started in the first. Once again our example domain will be enrollment lead management in the context of an online university.

In part 1 new leads flowed to a service activator that called a local LeadService.createLead() service bean method, which then pretended to save the lead to a database. Let's revisit that.

Routing international leads to an external CRM

[The source code for this section is available here. The funny numbering scheme is due to the fact that this section was originally section 5 of a single tutorial.]

As just mentioned, the bus currently drops enrollment leads into the CRM's lead database. Let's say, however, that we actually have a couple of different teams involved in processing enrollment leads: one team for domestic (U.S.) leads and another for international leads. The international team already uses a separate legacy CRM that eventually we plan to phase out, but for now we need to use it. So the problem is to route domestic leads to the CRM that the domestic team uses, and international teams to the legacy CRM.

Figure 1 shows how we're going to use a router to solve this problem.

 

 

 


Figure 1. Send domestic leads to the local CRM and international leads to a different CRM.

To put all of this in place we need to take care of several things, including creating a dummy external CRM for international leads, updating the local CRM POM, updating the Lead class to support content-based routing and serialization to XML, and adding further configuration to applicationContext-integration.xml to build out the new parts of the pipeline.

We'll take care of the dummy external CRM first, since that's self-contained.

Create a dummy external CRM for international leads

We won't cover the details here, but in the sample code we've added a new Maven module called xcrm (for "External CRM") to the top-level POM. All it contains is are some configuration files and a dummy web service endpoint—implemented as a plain old servlet—to log the HTTP request payload to the console. That's our "CRM." It will allow us to see the SOAP message we'll be sending it shortly, which is of course the real point of our including it.

Now we need to make several updates to the local CRM. We'll start with the POM and go from there.

Update the CRM POM

There are several POM dependencies we need to add to crm/pom.xml, mostly surrounding XML and SOAP web services. See the code download for details. I've used a Maven profile to support Java 5. If you know for sure that you're using Java 5, you can simply add those dependencies to the dependencies section of the POM instead of adding them to a profile. Alternatively, if you know for sure that you're using Java 6, you can omit them completely, as they're included with the Java 6 SDK.

You'll also need to add the spring.ws.version, jaxb.version and saaj.version properties.

Now let's check out the Lead class. There are a couple of different things we'll need to do.

DZone readers get 30% off Spring in Practice by Willie Wheeler and John Wheeler. Use code dzone30 when checking out with any version of the book at www.manning.com.

AttachmentSize
spring-integration-demo-5.zip29.93 KB
spring-integration-demo-6.zip42.65 KB
spring-integration-demo-7.zip44.91 KB
Published at DZone with permission of Willie Wheeler, author and DZone MVB.

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)

Tags:

Comments

Morali Julien replied on Wed, 2010/02/24 - 12:52pm

Hi Willie,

 

Thx for this post, it was really helpfull to me.

Still, I have a problem configuring an IMAP access to a gmail account.

As GMail's usernames are "xxx@gmail.com", the store-uri parameter is incorrect because of the "@"which is considered as a separator...

 I read that you mentionned a gmail account for testing, so did you manage to solve this problem ???

 

Thx by advance for your help !

Julien.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.