Module D314

thumbsshameServers

Nov 17, 2013 (3 years and 8 months ago)

104 views



P a g e
| 1
Creation of web services (David Durand - D314 : Web Services )


Module D314
Creating a web service under Eclipse / Tomcat

tutorial version 2 for Windows



Systems Engineering-Based Services


Download and installation tools

Installation folders
Configuring Eclipse with Tomcat / Axis

Development of a Web Service

Creation of business code
creating the Web Service

Configuring the Web Service

Launching the Web Service
Testing the Web Service with Web Service Explorer

Client Side

Create the main class
Service call







P a g e
| 2
Creation of web services (David Durand - D314 : Web Services )


Deployment of Web Service

Export WAR
configuring the "Apache server" Tomcat standalone.
Checking for service existence
Export the client and final test


Download and installation tools

The realization of this Web Service project is based on the use of three tools:

• the IDE "Eclipse Galileo J2EE" http://eclipse.org/downloads/
The standard version can also be used, but it requires the installation of additional plug-
in.
(Eclipse WTP http://www.eclipse.org/webtools/releases/3.1.1/)

• The application server Apache Tomcat 6.
The current version is available at http://tomcat.apache.org/download-60.cgi (take
the zip version)

• The Web services engine Apache Axis2, version 1.5.1 Release
http://ws.apache.org/axis2/download/1_5_1/download.cgi (grab version "WAR")



Installation folders

After unpacking the downloaded archive, we consider the following working folders:

• c: \ David: directory of "main job"

• c: \ David \ workspace_WS: the folder of "Eclipse projects";

• c: \ David \ apache-tomcat-6.0.20: Tomcat installation folder

• c: \ david \ Axis2-1.5.1: installation folder Axis

These folder names are to be adapted Depending to your system
.




P a g e
| 3
Creation of web services (David Durand - D314 : Web Services )




Configuring Eclipse with Tomcat / Axis

In the window "preferences of Eclipse", configure the server side and Web Services
as at the following figure:


P a g e
| 4
Creation of web services (David Durand - D314 : Web Services )


Development of a "Web Service"

Creation of business code

The "bottom-up" approach consists of starting from an existing code to expose it as
a Web Service. Here we create a simple Java project named LibrairieMath in which we
add a class math.Math:



P a g e
| 5
Creation of web services (David Durand - D314 : Web Services )

Creating the Web Service.

From the class "math. Math" uses the context menu to generate the associated Web
Service. A new project "WS_exemple1_start" will be created:


Configuring the Web Service

The wizard then prompts you to select the methods exposed by the Web Service. In our
example, we have only one method:



P a g e
| 6
Creation of web services (David Durand - D314 : Web Services )




Launching the Web Service

In the next step, the wizard offers to start the Tomcat server configured in Eclipse. it is
possible that your system or your firewall asks for permission to start a program that
listens on a port. After confirmation and closing the wizard, the server "Tomcat" is
started in Eclipse:




P a g e
| 7
Creation of web services (David Durand - D314 : Web Services )




Testing the Web Service with Web Service Explorer

In the generated project, use the context menu of the file Math.wsdl to test the service.
A form is offered to call the add method, passing it parameters.

After submitting the form, the result is displayed in the status window.


P a g e
| 8
Creation of web services (David Durand - D314 : Web Services )



Party Client (Client Side)

Now we create a "separate project", the client code used for the call to service. Still
using the context menu used on Math.wsdl, generate the client as in the figure below,
remembering to specify the project name:




P a g e
| 9
Creation of web services (David Durand - D314 : Web Services )

Create the main class

In the newly created project, add a Java class. In the following code, “Math Service
Locator” is an object linking you to the service math. Math.

It contains among others the address used to locate the service. Its method get Math()
returns a proxy to the service, which will take care to transmit calls.


Service call

Launch the newly created class Main Client. The result of the operation is displayed in
the console. (Ignore the warning messages indicating the absence of certain libraries,
we do not need them)




P a g e
| 10
Creation of web services (David Durand - D314 : Web Services )




Deployment of Web Service


For now, everything has been tested in Eclipse, it is now time to test our service in a
standalone server.

Export WAR

Select the root folder of the Web Service project, and use the menu to Export ... as a
Web Archive. Choose the folder webapps in tomcat to save the archive.



P a g e
| 11
Creation of web services (David Durand - D314 : Web Services )



Configuring the standalone Apache server Tomcat
.

Remember to stop the Tomcat server from Eclipse before the next steps. Set up - if
not already done so - the system environment variable to point to JRE_HOME the
installation folder of your JRE. Tomcat needs this variable to start:


P a g e
| 12
Creation of web services (David Durand - D314 : Web Services )



Checking for service existence


when you start Tomcat, it will automatically load the WAR file found in the webapps
folder. We must be able to test the service directly in the browser, using an address in
the form http://www.localhost:8080/NOM_DU_PROJET/services/Math
It is also possible to directly test the call of a method of our service from the address
bar. This gives the SOAP response containing the result.



P a g e
| 13
Creation of web services (David Durand - D314 : Web Services )


Export the client and final test

In Eclipse, export the project client to obtain an executable JAR. Finally, run the JAR
file obtained to test the service