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 5
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"/>   
1 2 3 4 5 6 Page 5
Page 5 of 6