Spring Integration: A Hands-On Tutorial Part 2
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.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)