JAX-WS specifies a detailed mapping from a service defined in WSDL to the Java classes that will implement that service. The logical interface, defined by the wsdl:portType
element, is mapped to a service endpoint interface (SEI). Any complex types defined in the WSDL are mapped into Java classes following the mapping defined by the Java Architecture for XML Binding (JAXB) specification. The endpoint defined by the wsdl:service
element is also generated into a Java class that is used by consumers to access endpoints implementing the service.
The wsdl2java command automates the generation of this code. It also provides options for generating starting point code for your implementation and an ant based makefile to build the application. wsdl2java provides a number of arguments for controlling the generated code.
You can generate the code needed to develop your service using the following command:
wsdl2java -ant -impl -server -d outputDir
myService.wsdl
The command does the following:
The -ant
argument generates a Ant makefile, called build.xml
, for your application.
The -impl
argument generates a shell implementation class for each wsdl:portType
element in the WSDL contract.
The -server
argument generates a simple main()
to launch your service as a stand alone application.
The -d
argument tells wsdl2java to write the generated code to a directory called outputDir
outputDir
.
myService.wsdl
is the WSDL contract from which code is generated.
For a complete list of the arguments for wsdl2java see wsdl2java in Celtix Enterprise Command Reference.
Table 4.1, “Generated Classes for a Service” describes the files generated for creating a service.
Table 4.1. Generated Classes for a Service
File | Description |
---|---|
|
The SEI. This file contains the interface your service implements. You should not edit this file. |
|
The endpoint. This file contains the Java class your clients will use to make requests on the service. |
|
The skeleton implementation class. You will modify this file to implement your service. |
|
A basic server mainline that allows you to deploy your service as a stand alone process. For more information see Chapter 6, Publishing a Service. |
In addition, wsdl2java will generate Java classes for all of the types defined in the WSDL contract.
The generated code is placed into packages based on the namespaces used in the WSDL contract. The classes generated to support the service (based on the wsdl:portType
element, the wsdl:service
element, and the wsdl:port
element) are placed in a package based on the target namespace of the WSDL contract. The classes generated to implement the types defined in the types
element of the contract are placed in a package based on the targetNamespace
attribute of the types
element.
The mapping algorithm is as follows:
The leading http://
or urn://
are stripped off the namespace.
If the first string in the namespace is a valid Internet domain, for example it ends in .com
or .gov
, the leading www.
is stripped off the string, and the two remaining components are flipped.
If the final string in the namespace ends with a file extension of the pattern .xxx
or .xx
, the extension is stripped.
The remaining strings in the namespace are appended to the resulting string and separated by dots.
All letters are made lowercase.