Java Tip: Write an SOA integration layer with Apache Camel

Web services integration with Spring and Apache Camel

1 2 3 4 5 6 Page 2
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.

1 2 3 4 5 6 Page 2
Page 2 of 6