Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java tip: Write an SOA integration layer with Apache Camel

Web services integration with Spring and Apache Camel

  • Print
  • Feedback

Page 5 of 6

 Step 5: Write the XSLT sheets for message transformation

In this step we apply XSL transformation to generate the request type of the destination web service. Apache Camel allows the use of XSLT sheets via the Camel XSLT component. The input will be the raw XML obtained from the ReservationService endpoint. This approach eliminates the need to do XML-to-Java binding and is more efficient and maintainable. As previously mentioned, the transformation rules are defined in custom XSLT sheets, which are loaded using the Camel XSLT component. With this approach we are able to update the mapping rules by making changes in the XSLT sheet itself, without updating the Java code. For example, we use the XSLT sheet to transform the request XML of the portal ReservationService into the destination-request XML of the Airline A and Airline B ReservationServices. We apply a similar technique for response transformation. (See the article source to view a sample XSLT sheet.)

Note: The Camel XSLT component uses optimized Spring resource loading to load the XSLT sheets. It also uses a caching mechanism, which is enabled by default.

 Step 6: Use WireTap to log the message

Wire Tap is an EIP that creates a copy of an original message and routes it to another destination. Here, we use Camel's wireTap component to log the messages flowing between our three web services at appropriate points. We actually called the wireTap component in Step 4 to direct a message to a route as shown below. The route in Listing 5 uses a JavaBean to log messages into an appropriate data store, such as a file or database.

Listing 5. Message logging with Camel's wireTap component

//Use wireTap in the main route where necessary, and send to a desired route using Camel's direct component
<wireTap uri="direct:logInfo"/> 

//Log the message in this route
<route id = "auditLogging">
    <from uri="direct:logInfo"/>

    //log the request object in database / file
    <to uri="bean:logAudit"/>   
</route>

  • Print
  • Feedback

Resources
  • Download the complete source code for this article.
  • Read more articles in JavaWorld's Java tips series.
  • "Hello Camel: Automatic File Transfer" (Dustin Marx, JW Blogs, January 2013): Get another quick introduction to Apache Camel, this time using it to transfer files automatically from one specified directory to another.
  • "Open source Java projects: Vert.x" (Steven Haines, JavaWorld, July 2013): If you're challenged by enterprise integration you might want to check out Vert.x, an enterprise messaging and integration framework similar to Node.js, that runs on the JVM.
  • "Open Source Integration with Apache Camel and How Fuse IDE Can Help" (Jonathan Anstey, Dzone, May 2011): Try another hands-on implementation example, this time with graphical tooling from the Fuse IDE in the mix.
  • Learn more about Camel from the classic book by Claus Ibsen and Jonathan Anstey: Camel in Action (Manning Publications, December 2010 ).