Documentos de Académico
Documentos de Profesional
Documentos de Cultura
In this demo we will make a Calculator JAX-WS service in Eclipse. I will make two
Java projects in Eclipse: one for the service and one for the client.
This demo is separated in three parts:
1. Create a Service
2. Test your service http://localhost:8080/WS/Calculator?wsdl
3. Create a Client
4. Monitoring the exchange of SOAP messages between the client and the
service
2.
3.
@WebService
public interface Calculator {
@WebMethod
Maja Pesic
}
SOA week 1 SOAP demo
Maja Pesic
So, the problem is how to import all necessary interfaces (and maybe also some
classes) from the Service to your client project.
There are two ways to do this:
A. Include services interfaces and classes in your client project as an external
library (i.e., as a JAR file), which contains interfaces and classes that are
needed for communication with the service. If you include this library in
your client project, you can use librarys interfaces and classes to call the
methods of the service. This approach assumes that the service provider
made such a library and is willing to give it to you. For example, service
provider can put such a jar file on a website, so that you can download it.
In the sections below, this approach is described as Creating a Client with
the services library.
B. Sometimes the service provider does not offer a jar library. In that case,
you must only rely on the wsdl file , because this file is always available
Maja Pesic
Luckily, Java provides a simple tool called wsimport (find it in the BIN folder
of your JDK installation). When you call the wsimport tool you must give it
the URL of the wsdl (http://localhost:8080/WS/Calculator?wsdl) , and this
tool will automatically create several classes and interfaces for you based
in the wsdl file. You can use these interfaces and classes to call the
methods of the service (the two lines of code shown above). In the sections
below, this approach is described as Creating a Client with the wsimport
tool.
Create a new folder in the Client project root called lib (next to the src
and bin). You will put the library (as a .jar file) in this folder.
Now go to your Service project to create the .jar file (the library). Select
interfaces (and classes) you want to put in the library and go to Export.
Choose, Java -> JAR file. Choose the name of the jar file (e.g.
CalculatorService.jar), browse to the location of your lib folder in the
client project and let Eclipse create the jar file there.
Now you have to add the reference to CalculatorService.jar in your
Client project. Choose Properties-> Java Build Path -> Libraries ->
Add External JARs and add the jar from the lib folder.
Maja Pesic
The calculator service uses only standard types (int). Sometimes the service
methods will use complex types as parameters or return values. For example, the
service could have a method Person findPerson(int personID). Class Person is
made in the Service project. In this case, you will have to select both the service
interface and class Peron while creating the jar file in the Service project (second
step).
First publish (start up) your service. The wsimport tool will request the wsdl
file from the service, so the service must be up and running.
In order to be able to execute the wsdimport tool from anywhere on your hard
disc, you must add this tool to the PATH My Computer-> Properties ->
Advanced System Settings->Environment Variables -> System
variables. Find variable Path and add the path to your wsimpirt tool ad the
end of the existing path (do not remove existing applications from the
Path!!!). For example, add ;c:\Program Files\Java\jdk1.7.0_67\bin\ to the
existing Path.
to see/edit the content of the .bat file > Open with Text editor
to execute the .bat file > Open with System editor.
Once you execute the wsimport tool, you can see that several classes and
interfaces are added to your client project (make sure to first Refresh the
project!).
Maja Pesic
Maja Pesic
service
client
8080
Eclipse has a tool for monitoring exchanging text messages on a specific port: the
TCP/IP Monitor tool. You can use this tool to see the SOAP messages that are
exchanged between the service and the client. If your client sends all its requests
to the port of the TCP/IP Monitor, then this tool will:
1.
2.
3.
4.
service
8080
9000
TCP/IP Monitor
Maja Pesic
client
This tool can be found in Eclipse menu Window -> Show View > Debug
-> TCP/IP Monitor. The right view should be shown at the bottom of your
Eclipse screen (next to Console, Problems, Debug, etc.).
You will have to add a new monitor for your service by clicking on the
Properties in the pop-up menu. First you should setup the port of the monitor,
and then the host and port of the service. Also, it is important to change the
client the client should no longer send its request to the service port (8080), but
to the monitor (9000).
Maja Pesic