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 3
Page 3 of 6

The steps to implement our SOA integration layer are as follows:

  • Step 1: Generate Java types for the three WSDLs
  • Step 2: Configure the Camel CXF endpoints
  • Step 3: Configure the Camel routes to use multicasting
  • Step 4: Configure the Camel routes for message transformation
  • Step 5: Write the XSLT sheets for message transformation
  • Step 6: Use WireTap to log messages
  • Step 7: Create the CamelContext XML
  • Step 8: Build and deploy the application

 Step 1: Generate Java types for the three WSDLs

To start, we use the Maven cxf-codegen-plugin and the wsdl2java tool provided by CXF to generate the Java artifacts from the three WSDLs found in the article source code. To execute the POM, use: cmd : mvn generate-sources. CXF generates the Java artifacts and puts them in the specified directory. We then use Maven to build our artifacts.

Listing 1. Maven plugin for generating Java stubs from WSDLs

                                    //ReservationService invoked by Portal
                                    //ReservationService exposed by Airline A
                                    //ReservationService exposed by Airline B

 Step 2: Configure the Camel CXF endpoints

Next, we define the endpoints for ReservationService, ReservationServiceAirlineA, and ReservationServiceAirlineB shown in Listing 2 below. These endpoints will be used subsequently in our Camel routes. Note that the Service interface class generated in Step 1 is referenced by the camel-cxf endpoint.

The camel-cxf endpoint uses the default dataFormat=POJO. In this example we used the data format of PAYLOAD to get the raw XML into our Camel endpoint and process the XML in our Camel routes. Enabling schema validation validates the incoming request against the XSD schema defined in the WSDL, which reduces the time we would otherwise need to invest in validation.

Listing 2. Camel CXF endpoints for web services

//Endpoint of Mock ReservationService for Airline A
    <cxf:cxfEndpoint id="airlineAEndpoint"
        address="http://localhost:8089/QuoteService" serviceClass="com.sample.aira.quote.AirLineAQuote"
            <entry key="dataFormat" value="PAYLOAD" />

    //Endpoint of Mock ReservationService for Airline B
    <cxf:cxfEndpoint id="airlineBEndpoint"
        address="http://localhost:8088/QuoteService" serviceClass="com.sample.airb.quote.AirLineBQuote"
            <entry key="dataFormat" value="PAYLOAD" />

    //Endpoint of ReservationService
    <cxf:cxfEndpoint id="reservationService" address="/QuoteService"
        serviceClass="com.sample.air.quote.AirLineQuote" wsdlURL="wsdl/ReservationService.wsdl">
            <entry key="dataFormat" value="PAYLOAD" />
            <entry key="schema-validation-enabled" value="true" />

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