Chapter 8. Use web services

There are several possibilites to access web services from Java. The easiest way is to generate a client stub directly from the wsdl description. This stub represents the web service on the client side. You can use this stub exactly like every other java class, the fact that a web service is working behind the scenes is not noticeable[4]. The Axis framework comes with the tool called „WSDL2Java“ for generating those stubs. Since direct calling is nevertheless rather pedantic, we let that to the Lomboz plugin:

Figure 8.1.  Call the web service wizards of Lomboz

You can either read the wsdl file from the filesystem and save the file with the browser. Or you can alternatively use the url http://localhost:8080/axis/services/Version?wsdl directly:

Figure 8.2.  web service wizard in lomboz

If you check „create Unittest“, Lomboz will also generate a unit test testing the web service. This is a simple way to show how to use the generated classes. The test class requires junit.jar to be added to the project libraries because it makes use of it.

Subsequently there are four new source files in the indicated package, that together enable the access to the „version“ web service:

The fifth file is the test case, which is calling the web service. To run this test case, select the resource and choose „Run / Run as ... / JUnit TestCase“ from the menu bar.


[4] This is not completely correct, since by the remote procedure call certain exceptions cannot be avoided.