Web Services with Apache CXF - Part 1

Training Date: 17 Aug 2011


At the end of this presentation, the participant will be able to:

  • Describe the role of Apache CXF as a framework for building and consuming web services.
  • Identify the basic characteristics of a SOAP web service.
  • Identify the terms used to describe the various components of a SOAP web service.
  • Describe the advantages and disadvantages of SOAP over other web service protocols, namely REST.
  • Be able to produce a SOAP web service with Apache CXF in a Java Stack web application.
  • Be able to consume a SOAP web service with Apache CXF from a Java Stack QA module.
  • Be able to identify the purpose and components of a SOAP web service's WSDL document.

Slide Deck



Video Presentation

Get Adobe Flash player


Video Presentation

Get Adobe Flash player

Lab 1: An Example JAX-WS SOAP Web Service

  1. Launch the Java Stack Starter
  2. Choose the Web Service Provider project type.
  3. Enter the following settings:
    • Project Name:
    • Package Name: 
    • Project Location:
       C:\Dev\Workspace\Training  (or anywhere you want)
  4. Click Next
  5. Select the Security property group and uncheck Use LDS Account Authentication.
  6. Select the Service Layer property group and choose Embedded as the database platform.
  7. Select the Web Services property group and choose SOAP as the CXF web service type.
  8. Click Next and Build
  9. Import the training-cxf project into your IDE as a Maven project. (Also ensure that you import all child projects: training-cxf-api, training-cxf-deploy, training-cxf-qa, and training-cxf-web)
    1. To do this in the LDSTech IDE Go to File->Import->Maven->Existing Maven Project
    2. Choose the folder that stack starter just created for you
  10. Add the training-cxf-web project to an LDSTech (Tomcat 6) web server and run it.
  11. Browse to the web service WSDL: http://localhost/training-cxf/Services/example?wsdl
  12. Note that the web service endpoint address is: http://localhost/training-cxf/Services/example without the ?wsdl query string.
  13. Locate all 3 web service operations in the WSDL
    • Observe how parameter types are defined in the XML.
    • Observe how the result is defined in the XML.
  14. Compare the WSDL to the SEI in the training-cxf-api module:

Video Presentation

Get Adobe Flash player

Namespace Handlers

Video Presentation

Get Adobe Flash player

Lab 2: Producing a JAX-WS SOAP Web Service

  1. Define a new service endpoint interface (SEI) in the training-cxf-api module:
    • Paste the following:

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebService;

public interface HelloWebService {

	public String hello(@WebParam(name="name") String name);
  1. Create a web service implementation class in training-cxf-web:
    • Paste the following:

import javax.jws.WebService;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

public class HelloWebServiceSoapImpl implements HelloWebService {

	public String hello(String name) {
		return "Oh, I wish I were a little bar of " + name + "!";
  1. Paste the following into your WEB-INF/training-cxf-servlet.xml Spring configuration:
<stack-ws:produce implementor="helloWebServiceSoap" secured="false" address="/hello"/>
  1. Rebuild and restart the web application.
  2. Browse to the web service WSDL: http://localhost/training-cxf/Services/hello?wsdl

Lab 3: Consuming a JAX-WS SOAP Web Service

  • Create an integration test in the QA module:
  • Paste the following:

import javax.inject.Inject;
import javax.inject.Named;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
import org.testng.annotations.Test;

public class HelloServiceSoapIT extends AbstractTestNGSpringContextTests  {

	private HelloWebService helloWebService;

	public void testCreateExample() {
  • Paste the following into the QA module's META-INF/spring/
    <stack-ws:consume id="helloWebServiceSoap"
    	endpoint="http://localhost/training-cxf/Services/hello" />
  1. Paste the following into the QA module's testenv/ resource file.
    • helloSoapEndpointUrl = ${appUrl}/Services/hello

Want to learn more?

See Java Stack Training | LDS Java Stack

This page was last modified on 12 July 2013, at 18:30.

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