3.2. Deploy the Apache CXF Example


Overview

This tutorial takes a standard Apache CXF example (the wsdl_first example) and shows you how to deploy it into a Web server, by packaging the application as a WAR. In this example, the Web service is implemented by binding the service to a Java class with the JAX-WS mapping.

Prerequisites

The following prerequisites are needed to build and run this example:
  • Either of the following Web servers are installed:
    • JBoss Web Server, or
    • JBoss Enterprise Application Platform
  • Java version 1.7 or later is installed.
  • Apache Maven 3.0.0 or later is installed.
  • Maven is configured to access the JBoss Fuse repositories, as described in Section 2.1, “Preparing to use Maven”.
  • You have access to the Internet, so that Maven can download dependencies from remote repositories.

Install Apache CXF

To obtain the code for the wsdl_first example, you need to install the Apache CXF kit, apache-cxf-3.0.4.redhat-620133.zip, provided in the extras/ directory of the JBoss Fuse installation.
Install the Apache CXF kit as follows:
  1. Find the Apache CXF kit at the following location:
    InstallDir/extras/apache-cxf-3.0.4.redhat-620133.zip
  2. Using a suitable archive utility on your platform, unzip the apache-cxf-3.0.4.redhat-620133.zip file and extract it to a convenient location, CXFInstallDir.

The wsdl_first example

The wsdl_first example is located under the following sub-directory of the Apache CXF installation:
CXFInstallDir/samples/wsdl_first/

Build and run the example

To build and run the wsdl_first example, perform the following steps:
  1. Using your favorite text editor, open the CustomerService.wsdl file, which can be found in the following location in the wsdl_first project:
    wsdl_first/src/main/resources/CustomerService.wsdl
    Edit the soap:address element in the WSDL contract, removing comments around the element labeled standalone Tomcat deployment and inserting comments around the element labeled embedded deployment. When you are finished editing, the soap:address element should be look as follows:
    <?xml version="1.0" encoding="UTF-8"?>
    ...
    <wsdl:definitions name="CustomerServiceService" targetNamespace="http://customerservice.example.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://customerservice.example.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
      ...
      <wsdl:service name="CustomerServiceService">
        <wsdl:port name="CustomerServicePort" binding="tns:CustomerServiceServiceSoapBinding">
          <!-- embedded deployment -->
          <!--soap:address location="http://localhost:9090/CustomerServicePort"/-->
          <!-- standalone Tomcat deployment -->
     <soap:address location="http://localhost:8080/wsdl_first/services/CustomerServicePort"/>
        </wsdl:port>
      </wsdl:service>
    </wsdl:definitions>
  2. Build the wsdl_first example using Maven. Change directory to the CXFInstallDir/samples/wsdl_first directory, open a command prompt, and enter the following command at the command line:
    mvn clean package
    If this command executes successfully, you should be able to find the WAR file, wsdl_first.war, under the wsdl_first/target sub-directory.
  3. Make sure that the Web server is already running (a simple way to test this is to enter the URL, http://localhost:8080, into your browser). If you need to start the Web server, you can typically do this from the command line. The command to start the Web server depends on the particular product you are using, as follows:
    • JBoss Web Server (WS)—open a new command prompt and execute the startup.sh script from the tomcat8/bin/ directory (or the tomcat7/bin/ directory, as appropriate). For more details about how to configure and launch the WS, see the Installation Guide from the JBoss Web Server library.
    • JBoss Enterprise Application Platform (EAP)—for a standalone instance, open a new command prompt and execute the bin/standalone.sh script. For more details about how to configure and launch the EAP, see the Administration and Configuration Guide from the JBoss Enterprise Application Platform library.
  4. Deploy the wsdl_first example to the running Web server. Manually copy the wsdl_first.war WAR file from the wsdl_first/target directory to the Web server's deployment directory, as follows:
    • JBoss Web Server (WS)—copy the wsdl_first.war WAR file to the tomcat8/webapps directory (or tomcat7/webapps directory, as appropriate).
    • JBoss Enterprise Application Platform (EAP)—copy the wsdl_first.war WAR file to the standalone/deployments directory.
  5. Use a Web browser to query the WSDL contract from the newly deployed Web service. Navigate to the following URL in your browser:
    http://localhost:8080/wsdl_first/services/CustomerServicePort?wsdl
    Note
    This step might not work in the Safari browser.
  6. Run the test client against the deployed Web service. Change directory to the CXFInstallDir/samples/wsdl_first directory, open a command prompt, and enter the following command at the command line:
    mvn -Pclient
    If the client runs successfully, you should see some output like the following in your command window:
    ...
    Sending request for customers named Smith
    Response received
    Did not find any matching customer for name=None
    NoSuchCustomer exception was received as expected
    All calls were successful
Red Hat logoGithubRedditYoutubeTwitter

Learn

Try, buy, & sell

Communities

About Red Hat Documentation

We help Red Hat users innovate and achieve their goals with our products and services with content they can trust.

Making open source more inclusive

Red Hat is committed to replacing problematic language in our code, documentation, and web properties. For more details, see the Red Hat Blog.

About Red Hat

We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.

© 2024 Red Hat, Inc.