LDSTechForumProjects

Web Services with Apache CXF - Part 2

Training Date: 14 Sept 2011

JAXB and WSDL to Java

Presentation

Download the training slides.


Video Presentation 1

Get Adobe Flash player

Lab 1: Modeling Data with JAXB

Objective:

  • Use JAXB annotations to make a music playlist usable to a web service.

Before you begin:

  • Download the lab, unzip it, and import it into your IDE as a Maven project.

Steps:

  1. Open your project to the package org.lds.tech.training.cxf.lab1
  2. Open Song.java and do the following:
    • import the package javax.xml.bind.*
    • Create a public, no-arg constructor
    • Annotate title and artist with @XmlAttribute
    • Annotate releaseDate with @XmlAttribute(name="release-date")
    • Annotate genres with @XmlElement(name="genre")
  3. Open SongCollection and do the following:
    • import the package javax.xml.bind.*
    • Create a public, no-arg constructor
    • Annotate the class with @XmlRootElement(name="song-collection")
    • Annotate name with @XmlElement
    • Annotate playList with @XmlElementWrapper(name="play-list") and @XmlElement(name="song")
  4. Under the src/test/java folder open the unit test org.lds.tech.cxf.lab1.Lab1Test
    • import the package javax.xml.bind.*
    • Follow the instructions in each of the comments.
  5. Run the unit test through your IDE or by running a Maven build.

Video Presentation 2

Get Adobe Flash player

Video Presentation 3

Get Adobe Flash player

Lab 2: Consuming a 3rd-party Web Service using Wsdl2Java

Objective:

  • Use the CXF WSDL to Java to Java tool to consume a third-party web service.

Before you begin:

  • Note: If using the LDSTech IDE, it is recommended that you do not use the beta.
  • Download the lab, unzip it, and import it into your IDE as a Maven project.

Steps:

  • Copy the following plugin configuration into the project's pom.xml
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <executions>
                    <execution>
                        <id>wsdl2java</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                        <configuration>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>http://www.webservicex.net/geoipservice.asmx?wsdl</wsdl>
                                </wsdlOption>
                            </wsdlOptions>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
  • Run a Maven build to ensure the Java web service client sources get generated.
    • After running a Maven build, you can view the generated sources by going to target/generated-sources
  • Under src/main/test, go to the unit test org.lds.tech.training.cxf.lab2.Lab2Test
    • Import the package net.webservicex.*
    • Add the following implementation to the testClient method:
		GeoIPService service = new GeoIPService();
		GeoIPServiceSoap soap = service.getGeoIPServiceSoap12();
		GeoIP info = soap.getGeoIP("216.49.176.33"); // from pinging www.lds.org
		System.out.println("-------------------------------------");
		System.out.println("WEB SERVICE RESULTS");
		System.out.println("-------------------------------------");
		System.out.println("Result:       " + info.getReturnCode());
		System.out.println("IP Address:   " + info.getIP());
		System.out.println("Country Code: " + info.getCountryCode());
		System.out.println("Country Name: " + info.getCountryName());
  • Run the unit test through your IDE or by running a Maven build.

Video Presentation 4

Get Adobe Flash player

Video Presentation 5

Get Adobe Flash player

Want to learn more?

See Java Stack Training | LDS Java Stack

This page was last modified on 10 February 2012, at 11:40.

Note: Content found in this wiki may not always reflect official Church information. See Terms of Use.