Java Reference
In-Depth Information
Now run the
wsimport
tool to create a proxy so you can invoke the service. Here is the com-
mand and the output:
>wsimport -d /home/ehewitt/soacookbook/code/imported -target 2.1 \
-verbose http://localhost:4933/CalculatorApp/
CalculatorWSService?wsdl
parsing WSDL...
generating code...
org\me\calculator\Add.java
org\me\calculator\AddResponse.java
org\me\calculator\CalculatorWS.java
org\me\calculator\CalculatorWSService.java
org\me\calculator\ObjectFactory.java
org\me\calculator\package-info.java
compiling code...
javac -d /home/ehewitt/soacookbook/code/imported -classpath //...
>
The
wsimport
tool has a variety of options, many of which have to do with customization. But
in the basic invocation, you pass the tool the options you want and the final argument is the
location of the WSDL. The first option,
-d
, indicates the directory where you want the impor-
ted source code to be written. The
-target
option is used to specify the version of JAX-WS
you want to be compatible with (2.0 is the default), and the
-verbose
option tells the tool to
indicate the work it is doing as it does it. Let's look at what the tool generated for you.
First it generated a set of packages that correspond to the namespace of the service, which in
this example is
org.me.calculator
. Inside the package is a set of Java classes. We will dis-
cuss the key Java classes the tool generated below.
NOTE
If you want to have
wsimport
retain the Java source files it generates in addition to the class files,
use the
-keep
option.
The generated Service class
In this example, the
Service
class is called
CalculatorWSService.java
, which corresponds
to the value of the
name
attribute of the WSDL
<service>
element. The generated
Service
class allows you to:
▪ Get available ports (service endpoint interfaces)