JBoss.orgCommunity Documentation

JBoss SOAP Web Services User Guide

Version: 3.3.0.M5


1. JBoss SOAP Web Services Runtime and Tools support Overview
1.1. Key Features of JBossWS
2. Creating a Simple Web Service
2.1. Generation
3. Creating a Web Service using JBossWS runtime
3.1. Creating a Dynamic Web project
3.2. Configure JBoss Web Service facet settings
3.3. Creating a Web Service from a WSDL document using JBossWS runtime
3.4. Creating a Web service from a Java bean using JBossWS runtime
4. Creating a Web Service Client from a WSDL Document using JBoss WS
5. JBoss Web Services and the development environment
5.1. Preferences
5.2. Default Server and Runtime
6. Sample Web Service wizards
6.1. Sample Web Service
6.1.1. Generation
6.1.2. Deployment
7. Web Service Test View
7.1. Preliminaries
7.2. Testing a Web Service

JBoss SOAP Web Services is a web service framework developed as a part of the JBoss Application Server. It implements the JAX-WS specification. JAX-WS (Java API for XML Web Services) defines a programming model and run-time architecture for implementing web services in Java, targeted at the Java Platform, Enterprise Edition 5 (Java EE 5).

JBossWS integrates with most current JBoss Application Server releases as well as earlier ones, that did implement the J2EE 1.4 specifications. Even though JAX-RPC, the web service specification for J2EE 1.4, is still supported JBossWS does put a clear focus on JAX-WS.

JBossWS Tools work with the JBossWS Runtime. Users can easily create, deploy and run a Web Service(WSDL based) and a Web Service Client using JBossWS Tool and JBossWS Runtime.

Also JBossWS Tool gives a way to test a web service running on a server.

This chapter describes how to create a simple web service.

A simple web service can be created by using the Simple Web Service wizard as described in Generate a simple web service

Procedure 2.1. Generate a simple web service

  1. Access the New - Select a wizard dialog

    1. Right click on the project name in the Project Explorer view.

    2. Select NewOther.

    3. Expand the Web Services folder and click on the Simple Web Service option.

    Result:

    The New - Select a wizard dialog displays with the selected wizard type highlighted.

    Figure 2.1. The New - Other (Wizard selection) dialog


  2. Access the Simple Web Service dialog

    Click the Next button to proceed.

    Result:

    The Simple Web Service - Project and Web Service Details dialog displays.

    Figure 2.2. Simple Web Service - Project and Web Service Details


  3. Define the service attributes

    Define the project, web service, package and class names according to the options displayed in Table 2.1, “Project and Web Service Details”

    Table 2.1. Project and Web Service Details

    Dialog groupFieldMandatoryInstructionDescription
    Technology yesSelect the technology the Web Service will be based on.A simple web service can be based on either the Web Service Definition Language (WSDL) or RESTful (REST) API. Click the radio button beside the technology your web service should use.
    Dynamic web project yesSelect the project name.The project name will default to the highlighted project in the Project Explorer. A different project can be selected from the drop-down list.
    Service detailsService nameyesEnter the name for the web service.The web service name will be the URL for the service as mapped in the deployment descriptor (web.xml).
     Update web.xmlnoCheckbox is checked by default, but is not mandatory.Leaving this checked will add your new service to the web.xml in your project.
    Add RESTEasy Jars from root runtime directorynoCheck this box to add RESTEasy JARs to the project.This option allows you to add RESTEasy JARs to the project if they appear in the root runtime directory but are not installed in the runtime. While this is not required, it will assist when working with JBoss Application Server 5 and JBoss Enterprse Application Platform 5 web service projects.
    Service implementationPackageyesEnter the package for the web service servlet.The default package is org.jboss.samples.websevices. Select your own package using the ... button.
     ClassyesEnter the name of the web service servlet.The default class name will correspond to the default web service name resulting in an equivalent URL to servlet name mapping in the deployment descriptor (web.xml).
     Application classonly when the JAX-RS technology option is selectedEnter the name of the JAX-RS application class to use.The default application class is MyRESTApplication.Select your own application class using the ... button.

  4. Generate the web service

    Click the Finish button to complete the web service setup.

    Result:

    The web service classes will be generated and the web.xml file updated with the deployment details if the Update web.xml option was selected.

    Figure 2.3. Created Simple Web Service


