7.0
JBoss SOAP Web Services User
Guide
Provides information relating to SOAP Web Services for JBoss.
Denny Xu
Ben Clare
Grid Qian
Brian Fitzpatrick
Red Hat JBoss Developer Studio 7.0 JBoss SOAP Web Services User
Guide
Denny Xu
Grid Qian
Brian Fitzpatrick
Ben Clare
Edited by
Isaac Ro o sko v
Legal Notice
Copyright 2011 Red Hat.
T his document is licensed by Red Hat under the Creative Commons Attribution-ShareAlike 3.0 Unported
License. If you distribute this document, or a modified version of it, you must provide attribution to Red
Hat, Inc. and provide a link to the original. If the document is modified, all Red Hat trademarks must be
removed.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section
4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, JBoss, MetaMatrix, Fedora, the Infinity Logo,
and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux is the registered trademark of Linus T orvalds in the United States and other countries.
Java is a registered trademark of Oracle and/or its affiliates.
XFS is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States
and/or other countries.
MySQL is a registered trademark of MySQL AB in the United States, the European Union and other
countries.
Node.js is an official trademark of Joyent. Red Hat Software Collections is not formally related to or
endorsed by the official Joyent Node.js open source or commercial project.
T he OpenStack Word Mark and OpenStack Logo are either registered trademarks/service marks or
trademarks/service marks of the OpenStack Foundation, in the United States and other countries and
are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or
sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
Abstract
T he JBoss SOAP Web Services User Guide explains how to use the JBoss Web Services module to
implement SOAP web services in Java.
Table of Contents
Table of Contents
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3. . . . . . . . . .
Preface
.Chapter
. . . . . . . . 1.
. . .JBoss
. . . . . . .SOAP
. . . . . . Web
. . . . . Services
. . . . . . . . . .Runtime
. . . . . . . . .and
. . . . T. .ools
. . . . support
. . . . . . . . .Overview
. . . . . . . . . . . . . . . . . . . . . . . .4. . . . . . . . . .
1.1. Key Features of JBossWS
4
.Chapter
. . . . . . . . 2.
. . .Creating
.........a
. . Simple
. . . . . . . .Web
. . . . .Service
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5. . . . . . . . . .
2.1. Generation
5
.Chapter
. . . . . . . . 3.
. . .Creating
. . . . . . . . . a. . Web
. . . . . Service
. . . . . . . . using
. . . . . . .JBossWS
. . . . . . . . . .runtime
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9. . . . . . . . . .
3.1. Creating a Dynamic Web project
9
3.2. Configure JBoss Web Service facet settings
11
3.3. Creating a Web Service from a WSDL document using JBossWS runtime
14
3.4. Creating a Web service from a Java bean using JBossWS runtime
21
.........4
Chapter
. ...Creating
. . . . . . . . . .a. Web
. . . . . Service
. . . . . . . . .Client
. . . . . . from
. . . . . .a. WSDL
. . . . . . . Document
. . . . . . . . . . . using
. . . . . . JBoss
. . . . . . . WS
. . . . . . . . . 27
............
.Chapter
. . . . . . . . 5.
. . .JBoss
. . . . . . .Web
. . . . .Services
. . . . . . . . . and
. . . . .the
. . . .development
. . . . . . . . . . . . . environment
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .31
...........
5.1. Preferences
31
5.2. Default Server and Runtime
34
.Chapter
. . . . . . . . 6.
. . .Sample
. . . . . . . .Web
. . . . .Service
. . . . . . . . wizards
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .36
...........
6.1. Sample Web Service
41
6.1.1. Generation
41
6.1.2. Deployment
43
.Chapter
. . . . . . . . 7.
. . .Web
. . . . .Service
. . . . . . . . T. .est
. . . View
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4. .6. . . . . . . . . .
7.1. Preliminaries
48
7.2. T esting a Web Service
48
.Getting
. . . . . . . .Help
. . . . .and
. . . . Giving
. . . . . . . .Feedback
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
............
A.1. Do You Need Help?
51
A.2. Give us Feedback
51
. . . . . . . . . .History
Revision
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
............
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Preface
Preface
T his manual uses several conventions to highlight certain words and phrases and draw attention to
specific pieces of information. T o get more information on these conventions please refer to the
Docum ent Conventions manual, which can be found on the Red Hat Documentation website under
the JBoss Developer Studio section.
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Benefit
JBoss AS
2.1. Generation
A simple web service can be created by using the Sim ple Web Service wizard as described in
Procedure 2.1, Generate a simple web service
Procedure 2.1. Generate a simple web service
1. Access the New - Select a wizard dialog
a. Right click on the project name in the Project Explorer view.
b. Select New Other.
c. Expand the Web Services folder and click on the Simple Web Service option.
Result:
T he New - Select a wizard dialog displays with the selected wizard type highlighted.
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Figure 2.2. Simple Web Service - Project and Web Service Details
Mand
atory
Instruction
Description
T echnology
yes
Dynamic web
project
yes
Servic
e
name
yes
Updat
e
web.x
ml
no
Checkbox is checked by
default, but is not
mandatory.
Add
REST
Easy
Jars
from
root
runtim
e
directo
ry
no
Packa
ge
yes
T he default package is
org.jboss.sam ples.websev
ices. Select your own package
using the ... button.
Class
yes
Applic
ation
class
only
when
the
JAXRS
techno
logy
option
Service details
Service
implementation
Field
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
is
select
ed
4. Generate the web service
Click the Finish button to complete the web service setup.
Result:
T he web service classes will be generated and the web.xm l file updated with the deployment
details if the Update web.xm l option was selected.
Create a Web project by selecting New > Project... > Dynamic Web project. Enter the following
information:
Project Name: enter a project name
T arget runtime: any server depending on your installation. If it is not listed, click New button and
browse to the location where it is installed to. You may set Target Runtime to None, in this case, you
should read the section Section 3.2, Configure JBoss Web Service facet settings.
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Configuration: You may Section 3.2, Configure JBoss Web Service facet settings by clicking the
Modify... button. T he opened page is like Figure 3.4.
Configure Web Module values:
10
If you added the JBoss Web Service facet to the project, now the Finish button is unavailable. You must
click Next button to set more information about the JBoss Web Service facet. T he page is like Figure 3.5.
T hen click on the Finish button.
If you didn't add the JBoss Web Service facet to the project, click on the Finish button. Next you will need
to add JBoss Web Service facet to the project.
11
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
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
12
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.
13
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
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.
14
T o 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. T his
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
15
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
16
Click on the Finish button to see the next wizard view opened:
17
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
18
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
19
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
20
In the next chapter you will find out how to create a Web service from a Java bean.
Note
T o use the Sim ple 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:
Switch to the Java EE perspective Window Open Perspective Java EE.
In the Project Explorer view, select the bean that you created or imported into the source folder of
your Web project.
21
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Click File New Other. Select Web Services in order to display various Web service wizards.
Select the Web Service wizard. Click on the Next button.
On the first Web Service wizard page: select Bottom up Java bean Web service as your Web service
type, and select the Java bean from which the service will be created:
22
23
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Generate WSDL file: select it, you will get a generated WSDL file in your project. But this wsdl's
service address location values are not a real address.
After the Web service has been created, the following option can become available depending on
the options you selected: Update the default web.xml file. If selected, you may test the web service
by Explorer.
Click on the Next button.
On this page, the project is deployed to the server. You can start the server and test the web service.
If you want to publish the web service to a UDDI registry, you may click the Next button to publish it. If
not, you may click the Finish button.
24
After the Web Service has been created, the following options may become available depending on the
options selected:
the generated web services code
If you selected to generate a WSDL file, you will get the file in your project's wsdl folder.
If you selected to update the default web.xml, you will test the web service in the browser. Open the
Explorer, input the url for the web service according to web.xml plus ?wsdl, you will get the WSDL file
from Explorer.
25
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
In the next chapter you will be able to create a Web Service Client from a WSDL document using JBoss
WS.
26
Chapter 4. Creating a Web Service Client from a WSD L D ocument using JBoss WS
T he first and the second Web Service Client wizard pages are the same as for Section 3.3, Creating
a Web Service from a WSDL document using JBossWS runtime.
27
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
28
Chapter 4. Creating a Web Service Client from a WSD L D ocument using JBoss WS
29
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
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.
Note:
T o run client sample as a Java application you need a JBoss Runtime in build path.
30
5.1. Preferences
In this section you will know how JBoss Web Services preferences can be modified during the
development process.
T o navigate to the preferences page click on Window Preferences JBoss T ools Web
Services JBossWS Preferences
On this page you can manage the JBoss Web Services Runtime. Use the appropriate buttons to Add
more runtimes or to Remove those that are not needed.
Clicking on the Add or Edit button will open the form where you can configure a new JBossWS runtime
and change the JBossWS runtime path and modify the name and version of the existing JBossWS
runtime settings. Click Finish to apply the changes.
31
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
WS container allows Source and Javadoc locations to be set via the Properties dialog on each contained
JAR: right-click on any JAR file in the Project Explorer view, select Properties. Choose Java Source
Attachm ent and select the location (folder, JAR or Z IP) containing new source for the chosen JAR
using one of the suggested options (workspace, external folder or file), or enter the path manually.
32
33
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Note
For ease of use, set the runtime to JBoss WS.
After the server and runtime are specified, click on the Apply button to save the values.
34
35
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
36
37
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Mandato
ry
Instruction
Description
Project
name
yes
Project
location
yes
T arget
runtime
no
Dynamic
web
module
version
yes
Configura
tion
yes
EAR
members
hip
no
Working
sets
no
38
Option
Description
2.2
2.3
2.4
2.5
Description
<custom>
Configures a project with CXF using Web Module v2.5 and Java
v5.0.
Minimal Configuration
39
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Mandato
ry
Instruction
Description
Context
root
yes
Content
directory
yes
Generate
web.xml
deployme
nt
descriptor
no
40
6.1.1. Generation
A sample web service can be created by using the Create a Sam ple Web Service wizard as
described in Procedure 6.2, Generate a sample web service
Procedure 6.2. Generate a sample web service
1. Access the New - Select a wizard dialog
a. Right click on the project name in the Project Explorer view.
b. Select New Other.
c. Click the Create a Sam ple Web Service label by expanding the Web Services
folder.
Result:
T he 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:
T he Generate a Sam ple Web Service - Project and Web Service Nam e dialog
displays.
Figure 6.3. Generate a Sample Web Service - Project and Web Service Name
41
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Field
Dynamic Web
Project
Mand
atory
Instruction
Description
yes
Web Service
Name
yes
Sample Web
Service Class
Packa
ge
yes
Class
yes
42
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.
6.1.2. Deployment
Once created, the sample web service can be deployed to the target runtime as described in
43
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
44
Manda
tory
Instruction
Description
Web project
yes
Destination
yes
Optimize for a
specific server
runtime
no
45
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Note
You can also access this view by right-clicking on a WSDL file of a project in the Project
Explorer and selecting Web Services T est in JBoss Web Service T ester from the
context menu. T his will open the Web Service T ester with the details of the selected
WSDL file.
T he main components of the Web Service T ester View are:
WSDL path/button bar (T able 7.1, WSDL path/button bar)
Request details panel (T able 7.2, Request details panel)
Response details panel (T able 7.3, Response details panel)
46
Description
Combo box
Select the type of service to test. T he options are JAX-WS or any other
option to test a JAX-RS service using HT T P request methods (PUT ,
GET , POST , DELET E or OPT IONS).
Click this button to display the Select WSDL dialog. Enter the URL,
File system location or Eclipse Workspace location of the WSDL file.
Given a valid file, the dialog will allow selection of the Port and
Operation to test. Once selected, the request details will be displayed
in the Request Details panel.
Once the WSDL file has been selected, the service can be invoked by
clicking this button. Response details will be displayed in the Response
Details panel.
Description
Select this check box to send a username and password with the
request. Entering the user details for each subsequent request is not
necessary as the details are stored in memory.
Headers
Enter (Add) one or more nam e=value pairs. T hese headers will be
passed with the invocation request at the HT T P level where possible.
Parameters
Body
Enter the JAX-WS SOAP request messages or input for JAX-RS service
invocations in this text box.
Description
Response headers
Response body
Parameters
Body
Enter JAX-WS SOAP request messages and input for JAX-RS service
invocations in this text box.
47
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
7.1. Preliminaries
T he following procedure describes the steps to perform before testing a web service.
Procedure 7.2. T esting a web service
Preliminary steps
Prior to testing a web service:
1. T he Web Service T est View should be opened as described in Procedure 7.1, Web
Services T est View;
Result:
T he Web Service T est View displays.
2. A web service has been deployed to the deploy directory of the chosen server profile.
3. T he server has been started with run.sh -c <profile>
48
1. Following the preliminary steps described in Procedure 7.2, T esting a web service, select JAXWS from the available combo box options.
Result:
T he SOAP message details are displayed in the Request Body textbox of the Request
Details panel.
2. Enter the location of the WSDL file in the editable dropdown list. T he location for the
WebServiceSample web service is http://localhost:8080/WebServiceSample/HelloWorld?WSDL
3. Click the Invoke button.
Result:
T he Select WDSL dialog appears.
49
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Select the Service, Port and Operation from the comboboxes and click OK.
Results:
T he <soap:Body/> section of the SOAP message is filled with the SayHello message details.
50
Additional information:
Be sure to give us your name so that you can receive full credit for reporting the issue.
51
Red Hat JBoss D eveloper Studio 7.0 JBoss SOAP Web Services User Guide
Revision History
Revision 7.0.0-1.4 00
Rebuild with publican 4.0.0
2013-10-31
Rdiger Landmann
Revision 7.0.0-1
Released for 7.0.0
Michelle Murray
52