WSDL2Java  Locate

Overview  Locate

WSDL2Java translates a WSDL definition of a Web service's interface into a Java class. Customizing the process is done most simply through the input parameters. Alternatively, you can write a custom WSDL2Java plug-in. For example, a plug-in could handle advanced XML Schema constructs such as choice.

WSDL2Java is included in the Core-Tools component (see Core-Tools in the Components chapter). It is accessible through the WSDL2Java script in the bin subdirectory of the WSO2 SOA Enablement Server distribution.

WSDL2Java replaces the deprecated WSDLCompiler tool. For backward compatibility, WSDLCompiler is also included in Core-Tools, with a script in the bin directory.

For more information and examples about how to use WSDL2Java, see Invocation: Jumpstart in Developing Basic Web Services.

[Note]Note

Instead of manually typing out the command line each time you run WSDL2Java, you can create an ANT task build script that can be reused. Please see ANT WSDL2Java Task for details.

Command-Line Options  Locate

The WSDL2Java tool can process both local and remote WSDL documents. When compiling a local WSDL, simply enter the file name, as follows:

WSDL2Java interfaces.wsdl

If you are compiling a remote WSDL, use the --url switch, as follows:

WSDL2Java --url http://localhost:6060/interfaces/
Optional Parameters  Locate

The WSDL2Java tool has many optional parameters that adjust the compilation process. For ease of use, these are divided into input parameters, output parameters and debugging parameters. They are described in the following tables:

Table 13. WSDL2Java Input Parameters

Parameter

--full-name

-abbreviation

Description
--service {nsURI}localPartQName of the service in the form of {nsURI}localPart. Only this service is generated.
--port

Name of the port to be generated. Example:

WSDL2Java --service {http://my.org/ServiceNS}JavaService --port HelloPort
--port-type {ns}Local

Selects the port type generated, for example:

WSDL2Java --port-type {http://my.org/ServiceNS}HelloPortType
--deployment-descriptor

Sets a deployment descriptor that describes additional XML schemas/type mapping to be used for processing the WSDL document. When this option is used, --processing must be used as well. (Please see Deployment Descriptors.)

--processing

Sets the processing in the deployment descriptor set in the --deployment-descriptor parameter. (See above.) Can only be used with --deployment-descriptor. This parameter is mainly used for custom serialization. (For more information about serialization frameworks, see Java Level Processing.) An example follows:

WSDL2Java --deployment-descriptor package.xml --processing TypeMapping 
       Definitions.wsdl
--protocol

Chooses the protocol type to be processed. Other protocol types will be ignored. Supported values are soap11 for SOAP 1.1 and soap12 for SOAP 1.2.

--username user_name Sets username for HTTP-Basic authentication.
--password password Sets password for HTTP-Basic authentication.
--unwrap

If false, WSDL2Java does not unwrap wrapping elements in wrapped document/literal binding. Default value is 'true'. (Please see Document/Literal Wrapped for further explanation and Example of the --unwrap Option for examples.)

Table 14. WSDL2Java Output Parameters

Parameter

--full-name

-abbreviation

Description

--output-directory

-d

The output directory where the Java files are to be generated. If the directory does not exist, it is created.

--force

-f

Overwrites existing file, when a file with same path as the file being generated exists already. This prevents File already exists-type errors.

--output-language language

-l language

Set of back ends that WSDL2Java should use. Choices include java, java-async, java-async-server and java-impl. The default is java-async.

The WSDL2Java command by itself lists all the available back ends.

--target-java version

Generated sources will compile with this version of Java. Choices include 1.3, 1.4 and 5.

--interface-package package-name

-p package-name

Designates the package for the interface for the service. If no destination is set, the default package will be used.

--structure-package package-name

-s package-name

If data structures are generated, this option sets the package to be used for them. If --structure-package is not used, the structures will be included in the interface package.

--generate-javabeans The default mode for generating structures is via creating all public attributes. This option switches to a mode where the fields are protected. Public get/set methods are generated as well, conforming to the Java Beans compatibility mode.
--generate-interfaces The default mode for generating structures is via making all fields public. This option switches to a mode where only an interface for the actual implementation is generated. The user must provide an implementation of the interface, and create custom (de)serializers for these types.

--map-type {ns}local->javaName

-m {ns}local->javaName

Specifies type mapping from a schema type named {ns}local to a Java class, where ns is the namespace, local is the name of the schema type from that namespace, and javaName is the fully qualified name of the Java class. Example:

WSDL2Java -m {http://some.org}Order→org.myorg.BasicOrder Some.wsdl

--map-type-fault {ns}local=javaName

Specifies type mapping from schema type used as fault to Java exception. Use for customization of Java exception names; useful if the same XML Schema type is used as both data class and exception.

--map-ns namespace=package

-n namespace=package

Specifies mapping from schema namespace to Java package.
--use-mtom mode

Sets mode for base64Binary schema types. Possible values are never, auto, and always. The default is auto.

--strict-schema For better interoperability with Microsoft .NET WSO2 SOA Enablement Server, WSDL2Java canonizes the WSDL file (for example, operations with one output parameter and no return value are generated into a Java method with one return value and no output parameter). Switch off this behavior using this option.
--mixed-to-dom Map XML Schema types with mixed content to org.w3c.dom.Element.

Table 15. WSDL2Java Debugging Parameters

Parameter

--full-name

-abbreviation

Description

--verbose0-10

-v0-10

Controls verbose output. The optional parameter (default value 0) is the level of verbose messages (0: no messages, 10: full messages).

--version Shows the version of the WSDL2Java tool. Use this option when reporting potential WSDL2Java bugs.
--print-types Shows the internal representation of XMLSchema types contained in the WSDL file.
Example of the --unwrap Option  Locate

Consider a Java method that takes two numbers and returns the result of the operation 'number1 + number2':

int add(int number1, number2)

In wrapped document/literal binding, it will be described in the WSDL with the element wsdl:message:

<wsdl:message name="Add_RequestMessage">
    <wsdl:part name="parameters" element="ns:add"/>
</wsdl:message>

All method parameters will be wrapped inside the element with the "wsdl:types" section of WSDL:

<wsdl:types>
    <xsd:element name="add">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="number1" type="xsd:int"/>
                <xsd:element name="number2" type="xsd:int"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
    <xsd:element name="addResponse">
        <xsd:complexType>
            <xsd:sequence>
                <xsd:element name="result" type="xsd:int"/>
            </xsd:sequence>
        </xsd:complexType>
    </xsd:element>
</wsdl:types>

WSDL2Java detects that the WSDL is wrapped document/literal. (The name of the element is the same as the name of the operation, the type of element is a sequence without attributes). Normally it would generate the same interface as the original one.

As the rules for wrapper-detection are not specified in some standards and for the sake of backward compatibility, user can suppress the detection of wrappers and force WSDL2Java to generate wrapper elements as classes.

Calling WSDL2Java with --unwrap=false would generate this interface:

AddResponse add(AddRequest p0)

where

class AddRequest {
     public int number1;
     public int number2;
}
                
class AddResponse {
    public int response;
}