In this chapter we provide you with the necessary steps to create a Web Service using JBossWS runtime. First you need to create a Dynamic Web project:

If you have already created a new Dynamic Web project and not set the JBoss Web Service facet to the project, the next step is to add JBoss Web Service facet to the project. Right-click on the project, select its Properties and then find Project Facets in the tree-view on the left-side of the project properties dialog. Tick on the check box for JBoss Web Services. You will see what like this:


At the bottom-left of the right-side of the project properties dialog, there is a error link: Further configuration required... . You must click the link to set more information about JBoss Web Service facet.

Click on the Further configuration required... link. In the opened window


Server Supplied JBossWS Runtime: If you have already set a JBoss runtime to the project's target runtime, you may choose Server Supplied JBossWS Runtime and then click Ok to finish the configuration of JBoss Web Service facet.

If the project has no Target Runtime settings, you should check the second radio button and specify a JBossWS runtime from the list. You also can create a new JBossWS runtime, click on the New... button will bring you to another dialog to configure new JBossWS runtime.


See how to configure a new JBossWS runtime in the Chapter 5, JBoss Web Services and the development environment section.

After setting the information about JBoss Web Service facet, for saving the result, you should click the Apply or OK button at the bottom-right of the right-side of the project properties dialog.

In this chapter we provide you with the necessary steps to create a Web Service from a WSDL document using JBossWS runtime.

Make sure that you have already created a dynamic Web project with JBoss Web Service facet installed and set the necessary preferences through the Preference menu.

See how to make it in the Section 3.1, “Creating a Dynamic Web project”, Section 3.2, “Configure JBoss Web Service facet settings” and Chapter 5, JBoss Web Services and the development environment sections.

To create a Web Service using JBossWS runtime select File > New > Other > Web Services > Web Service to run Web Service creation wizard.

Let's get through the wizard step-by-step:


  • Select the stages of Web service development that you want to complete using the slider:

    • Develop: this will develop the WSDL definition and implementation of the Web service. This includes such tasks as creating modules that will contain generated code, WSDL files, deployment descriptors, and Java files when appropriate.

    • Assemble: this ensures the project that will host the Web service or client gets associated to an EAR when required by the target application server.

    • Deploy: this will create the deployment code for the service.

    • Install: this will install and configure the Web module and EARs on the target server.

    • Start: this will start the server once the service has been installed on it. The server-config.wsdd file will be generated.

    • Test: this will provide various options for testing the service, such as using the Web Service Explorer or sample JSPs.

  • Select your server: the default server is displayed. If you want to deploy your service to a different server click the link to specify a different server.

  • Select your runtime: ensure the JBoss WS runtime is selected.

  • Select the service project: the project selected in your workspace is displayed. To select a different project click on the project link. If you are deploying to JBoss Application Server you will also be asked to select the EAR associated with the project. Ensure that the project selected as the Client Web Project is different from the Service Web Project, or the service will be overwritten by the client's generated artifacts.

  • If you want to create a client, select the type of proxy to be generated and repeat the above steps for the client. The better way is to create a web service client project separately.

First, please select Top down Java bean Web Service from the Web Service type list, and select a WSDL document from workspace, click on the Server name link on the page will bring you to another dialog. Here you can specify the server to a JBoss Server and Web Service runtime to JBossWS runtime:


Click on the Finish button to see the next wizard view opened:


Click on the Next button to proceed:


  • WSDL Service : display the services in your WSDL file, you can select one to generate Web Service.

  • Source Folder : display the source codes folder in your web project, you can select one to generate java codes.

  • Package name : input a package name. You can click the Browse button to choose one. If you don't input a package name, system will generate one for you.

  • JAX-WS specificaiton : display the supported JAX-WS version, include, 2.0, 2.1, 2.2

  • Catalog file : specify a catalog file.

  • Binding files : specify some binding files that are used by your WSDL file

  • Enable binding extension support (Only available for JBossWS 3.0 or later) : select it if you need the binding extension support. Only work based on JBossWS 3.0 or later.

  • Generate default Web Service Implementation classes : select it if you want to generate empty implementation classes for the selected WSDL Service.

  • Update the default Web.xml : update the Web.xml file with your Web Service servlets configured.

  • Additional Options : the senior options for the generating process. Only for the senior user.

