Spring Integration: A Hands-On Tutorial Part 2
Integrating web-based RFI forms
[The code for this section is available here]
Request for information forms, or RFIs, are an important piece of the lead management domain. They allow prospective customers to find out more, and they result in a lead being created in the lead management system. Qualifying reps or else salespersons can then pull the lead out of the CRM and follow up, providing the requested information. In the context of our hypothetical online university, enrollment advisors might for example contact prospective students with information about academic programs, financial aid and so on.
Figure 2 shows how our web-based RFI fits into the overall scheme of things.
Figure 2: We're going to accept leads from web-based RFI forms.
Let's go through the various steps involved in adding the new web-based RFI to the overall integration.
Add the lead generation website
RFI forms live on customer-facing lead generation websites, so we're going to need a separate Maven module. See the code download for the leadgen module. Normally this would be an entire website that describes university events, academic programs, student and faculty profiles, accreditation information and that sort of thing. Here though we're interested in only the RFI form itself, so that's all our sample lead gen site has.
When the user submits the RFI, it goes to a web MVC controller (part of the lead gen site), which in turn passes it to a service bean (still part of the lead gen site). The service bean uses HttpClient to send an HTTP POST request through the firewall to the CRM, which would typically live on the internal network. So as this example shows, we can integrate systems in the DMZ with those on the internal network.
Once the HTTP request makes it onto the bus (and we'll show how that works shortly), we have to have a way to transform it into a Lead object that we can place on the newLeadChannel. The next section shows how to do that.
Transform the HTTP POST request parameters to a Lead
In the first tutorial we created a transformer bean to convert Leads into MailMessages so we could send prospective students a confirmation e-mail. Here we're going to create another transformer bean, this time to map the HTTP POST request to a Lead. Listing 4 shows how it's done.
We've already covered the mechanics of creating a transformer bean, so there's no need to repeat that. In this case, the HTTP channel adapter (we'll see it momentarily) creates a Message with a Map of HTTP parameters as its payload, so that's why our @Transformer method takes a Map as an input.
The last step is once again to configure the message bus.
Configure the message bus to add the new pipeline
There's not much of a change to applicationContext-integration.xml, so instead of showing the whole configuration, listing 5 concentrates on the parts that change.
Listing 5. Updates to /WEB-INF/applicationContext-integration.xml
<?xml version="1.0" encoding="UTF-8"?>
... other namespace declarations ...
... other schema locations ...
<channel id="httpLeadChannel" />
<transformer input-channel="httpLeadChannel" output-channel="newLeadChannel">
<beans:bean class="crm.integration.transformers.HttpToLeadTransformer" />
... other message bus configuration ...
We've added the new http namespace and schema location, and we're using it to declare an inbound HTTP channel adapter that handles requests coming to the /leads path, thanks to the BeanNameUrlHandlerMapping. (See Spring Web MVC if you're unfamiliar with how that works.) The full URI is
and that's the destination URI for the HTTP POST requests that the lead gen website's HttpClient sends. The inbound channel adapter listens for HTTP POST requests mapping to that URI and then pushes a Message containing the parameter map onto the httpLeadChannel. The bus takes over from there.
We have a transformer definition, but we've already seen one of those so we won't cover it again.
To try it out, start up your CRM and lead gen site, and direct your browser to
The RFI form as it currently stands doesn't provide any way to specify the country, so the country will be null and RFI leads will all route through the domestic channel and end up in the local CRM. So you don't need to start up the external CRM.
One more before we call it a day: an e-mail based RFI.
(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)