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

  <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>2.7.0</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${basedir}/src/main/java</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    //ReservationService invoked by Portal
                                    <wsdl>${basedir}/src/main/resources/wsdl/ReservationService.wsdl</wsdl>
                                </wsdlOption>
                                <wsdlOption>
                                    //ReservationService exposed by Airline A
                                    <wsdl>${basedir}/src/main/resources/wsdl/ReservationServiceAirlineA.wsdl</wsdl>
                                </wsdlOption>
                                <wsdlOption>
                                    //ReservationService exposed by Airline B
                                    <wsdl>${basedir}/src/main/resources/wsdl/ReservationServiceAirlineB.wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

 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"
        wsdlURL="wsdl/ReservationServiceAirlineA.wsdl">
        <cxf:properties>
            <entry key="dataFormat" value="PAYLOAD" />
        </cxf:properties>
    </cxf:cxfEndpoint>


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

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


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