Click on the Next or on the Finish button to generate code.

Once the Web Service code is generated, you can view the implementation class and add business logic to each method.


View the Web.xml file:


In the next chapter you will find out how to create a Web service from a Java bean.

To create a Web service from a bean using JBoss WS:

Setup Chapter 5, JBoss Web Services and the development environment.

Create Section 3.1, “Creating a Dynamic Web project”.

Note

To use the Simple Web Service wizard to create this Web Service, replace the Class and Application Class fields with your specific classes, within the instructions in Chapter 2, Creating a Simple Web Service.

Section 3.2, “Configure JBoss Web Service facet settings”

Create a Web Service from a java bean:

After the Web Service has been created, the following options may become available depending on the options selected:

In the next chapter you will be able to create a Web Service Client from a WSDL document using JBoss WS.

To create a Web Service Client from a WSDL Document using JBoss WS you need to fulfil the following steps:

Setup Chapter 5, JBoss Web Services and the development environment.

Section 3.1, “Creating a Dynamic Web project”.

Section 3.2, “Configure JBoss Web Service facet settings”.

Then you can create a Web Service Client from a WSDL document:

After the Web Service Client has been created, the following may occur depending on the options you selected:

JBoss WS use a Java class to test Web Service. A client sample class will be generated, you may run this client as a java application to call a web service.

In this chapter you will learn how to change preferences and set the default server runtime.

JBoss Tools includes wizards for the creation of sample web services. These include:

  • Create a Sample Web Service for a JAX-WS web service

This wizard is used within a Dynamic Web project. A dynamic web project can be created by following the steps in Creating a dynamic web project.

Procedure 6.1. Creating a dynamic web project

  1. Access the New Project Dialog

    Select FileNewProject

    Result:

    The New Project screen displays.

  2. Define the Project Type

    1. Click the Dynamic Web Project label by expanding the Web folder.

    2. Click the Next button to proceed.

    Result:

    The New Dynamic Web Project screen displays.

    Figure 6.1. Dynamic Web Project Attributes


  3. Define the Project Attributes

    Define the Dynamic Web Project attributes according to the options displayed in Table 6.1, “New Dynamic Web Project”

    Table 6.1. New Dynamic Web Project

    FieldMandatoryInstructionDescription
    Project nameyesEnter the project name.The project name can be any name defined by the user.
    Project locationyesClick the Use default location checkbox to define the project location as the Eclipse workspace or define a custom path in the Location field.The default location corresponds to the Eclipse workspace.
    Target runtimenoSelect a pre-configured runtime from the available options or configure a new runtime environment.

    The target runtime defines the server to which the application will be deployed.

    Dynamic web module versionyesSelect the required web module version.

    This option adds support for the Java Servlet API with module versions corresponding to J2EE levels as listed in Table 6.2, “New Dynamic Project - Dynamic web module version”.

    ConfigurationyesSelect the project configuration from the available options.

    The project can be based on either a custom or a set of pre-defined configurations as described in Table 6.3, “New Dynamic Project - Configuration”.

    EAR membershipnoAdd the project to an existing EAR project.

    The project can be added to an existing EAR project by selecting the checkbox. Once checked, a new EAR project can be defined by clicking the New Project button.

    Working setsnoAdd the project to an existing working set.

    A working set provides the ability to group projects or project attributes in a customized way to improve access. A new working set can be defined once the Select button has been clicked.




  4. Access the Java sub-dialog

    Click Next to proceed.

    Result:

    The New Dynamic Web Project - Java dialog displays.

  5. Define the source and output folders

    Define the Dynamic Web Project source and output folders by adding or editing folders as required.

  6. Access the Web Module sub-dialog

    Click Next to proceed.

    Result:

    The New Dynamic Web Project - Web Module dialog displays.

    Figure 6.2. New Dynamic Web Project - Web Module


  7. Enter the web module settings

    Define the settings as listed in Table 6.4, “New Dynamic Web Project - Web Module” including the root folder for path names in the web project context and the name of the web content directory.


  8. Open the Java EE perspective.

