Newsletter sign-up
View all newsletters

Enterprise Java Newsletter
Stay up to date on the latest tutorials and Java community news posted on JavaWorld

Sponsored Links

Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs

Java tip: Write an SOA integration layer with Apache Camel

Web services integration with Spring and Apache Camel

  • Print
  • Feedback

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>


  • Print
  • Feedback

Resources
  • Download the complete source code for this article.
  • Read more articles in JavaWorld's Java tips series.
  • "Hello Camel: Automatic File Transfer" (Dustin Marx, JW Blogs, January 2013): Get another quick introduction to Apache Camel, this time using it to transfer files automatically from one specified directory to another.
  • "Open source Java projects: Vert.x" (Steven Haines, JavaWorld, July 2013): If you're challenged by enterprise integration you might want to check out Vert.x, an enterprise messaging and integration framework similar to Node.js, that runs on the JVM.
  • "Open Source Integration with Apache Camel and How Fuse IDE Can Help" (Jonathan Anstey, Dzone, May 2011): Try another hands-on implementation example, this time with graphical tooling from the Fuse IDE in the mix.
  • Learn more about Camel from the classic book by Claus Ibsen and Jonathan Anstey: Camel in Action (Manning Publications, December 2010 ).