6.
Deploying & Testing the Web Service
JAX-WS is part of the Java EE 5 specification, if you are
deploying your project to a full Java EE 5-compliant server, you
should be ready to deploy your project right now without any
further changes to the libraries. However, there are some common
servers, like Jetty or Tomcat, that do not implement the entire
Java EE 5 spec and will need the JAX-WS libraries deployed with
your project in order to run.
IMPORTANT: In
MyEclipse we have tried to make this process easier by including
the JAX-WS RI (Metro 1.1) with our embedded MyEclipse Tomcat
server, so your web services will run out of the box on MyEclipse
Tomcat, but if you plan to deploy to an external server that does
not provide the JAX-WS libraries, you will need to follow the
steps below on how to augment your build path to include them (so
they are deployed). You can also install the JAX-WS libraries
directly into your application server's /lib directory ususally
if you don't want to add the libraries directly to your project;
please check your Application Server's documentation for more
information regarding that.
If you do want to add the libraries to your project build path,
please keep reading section 6.1, otherwise skip to section 6.2.
6.1
Adding JAX-WS Libraries to Your Build Path
First thing we need to do is open our project's
Java Build Path >
Libraries preference page by right-clicking on our
project, and going to
Properties, from there we want to click the
Libraries button:
Now you want to click
MyEclipse Libraries and hit
Next, then scroll down and select both the JAX-WS
library containers to be added to your project's build path:
So we end up wth something like the following:
Now we have the JAX-WS libraries in our project's build path, and
they will be deployed along with our project to MyEclipse Tomcat.
6.2
Deploying and Running the JAX-WS Web
Service
The fastest way to deploy our web service is to deploy our web
project using the
Run As or
Debug As action of
MyEclipse Server Application. We can do that by
right-clicking on our project, going down to
Debug As (or
Run As) and selecting
MyEclipse Server Application:
If you have multiple server connectors configured, MyEclipse will
ask you which one you want to use, for the purpose of this
tutorial select
MyEclipse Tomcat. If you don't have any connectors
configured,
MyEclipse Tomcat will be used automatically for you to
deploy your project to and then run.
Now MyEclipse will perform the following steps for you
automatically:
-
Package our web project, and deploy it in
Exploded format to the application server
-
Start the application server for us, loading our web project
The MyEclipse Web Browser will popup and show you the default
index.jsp page of our web app, we don't actually need
this because we aren't testing a web page, so you can close this
view.
6.3
Testing our JAX-WS Web Service
Now we are ready to connect to the web service and test it out.
The first thing we need to do is load the
Web Services Explorer from the toolbar by
clicking it's button:
After the
Web Services Explorer is loaded, we want to
click on the WSDL mode button, then click on
WSDL Main to open the
Open WSDL screen. Then we want to enter the URL
for our web service WSDL which is:
http://localhost:8080/WebServiceProject/CalculatorPort?WSDL
We can break the URL down into the following components to
understand how we arrived at that URL:
-
http://localhost:8080 = We know the server is
running on localhost, and we know the default Tomcat port is
8080.
-
/WebServiceProject = We know by default the
Web Context-root that is used to deploy web
projects matches the name of the projects. Since we didn't
customize our
Web Context-root for this project, it will be
the same name as our project name.
-
/CalculatorPort = As we saw from the last
screenshot in
Section #5, when our JAX-WS web
service was generated, it was bound using a
servlet-mapping in the
web.xml file to the /CalculatorPort path.
-
?WSDL = This is a universal query string
argument that can be added to the end of any web service which
will tell the web service to return it's full WSDL to the
caller. In this case, the WSDL is returned to our
Web Services Explorer tool which loads it up,
and displays the web services exposed operations to us.
Now the
Web Services Explorer will load up all the
operations exposed to us from this web service and display them
to us:
For the purposes of testing this web service, we can click one of
the operations to use the explorer to test them. Let's click the
add operation.
Now we are shown the
Invoke a WSDL Operation screen. We are shown the
endpoint we are going to test (
Calculator) and each argument the operation takes along
with a field to enter values for each operation.
Enter the values "10" and "20" to add, then
click
Go:
After clicking
Go, down in the
Status view you'll see the response from the web
service, which in this case was "30", and is correct.
Now that we tested our web service, and it works, let's close the
Web Services Explorer and move onto the next
step... creating a web service client!
|