These sections describe how to generate and deploy a sample web service.

A sample web service can be created by using the Create a Sample Web Service wizard as described in Generate a sample web service

Procedure 6.2. Generate a sample web service

  1. Access the New - Select a wizard dialog

    1. Right click on the project name in the Project Explorer view.

    2. Select NewOther.

    3. Click the Create a Sample Web Service label by expanding the Web Services folder.

    Result:

    The New - Select a wizard dialog displays with the selected wizard type highlighted.

  2. Access the Generate a Sample Web Service dialog

    Click the Next button to proceed.

    Result:

    The Generate a Sample Web Service - Project and Web Service Name dialog displays.

    Figure 6.3. Generate a Sample Web Service - Project and Web Service Name


  3. Define the service attributes

    Define the project, web service, package and class names according to the options displayed in Table 6.5, “Project and Web Service Name”


  4. Generate the web service

    Click the Finish button to complete the web service setup.

    Result:

    The web service classes will be generated and the web.xml file updated with the deployment details.

  5. Browse the HelloWorld.java class

    Double click the HelloWorld.java class and note the annotated class name and method. These annotations identify the web service entities to the server.

    Figure 6.4. web.xml


  6. Browse the web.xml deployment decriptor

    Double click the web.xml file and note the servlet mapping as defined in Figure 6.3, “Generate a Sample Web Service - Project and Web Service Name”. Note also that:

    • the main servlet for the application is org.jboss.samples.webservices.HelloWorld which is given the custom name HelloWorld; and

    • the main servlet is mapped to the particular url /HelloWorld [1].

    Figure 6.5. web.xml


    Upon start up, the server will write a WSDL file to the server-profile/data/wsdl/ directory and the WSDL can be accessed with http://localhost:8080/ProjectName/[1]?WSDL or, http://localhost:8080/WebServiceSample/HelloWorld?WSDL.

Once created, the sample web service can be deployed to the target runtime as described in Export the project as a Web Archive (WAR).

JBoss Tools provides a view to test web services. The Web Services Test View can be displayed by following the steps in Web Services Test View.

Procedure 7.1. Web Services Test View

The following sections describe testing JAX-WS web services.

The following procedure describes the steps to perform before testing a web service.

Procedure 7.2. Testing a web service

A JAX-WS web service can be tested by using the Web Service Tester View displayed in Figure 7.1, “Web Service Test View”. The JAX-WS test is specified by:

  1. Selecting the JAX-WS combobox option.

  2. Entering the location of the WDSL file.

Step 2 can be performed in a number of ways including:

  • entering the location directly in the editable dropdown list; or

  • clicking the Get from WSDL file button and entering the URL, Eclipse workspace or File system details.

Testing a JAX-WS web service demonstrates testing the WebServiceSample project developed in Generate a sample web service.

Procedure 7.3. Testing a JAX-WS web service

  1. Following the preliminary steps described in Testing a web service, select JAX-WS from the available combo box options.

    Result:

    The SOAP message details are displayed in the Request Body textbox of the Request Details panel.

    Figure 7.3. JAX-WS Body Text


  2. Enter the location of the WSDL file in the editable dropdown list. The location for the WebServiceSample web service is http://localhost:8080/WebServiceSample/HelloWorld?WSDL

  3. Click the Invoke button.

    Result:

    The Select WDSL dialog appears.

    Figure 7.4. Select WSDL


  4. Select the required service attributes

    Select the Service, Port and Operation from the comboboxes and click OK.

    Results:

    The <soap:Body/> section of the SOAP message is filled with the SayHello message details.

    Figure 7.5. JBoss Tools Project Creation


    The response header details are returned.

    Figure 7.6. JBoss Tools Project Creation


    The response message body is displayed in the Response Body textbox.

    Figure 7.7. JBoss Tools Project Creation


    These results indicate a successful test.