Java Tip: Write an SOA integration layer with Apache Camel

Web services integration with Spring and Apache Camel

In this Java tip, learn how to use Apache Camel to develop a quick-and-easy integration layer for a service-oriented architecture. Apache Camel lets you configure Camel integration components for web service endpoints; message transformation, routing, and aggregation; and exception handling. All with a minimum of Java coding.


Integration is a top priority for enterprise projects that seek to connect multiple web service endpoints quickly, efficiently, and maintainably. From a development standpoint, integration can also be a serious challenge. One way to ease that challenge is by using an integration framework like Apache Camel.

Apache Camel's API and out-of-the-box components implement many common enterprise integration patterns (EIPs), making it relatively simple and easy to do integration tasks such as connecting web services, performing XSL transformations, logging audits, and more. In this Java tip we introduce a process for using Apache Camel as an integration solution. We start with a business integration problem involving multiple web services. We then map the problem, briefly discuss the components needed to resolve it, and implement a solution based on Apache Camel's routing engine.

An enterprise integration scenario

Say that we are given an airline portal that wants to develop a web service for its online reservation service. The service will aggregate fare quotes from multiple airline companies in order to provide portal visitors searching for flights with the best available fares. This scenario involves connecting multiple web services: The portal will invoke a ReservationService to collect a list of quotes based on the given search criteria. The portal ReservationService will then invoke the ReservationServices exposed by various airlines, consolidate the quotes, and return the results to the portal user. This is a typical integration scenario where a composite web service invokes multiple external web services and aggregates the responses.

Figure 1 shows a flow diagram of an SOA architecture for the portal reservation service and two airline reservation services. (Note that we are using a contract-first or Design by Contract for this demonstration.)

Figure 1. Flow diagram of an SOA architecture (click to enlarge)

Solving the problem with Java

Creating a custom solution for this business problem would mean writing a lot of Java code. We would need to map and transform the Request objects from their source formats to the target format; use Java threads to invoke both of the airline web services in parallel; set up event listeners to wait for both services to respond; aggregate the responses; and also manage supporting tasks like logging and exception handling.

Using Apache Camel as an integration framework shortcuts a lot of that programming. We can simply leverage Camel's API and components, which are designed to resolve most web services integration tasks with standard enterprise integration patterns (EIPs). Rather than Java code, we'll work with a streamlined domain-specific language (DSL). Apache Camel provides DSLs based on Java, Scala, Groovy, or XML. In this case, we'll use Camel's XML-based Spring DSL to specify the routing and configure our integration layer.

1 2 3 4 5 6 Page 1