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 2 of 6

Enterprise integration with Apache Camel

Figure 2 shows how we plan to implement our requirements using Spring configuration and built-in Camel components.

Figure 2. Camel implementation of an SOA integration layer (click to enlarge)

As shown, a portal user (Consumer) sends a GetQuote request consisting of a starting location, travel destination and dates, and (optionally) the preferred airline. The response consists of an array of price elements with the airline name. The portal ReservationService accepts the GetQuote request. Based on the Consumer's preferences, it invokes the ReservationServices of either Airline A or Airline B or All. It then aggregates and returns the responses obtained from these web services to the Consumer.

The three web services in our SOA are integrated using Camel routes, which are defined in XML files. We'll also need to write some Java code for the processors that comprise the routes.

Camel terminology

An Apache Camel route is essentially a chain of processors, which allows messages to flow between Camel endpoints. A Camel route refers to endpoints as URIs. Messages are contained during routing in a component called an Exchange. Finally, the Camel runtime, known as the CamelContext, glues these components (routes and endpoints) together.

Components of the Camel SOA integration layer

Before we proceed into the demo we'll briefly introduce the Apache Camel components that we'll use to create the SOA integration layer for our reservation service implementation:

  • Camel CXF Endpoint: Camel uses Apache CXF for web services implementation. We'll use the the Camel CXF component to configure all three of our web services (the portal ReservationService and the two airline ReservationServices) and use them in the Camel routes.
  • Camel Bean: Camel's component for using JavaBeans. We'll use the Camel Bean to set up custom processing in some of the steps that follow.
  • Camel Direct: Connects two routes via direct synchronous invocation.
  • Camel XSLT: Loads and uses XSLT sheets via Spring's resource loading mechanism. We'll use the XSLT component to do request-and-response transformations.
  • Camel Multicast EIP: This pattern allows us to send messages to several different destinations for processing. We'll use multicasting to send requests from the portal ReservationService to our two airline ReservationServices.
  • Camel Aggregator EIP: This pattern combines the results of individual but related messages into a single outgoing message. We'll use Aggregator to combine the responses from our two airline Reservation Services.
  • Camel WireTap EIP: This pattern lets us inspect messages as they flow through the system. We'll use this EIP to log messages at appropriate points in the flow shown in Figure 1.

Web services interfaces

You may find the WSDL files and associated XML schemas for our web services interfaces in the source code for this demo.

  • 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 ).