Create a Web Service from a Java implementation bean using Apache CXF

Prerequisites:

  1. Install and configure the Apache CXF runtime environment. See the Requirements and Installation page for more details.
  2. Create a Dynamic Web Project and enable it for Apache CXF Web services development as described here: Create a project for CXF Web services.
  3. Create or import a Java implementation bean into the source folder of the Dynamic Web Project.
To create a Web service from a Java bean using the Apache CXF runtime environment:
  1. Select Open the Java EE perspectiveWindow > Open Perspective > Java EE from the top level menu to switch to the Java EE perspective.
  2. In the Project Explorer view select the Java implementation bean that you created or imported into the Dynamic Web Projects source folder.
  3. Open the Web Service wizard by selecting Open the new web service wizardFile > New > Other... > Web Services > Web Service from the top level menu.
  4. Web Services page: select Bottom up Java bean Web Service as the Web service type and browse to select the Java implementation bean from which to create the Web service:

    Bottom Up Web Services Wizard

    1. Move the service slider to the stage of Web services development that you wish to complete.
      • Develop: Invokes the Apache CXF java2ws tool using the preference defaults and the information gathered in the wizard to create a service. The wizard also generates a JAX-WS endpoint configuration file.
      • Assemble: If required by the target server this phase assembles and configures the project that hosts the Web service into an EAR.
      • Deploy: Generates the deployment artifacts for the Web service.
      • Install: Installs and configures the Web Module and EARs on the target server.
      • Start: Starts the target server once the Web service has been installed on it.
      • Test: Use the Web Service Explorer to test the generated Web service.
    2. Server: Select a server to deploy your Web service to.
    3. Web service runtime: Select Apache CXF 2.x
    4. Service project: Select the project in your workspace into which Apache CXF will generate the code.
    5. If you wish to generate a client for your Web service, select Java Proxy as the Client type:
      • Move the client slider to the Develop client stage.
      • Client project: Select a different project into which to generate the client code. The wizard will create the project for you if it doesn't exist and configure it with the CXF Facet.
    6. Publish the Web service: Launch the Web Services Explorer to publish your Web service to a UDDI registry.
    7. Monitor the Web service: Monitor the Web service's SOAP traffic using the TCP/IP Monitor.
  5. Click Next > to move to the Service Endpoint Interface configuration page:
    1. Use a Service Endpoint Interface: Select or create a Service Endpoint Interface (SEI) that defines the methods you wish to expose in the service. This is the recommended approach.
      • Select an SEI: Browse to select an existing SEI.
      • Create an SEI: Create an Interface from the Implementation by providing a name and the methods to declare in the extracted interface.
      Both options create or update the @WebService.endpointInterface element on the implementation bean.
  6. Click Next > to move to the JAX-WS annotations configuration page:

    This page allows you add to JAX-WS annotations to the SEI or Implementation (if not using an explicit SEI).

    The JAX-WS annotations element values default to those outlined in the JAX-WS specifications.

    If the Implementation bean / SEI contains overloaded methods the JAX-WS annotations added on this page adjust to resolve those conflicts.

  7. Click Next > to move to the Apache CXF java2ws configuration page which allows you to override the default java2ws preferences:
  8. Test Web Service page. This page will be displayed if the service slider on the first page was set to Test service.

    Select the launch button to test the Web Service with the Web Services Explorer.

  9. Apache CXF JAX-WS client configuration page: This page will be displayed if the client slider on the Web services page was set to Develop client.

    Refer to the Generate a JAX-WS Web Service Client page for information on the options displayed on this page.

  10. Web Service Publication Page: Select whether or not you want to publish this Web service to a UDDI registry. Click Finish

Related tasks

Generate an SEI and a skeleton implementation bean from a WSDL document using Apache CXF
Generate a JAX-WS Web Service Client from a WSDL document using Apache CXF