JAX-WS specifies a detailed mapping from a service defined in WSDL to the Java classes that will implement that service as a service
provider. 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 service providers implementing the service.
The cxf-codegen-plugin Maven plug-in generates this code. It also provides
options for generating starting point code for your implementation. The code generator provides a number of
options for controlling the generated code.
Example 4.1 shows how to use the code generator to generate starting point code for a service.
Example 4.1. Service Code Generation
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>outputDir</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>wsdl</wsdl>
<extraargs>
<extraarg>-server</extraarg>
<extraarg>-impl</extraarg>
</extraargs>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>This does the following:
The
-imploption generates a shell implementation class for eachwsdl:portTypeelement in the WSDL contract.The
-serveroption generates a simplemain()to run your service provider as a stand alone application.The
sourceRootspecifies that the generated code is written to a directory calledoutputDir.wsdlelement specifies the WSDL contract from which code is generated.
For a complete list of the options for the code generator see cxf-codegen-plugin.
Table 4.1 describes the files generated for creating a service provider.
Table 4.1. Generated Classes for a Service Provider
| File | Description |
|---|---|
| The SEI. This file contains the interface your service provider implements. You should not edit this file. |
| The endpoint. This file contains the Java class consumers use to make requests on the service. |
| The skeleton implementation class. Modify this file to build your service provider. |
| A basic server mainline that allows you to deploy your service provider as a stand alone process. For more information see Publishing a Service. |
In addition, the code generator 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://orurn://are stripped off the namespace.If the first string in the namespace is a valid Internet domain, for example it ends in
.comor.gov, then the leadingwww.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
.xxxor.xx, then 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.








