Java2WSDL  Locate

Overview  Locate

Java2WSDL creates WSDL documents from Java .class files. The WSDL specification is located at http://www.w3.org/tr/wsdl.

The Java2WSDL tool relies on the Java2Schema utility (Please see Multiple Inheritance), which maps Java data types to their XML Schema representations.

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

Style of Compilation  Locate

Each class given as a parameter on the command line is introspected. All required information is generated into the WSDL file. All the public non-static methods are published as operations, including those methods inherited from superclasses and superinterfaces.

The created WSDL files follow the structure of the Java class files. By default, a single file is constructed for each package. All the necessary XML Schema mappings of Java types are copied into each file.

Unless it is explicitly stated otherwise, the WSDL filename and its target namespace consists of a default prefix and a unique suffix derived from the name of the package containing the class. So, if you generate WSDL for more than one class at a time, all the classes from a common package will be processed into a common file.

WSDL filename and target namespace can be customized thanks to the following two rules of WSDL:

  1. Each package name can be mapped to a specific target namespace

  2. Each target namespace can be mapped to a specific filename

By adding a command-line parameter, you can remap a package name to a custom namespace and filename. You can create a file named anything you wish, with any namespace you want, as shown here:

Java2WSDL --package-mapping examples.package=http://wso2.com/myService
     --output-file-mapping http://wso2.com/myService=myWSDL.wsdl examples.package.Service

When the class examples.package.Service is processed by Java2WSDL, it is inserted into a WSDL file named Definitions_examples_package.wsdl in the target namespace http://wso2.com/wsdl/examples/package/. By remapping, you can put the file myWSDL.wsdl in the namespace http://wso2.com/myService.

While Java2WSDL generates WSDL information, it uses Java2Schema to create XML Schema mappings of the Java structures. When generating multiple WSDLs, you may find that the same Schema mappings are copied into each file. To avoid this redundancy, move all the Schemas into one common file, which can then be imported by the other WSDLs, with this command:

Java2WSDL --reuse-types a.ServiceA b.ServiceB c.ServiceC

This command creates four files. Definitions_a.wsdl, Definitions_b.wsdl and Definitions_c.wsdl each contain a single service with an import element referring to the fourth file, which contains all Schema types: Definition_com_wso2_types_SchemaTypes.wsdl.

Features  Locate

SOAP Binding and Encoding Styles  Locate

Within a WSDL document, the binding describes how the service is bound to the SOAP messaging protocol. Following the WSDL 1.1 specification, located at http://www.w3.org/TR/wsdl), the WSDL SOAP binding can be either RPC style or document style. In addition, the binding can have an encoded use or a literal use. Of the possible combinations, WSO2 SOA Enablement Server supports the following:

  • RPC/encoded

  • RPC/literal

  • document/literal

  • A special style called document/literal wrapped, or wrapped/literal

The combinations wrapped/literal and rpc/literal are compliant with WS-I Basic Profile Version 1.0.

The RPC/encoded binding style was mostly used during the early days of Web services. Today the de-facto standard is document/literal (or wrapped document/literal) because of its compatibility with .NET services and because of the WS-I basic profile. This is the default binding/encoding style of WSDL documents generated by WSO2 SOA Enablement Server Java2WSDL. A WSDL document with this style of binding is in Example 170. We see the style attribute of the soap:binding element has the value document and the soap:body element specifies the literal use.

Example 170. WSDL Binding for HelloService

<wsdl:binding name="HelloService" type="tns:HelloService">
    <soap:binding style="document" 
    transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="hello">
        <soap:operation soapAction="helloService" style="document"/>
        <wsdl:input>
            <soap:body parts="name" use="literal"/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts="response" use="literal"/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

WSDL documents utilizing all four supported binding styles are presented below for the following Hello service:

public interface Hello {
    String hello(String s);
}
RPC/Encoded  Locate

When using the rpc/encoded style, the parameters in the message are surrounded by an element whose name is the same as the name of the operation. This is a big advantage, because the server can easily dispatch the operation according to the element name.

The names of the parts within the message are not important. What matters are the types of the parts inside the message and the parameter order.

The rules for SOAP encoding (cf. Section 5 of the SOAP specification) are applied on the XML content. Hence, the XML content of the message cannot be directly validated against XML schema.

Example 171. RPC/Encoded Binding for Hello Service

<wsdl:message name='Hello_hello_Response_Soap'>
    <wsdl:part name='response' type='xsd:string'/>
</wsdl:message>
<wsdl:message name='Hello_hello__Request_Soap'>
    <wsdl:part name='name' type='xsd:string'/>
</wsdl:message>
<wsdl:portType name='Hello'>
    <wsdl:operation name='hello' parameterOrder='name'>
        <wsdl:input message='tns:Hello_hello__Request_Soap'/>
        <wsdl:output message='tns:Hello_hello_Response_Soap'/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name='Hello' type='tns:Hello'>
    <soap:binding transport='http://schemas.xmlsoap.org/soap/http' 
        style='rpc'/>
    <wsdl:operation name='hello'>
        <soap:operation soapAction='' style='rpc'/>
        <wsdl:input>
            <soap:body parts='name' use='encoded' 
            encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' 
            namespace='http://wso2.com/wsdl/hello/Hello#hello#KExqYXZhL2xhbmcvU3RyaW5nOylMamF2YS9sYW5nL1N0cmluZzs='/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts='response' use='encoded' 
            encodingStyle='http://schemas.xmlsoap.org/soap/encoding/' 
            namespace='http://wso2.com/wsdl/hello/Hello#hello#KExqYXZhL2xhbmcvU3RyaW5nOylMamF2YS9sYW5nL1N0cmluZzs='/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>
Document/Literal  Locate

In the document/literal binding style, each message part is described using an XML schema element. This allows the data content of the message to easily be validated. Unfortunately, there is no wrapping element with the operation name, so dispatching on the server side can be a little more complicated. This disadvantage is solved in the wrapped document/literal style. Example 172 contains an unwrapped document/literal-bound Hello service WSDL.

Example 172. Document/Literal Binding (unwrapped) for Hello Service

<wsdl:types>
    <xsd:schema elementFormDefault="qualified"
        targetNamespace="http://wso2.com/xsd/SchemaTypes/"
        xmlns:tns="http://wso2.com/xsd/SchemaTypes/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="name" nillable="true" type="xsd:string"/>
        <xsd:element name="string_Response" nillable="true" 
            type="xsd:string"/>
    </xsd:schema>
</wsdl:types>

<wsdl:message name='Hello_hello_Response_Soap'>
    <wsdl:part name='response' element='ns0:string_Response'/>
</wsdl:message>
<wsdl:message name='Hello_hello__Request_Soap'>
    <wsdl:part name='name' element='ns0:name'/>
</wsdl:message>
<wsdl:portType name='Hello'>
    <wsdl:operation name='hello' parameterOrder='name'>
        <wsdl:input message='tns:Hello_hello__Request_Soap'/>
        <wsdl:output message='tns:Hello_hello_Response_Soap'/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name='Hello' type='tns:Hello'>
    <soap:binding transport='http://schemas.xmlsoap.org/soap/http'
        style='document'/>
    <wsdl:operation name='hello'>
        <soap:operation soapAction='hello' style='document'/>
        <wsdl:input>
            <soap:body parts='name' use='literal'/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts='response' use='literal'/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

Document/Literal Wrapped  Locate

This is very similar to document/literal. The difference is the wrapping of parameters. All method parameters are wrapped into an element whose name is the same as the name of the operation. The wrapping element is described in the XML schema, so the message content can easily be validated against the schema. The wrapper element type is xsd:complexType, containing the xsd:sequence. This sequence contains one element for each parameter. The name of the wrapper element can be used to dispatch the call on the server side.

Wrapped document/literal binding is the de-facto standard used by Microsoft .NET. Because it maps the parameters inside the wrapper element, the message can contain only one part, making it WS-I compliant.

The wrapper elements are recognized according to the following criteria:

  • The input message has only one part inside the SOAP body.

  • That part is an element.

  • The element name is the same as the name of the operation.

  • The type of the element is complexType and it has no attributes.

[Note]Note

Wrapped document/literal binding has been supported since WSO2 SOA Enablement Server for Java 4.7.

Because the WS-I basic profile dictates that no more than one message part be present inside a SOAP message, we recommend using wrapped/literal to publish your services. Example 173 contains a wrapped document/literal-bound WSDL for the Hello service.

Example 173. Wrapped Document/Literal Binding for the Hello Service

<wsdl:types>
    <xsd:schema elementFormDefault="qualified"
        targetNamespace="http://wso2.com/wsdl/hello/"
        xmlns:tns="http://wso2.com/wsdl/hello/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <xsd:element name="hello">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="name" nillable="true" 
                        type="xsd:string"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
        <xsd:element name="helloResponse">
            <xsd:complexType>
                <xsd:sequence>
                    <xsd:element name="response" nillable="true" 
                        type="xsd:string"/>
                </xsd:sequence>
            </xsd:complexType>
        </xsd:element>
    </xsd:schema>
</wsdl:types>

<wsdl:message name='Hello_hello_Response_Soap'>
    <wsdl:part name='parameters' element='tns:helloResponse'/>
</wsdl:message>
<wsdl:message name='Hello_hello__Request_Soap'>
    <wsdl:part name='parameters' element='tns:hello'/>
</wsdl:message>
<wsdl:portType name='Hello'>
    <wsdl:operation name='hello'>
        <wsdl:input message='tns:Hello_hello__Request_Soap'/>
        <wsdl:output message='tns:Hello_hello_Response_Soap'/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name='Hello' type='tns:Hello'>
    <soap:binding transport='http://schemas.xmlsoap.org/soap/http'
        style='document'/>
    <wsdl:operation name='hello'>
        <soap:operation soapAction='hello' style='document'/>
        <wsdl:input>
            <soap:body parts='parameters' use='literal'/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts='parameters' use='literal'/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

RPC/Literal  Locate

The RPC/literal binding style is similar to RPC/encoded, but the SOAP encoding is not applied to the data. Example 174 contains an RPC/literal-bound WSDL for the Hello service.

Example 174. RPC/Literal Binding for Hello Service

<wsdl:message name='Hello_hello_Response_Soap'>
    <wsdl:part name='response' type='xsd:string'/>
</wsdl:message>
<wsdl:message name='Hello_hello__Request_Soap'>
    <wsdl:part name='name' type='xsd:string'/>
</wsdl:message>
<wsdl:portType name='Hello'>
    <wsdl:operation name='hello' parameterOrder='name'>
        <wsdl:input message='tns:Hello_hello__Request_Soap'/>
        <wsdl:output message='tns:Hello_hello_Response_Soap'/>
    </wsdl:operation>
</wsdl:portType>
<wsdl:binding name='Hello' type='tns:Hello'>
    <soap:binding transport='http://schemas.xmlsoap.org/soap/http'
        style='rpc'/>
    <wsdl:operation name='hello'>
        <soap:operation soapAction='' style='rpc'/>
        <wsdl:input>
            <soap:body parts='name' use='literal' 
            namespace='http://wso2.com/wsdl/hello/Hello#hello#KExqYXZhL2xhbmcvU3RyaW5nOylMamF2YS9sYW5nL1N0cmluZzs='/>
        </wsdl:input>
        <wsdl:output>
            <soap:body parts='response' use='literal' 
            namespace='http://wso2.com/wsdl/hello/Hello#hello#KExqYXZhL2xhbmcvU3RyaW5nOylMamF2YS9sYW5nL1N0cmluZzs='/>
        </wsdl:output>
    </wsdl:operation>
</wsdl:binding>

A Partially Generated WSDL  Locate

The structure of WSDL is modular. The Java2WSDL utility works in two modes:

  • Generating complete WSDL

  • Excluding the service and binding sections of the WSDL

The latter mode can be useful in situations when you do not want to use the WSDL directly but have it reused by another service. For more information, please refer to Partially Generated WSDL File .

Class Inclusion and Exclusion  Locate

Use Class Inclusion and Exclusion when you do not wish to map private sections of your frameworks. The settings are delegated to Java2Schema. See Class Inclusion and Exclusion in Java2Schema for more information.

Method Inclusion and Exclusion  Locate

By default, Java2WSDL puts all public methods of a service class into the WSDL. However, problems can occur, such as a service implementing a configurable interface which should not be part of public operations. This is why Java2WSDL allows exclusion of methods.

Each method can be targeted using: packageName.className.methodNamesignature .

Method inclusion is used with class exclusion. It allows you to use methods from a class you otherwise wish to keep private. There is a similar case with the Java2Schema Tool (see Java2Schema: Class Inclusion and Exclusion.

See the Method Signature Listing example for a description of how to find the method signature.

One-Way Operations  Locate

A method can be designated one-way instead of the default request-response. In this case, no SOAP response is generated. Only an HTTP notification is sent back. This can be useful for notifications if no response is expected. Use the --one-way parameter and the method name to set a method as one-way, as follows:

Java2WSDL --one-way examples.package.Service.method(Ljava/lang/String;)V org.Service

For more information, please refer to Example 181 .

Attachments  Locate

WSO2 SOA Enablement Server fully supports attachments. An attachment is binary data processed as a directional stream. The way that attachments are represented is described in the Attachments section of Java2Schema.

WSO2 SOA Enablement Server supports either Multipurpose Internet Mail Extension (MIME) or Direct Internet Message Encapsulation (DIME) attachments. The default setting is for MIME attachments. To change the type of attachment to DIME, use the advanced --attachment-type option and set the value to dime.

There are three possible directions for an attachment:

  • Input - Data goes to the server side only.

  • Output - Data goes to the client only.

  • Input/Output - Data goes to both server and client sides.

The default direction is input/output. There are two ways to change the direction. The first is with the --set-attachment option for the Java2WSDL Tool. The second, recommended way is to use the classes described in Java2Schema attachments. With these classes, the direction of the attachment is automatically set as input or output according to the class type.

[Note]Note

When generating WSDLs with MIME attachments, the generated MIME content type is 'application/octet-stream' and not 'application/binary', as we had used previously. This value can be changed in the deployment descriptor of the builtin_serialization package.

Inheritance  Locate

Setting custom inheritance paths is a feature of Java2Schema. See Multiple Inheritance.

Extra Types  Locate

Extra type mapping allows the user to map additional Java types into the WSDL and send them via SOAP. You need this when your interface uses type polymorphism. Often, a method parameter is just an interface allowing for more loosely coupled implementations. The WSDL for such a service may not contain all the required information. One example is a method with an array of objects as a parameter. Adding a class instance to this array may prevent the opposite side from understanding the message.

The following command maps two types, examples.StructureA and examples.StructureB, to their XML Schema representation and adds them to the target WSDL. If the structure is sent, necessary information can be extracted from the WSDL.

Java2WSDL examples.package.Service --add-type examples.StructureA 
                --add-type examples.StructureB
Deployment Descriptor Support  Locate

Java type mapping can be customized using deployment descriptors (Please see Deployment Descriptors). If the user already has a descriptor, he can simply tell Java2WSDL to use it, with the --deployment-descriptor parameter. Note that the deployment descriptor and processing options must be set together, as in the following command:

Java2WSDL --deployment-descriptor package.xml --processing MyProcessing 
                example.service.MyService

This command tells Java2Schema to parse the deployment descriptor file package.xml. The processing node inside the descriptor named Processing is taken and put into the mapping context. If the descriptor contains additional information--about type mapping, for example--WSO2 SOA Enablement Server will hold the new settings.

Custom Mapping and XML Schema Referencing  Locate

The Java2Schema utility handles custom mapping. For more details, see Java2 Schema: Schema Reference and Custom Mapping.

Custom WSDL Extensions  Locate

Java2WSDL generates custom WSDL extensions to help a related tool, WSDL2Java, generate Java classes easily.

Extension QNameAttributesPosition in WSDLDescription
{nsURI}java-operation
name='methodName'
signature='base64 encoded method signature'
Binding/OperationHas the operation mapped to the specified Java method and signature
Classpath  Locate

Each .class or source file processed or used during compilation must be in the current classpath. Java2WSDL can extend the classpath for custom purposes with the --classpath parameter, which has the following syntax:

Java2WSDL --classpath c:\temp classname

Once Web service class sources are available in the classpath, parameter names are read from them and fed into WSDL. This occurs when either Java2WSDL or Runtime Publishing is used. The same occurs with the contents of deployment packages.

Command Line  Locate

Java2WSDL receives optional parameters customizing compilation. One or more mandatory arguments must be set. These arguments contain the names of the classes for which WSDL will be generated. Class names must be in a fully qualified form.

The Java2WSDL command-line parameters are divided into basic and advanced sets. Basic parameters appear when you enter Java2WSDL by itself, or Java2WSDL --help. Both basic and advanced options appear when you enter Java2WSDL --morehelp.

Usage of Java2WSDL is:

Java2WSDL [option...] class...

Options are listed in Table 16, “Basic Java2WSDL Command Options” and Table 17, “Advanced Java2WSDL Command Options”.

Table 16. Basic Java2WSDL Command Options

Parameter

--full-name

-abbreviation

Description
--add-type class

Generates a schema type for the given class to output definition(s). Useful for polymorphism.

--class-mapping class=endpointURI

-c class=endpointURI

Maps Java class to Web service endpoint URI.

--classpath classpath

--cp classpath

Classpath for loading class and source when these classes are not in the system classpath.

--deployment-descriptor file --processing localName

Specifies deployment descriptor file name and its processing. Both parameters must be set at the same time.
--force

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

--help

-h

Prints help screen with the basic commands.
--morehelpPrints help screen with both basic and advanced options.

--output-directory dir

-d dir

Directory where output definition(s) will be stored (default is current directory).

--output-file-mapping targetNamespace=definitionFileName

-o targetNamespace=definitionFileName

Maps WSDL (identified by its target namespace) to output file name.

--package-mapping package=targetNamespace

-p package=targetNamespace

Maps a Java package to WSDL target namespace. For Java classes with no package (default package), use default as package name.

--protocol SOAP version number

Specifies SOAP version protocol. Supported protocols are soap11 for SOAP 1.1 and soap12 for SOAP 1.2. By specifying both protocols with the command --protocol soap11 --protocol soap12 or --protocol soap11,soap12, both protocols will be supported, each with its own port and binding.

If this parameter is not set, the SOAP version protocol will be determined by the configuration file. This is set during installation, when the default choice is SOAP 1.1 See Standard Installation.

--service-mapping class=serviceName

-s class=serviceName

Maps Java class to a specific service name (default is JavaService).

--soap-binding-style style

--sbs style

Specifies SOAP Binding style. Style can be either rpc, document or wrapped. The default value is read from WSO2 SOA Enablement Server configuration files and it is set during the installation process. The default during installation is document. Please see SOAP Binding and Encoding Styles.

--soap-encoding-style style

--ses style

Specifies SOAP encoding style (use attribute). Style can be either literal or encoded. The default value is read from WSO2 SOA Enablement Server configuration files and it is set during the installation process. The default during installation is literal. Please see SOAP Binding and Encoding Styles.

--use-nillable[true|false]

Sets which attribute should be generated for Java reference data types. If true, nillable="true" is generated. If false, minOccurs=0 is generated.

The default setting is 'true.' This default can be changed in the defaultUseNillable element in serverconf.xml or clientconf.xml.

This switch can be useful if you are experiencing trouble communicating with .NET, as C# prefers optional elements to be present rather than nillable.

Setting of --use-nillableExample Java data typeResulting WSDL element
--use-nillable true
java.lang.Integer i
<element name="i" 
     type="xsd:int"
     nillable="true"/>
--use-nillable false
java.lang.Integer i
<element name="i" 
     type="xsd:int" 
     minOccurs="0" 
     maxOccurs="1"/>
--verbose[=length]

Additional information during processing will be printed to stderr. Optional length attribute sets max length of output message.

--version

-v

Prints version information.

Table 17. Advanced Java2WSDL Command Options

Parameter

--full-name

-abbreviation

Description
--add-fault class.methodsignature->exceptionClass

Adds an additional SOAP fault to an operation generated from the method. This has very similar effect as if the exeption was included in a java throws clause. The signature is mandatory only if the method is overloaded. Both classes must be available in classpath. Example:

--add-fault com.example.webservice.OperationsIface.echoInt(I)I->
     com.example.webservice.exception.SomeException
[Note]Note

It is usually not necessary to use this option. For example if you want to use polymorphism for faults, it is enough to have throws com.example.BaseException in the Java method signature (the base exception class must not be a system exception because for such exceptions Java2WSDL cannot provide an XML Schema definition) and add subexceptions with the --add-type option.

--always-use-swaRef[=true|false]

If WS-I Attachments are turned on (with --wsi-attachments ), this forces all attachments to be expressed with a swaRef type and not with an explicit MIME part. Default is false. Option entered without value means true.

--attachment-type

Specifies whether attachments will be MIME or DIME. Default value is read from WSO2 SOA Enablement Server configuration files. It is set during the installation process, where it is MIME by default. Please see Attachments.

--disable-bindings

-b

Disable generation of bindings and services

--exclude-class class

-x class

Excludes all methods of a given class from the output definition. (You can use Java notation such as java.lang.*, to exclude all classes.)

--exclude-method class.methodsignature

-e class.methodsignature

Excludes the method of given class from output definition.

--include-class class

-y class

Includes all methods of a given class in the output definition. (Class inclusion has higher priority than exclusion.)

--include-method class.methodsignature

-i class.methodsignature

Includes the method of the given class into the output definition.
--inherit class-superclassSpecifies the inheritance path.
--insert xmlschema-or-wsdl-file

Takes a given XML Schema or WSDL file and uses types defined therein as the basis for compilation. Inserts file to target WSDL.

--list-signatures class

-l class

Lists all methods of the given class with their signatures.
--no-java-mapping-extensionDisables generation of extensibility elements into WSDL and XML Schema.

--one-way class.methodsignature

-w class.methodsignature

Generates operation as one-way (NO RESPONSE).
--reference xmlschema-or-wsdl-file

Takes given XML Schema or WSDL file and use types defined therein as the base for compilation. The reference will be included in the resulting WSDL, as follows: WSDLs are referenced with <wsdl:import>, and XML Schemas are imported in types with <xsd:import>.

--reuse-types

-r

Enables type reuse. All the types will be in common WSDL files.

--set-attachment class.methodsignature[+/-/+-]

-a class.methodsignature[+/-/+-]

This option controls the type of generated attachments for a given method. The attachment type is set by a suffix to the method signature. Use + for output, - for input and +- for in/out attachments.

--set-in-attachmentsCauses attachments to be mapped as input parameters. By default, attachments are input/output.
--singledim-arrays

Disallows the generation of SOAP Sec. 5 arrays as multidimensional. For example, a 2-dimensional array will be generated as an [][] array, not as an [,] array.

--wsi-attachments[=true|false]Turns on WS-I Attachment Profile 1.0 compliant attachment specification in WSDL. Default value depends on SSJ configuration. Option entered without value means true.

Configuration  Locate

Java2WSDL can be partially configured through the client's configuration file in WSO2 SOA Enablement Server, the contents of which are shown in Example 175 .

Example 175. Java2WSDL Configuration file

<?xml version="1.0" encoding="UTF-8"?>
<java2Type name="main">
    <excludedClass>fullClassName-or-packageName-to-exclude</excludedClass>
    <includedClass>fullClassName-to-include</includedClass>
    <excludedMethod>methodSignature-or-methods-to-exclude</excludedMethod>
    <includedMethods>methodSignature-to-include</includedMethods>
    <internalSchema fileName="schema-file-name" 
    targetNamespace="namespace-to-include-schema-on"/>
</java2Type>

Both the server and client side WSO2 SOA Enablement Server configuration files preset Java2WSDL to:

  • Exclude these classes and packages from compilation:

    java.io.*
    java.lang.ClassLoader 
    java.lang.Compiler 
    java.lang.ThreadLocal 
    java.lang.Process 
    java.lang.Runtime 
    java.lang.RuntimePermission 
    java.lang.SecurityManager 
    java.lang.System 
    java.lang.Thread 
    java.lang.ThreadGroup
    java.lang.Throwable 
    java.net.* 
    java.text.* 
    org.systinet.wasp.webservice.*
  • Insert XML Schema to the generated WSDL if the appropriate namespace is used.

Table 18. Default Configuration of Java2WSDL

Namespace XML Schema File
http://idoox.com/interfacecom/idoox/wasp/interrefs/interrefs.xsd
http://idoox.com/interfacecom/idoox/wasp/interrefs/interrefs.literal.xsd
http://idoox.com/securitycom/idoox/wasp/security/security.xsd
http://idoox.com/containerscom/idoox/wasp/serialization/javabuiltin/idooxContainers.xsd
http://idoox.com/containerscom/idoox/wasp/serialization/javabuiltin/apacheContainers.xsd
http://xml.apache.org/xml-soapcom/idoox/wasp/serialization/javabuiltin/apacheContainers.xsd
http://wso2.com/containers/encoded/ms.netcom/idoox/wasp/serialization/javabuiltin/msnet/msnetEncodedContainers.xsd
http://wso2.com/containers/literal/ms.netcom/idoox/wasp/serialization/xml/msnet/msnetLiteralContainers.xsd
http://idoox.com/sparse-arraycom/idoox/wasp/serialization/idooxbuiltin/array.xsd

Examples  Locate

All the examples can be found in the directory src/example/tools/java2WSDL.

Customizing Basic Properties  Locate

The following basic properties are related:

  • WSDL filename

  • WSDL target namespace

  • Endpoint URI

Target namespaces are determined by the package name. The filename is mapped to a namespace. The endpoint URI can be changed for each class (and therefore for each service) separately. The command in Example 176 sets the WSDL filename, target namespace and endpoint URI for the BasicProperties class.

Java2WSDL --package-mapping example.tools.java2wsdl.BasicProperties=http://my.org/

Example 176. Setting WSDL Filename, Target Namespace, and Endpoint URI for BasicProperties

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.BasicProperties;

public interface Service {
    public int serviceMethodA();

    public void serviceMethodB();
}

In Example 176 , the file ExampleWSDL.wsdl is created. Its target namespace is http://my.org/ and the service endpoint URI is set to http://my.org/Service'/, as can be seen in Example 177 .

Example 177. ExampleWSDL.wsdl

<?xml version='1.0'?>
<wsdl:definitions name="example.tools.java2wsdl.BasicProperties.Service"
    targetNamespace="http://my.org/" xmlns:map="http://systinet.com/mapping/"
    xmlns:ns0="http://systinet.com/xsd/SchemaTypes/"
    xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/"
    xmlns:tns="http://my.org/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
    <wsdl:types>
        <xsd:schema elementFormDefault="qualified"
            targetNamespace="http://systinet.com/xsd/SchemaTypes/"
            xmlns:tns="http://systinet.com/xsd/SchemaTypes/" 
            xmlns:xsd="http://www.w3.org/2001/XMLSchema">
            <xsd:element name="int_Response" type="xsd:int"/>
        </xsd:schema>
    </wsdl:types>
    <wsdl:message name="Service_serviceMethodB_1_Request"/>
    <wsdl:message name="Service_serviceMethodA_1_Request"/>
    <wsdl:message name="Service_serviceMethodB_Response"/>
    <wsdl:message name="Service_serviceMethodA_Response">
        <wsdl:part element="ns0:int_Response" name="response"/>
    </wsdl:message>
    <wsdl:portType name="Service">
        <wsdl:operation name="serviceMethodA">
            <wsdl:input message="tns:Service_serviceMethodA_1_Request"/>
            <wsdl:output message="tns:Service_serviceMethodA_Response"/>
        </wsdl:operation>
        <wsdl:operation name="serviceMethodB">
            <wsdl:input message="tns:Service_serviceMethodB_1_Request"/>
            <wsdl:output message="tns:Service_serviceMethodB_Response"/>
        </wsdl:operation>
    </wsdl:portType>
    <wsdl:binding name="Service" type="tns:Service">
        <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
        <wsdl:operation name="serviceMethodA">
            <map:java-operation name="serviceMethodA" signature="KClJ"/>
            <soap:operation
                soapAction="http://my.org/Service#serviceMethodA#KClJ" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
        <wsdl:operation name="serviceMethodB">
            <map:java-operation name="serviceMethodB" signature="KClW"/>
            <soap:operation
                soapAction="http://my.org/Service#serviceMethodB#KClW" style="document"/>
            <wsdl:input>
                <soap:body use="literal"/>
            </wsdl:input>
            <wsdl:output>
                <soap:body use="literal"/>
            </wsdl:output>
        </wsdl:operation>
    </wsdl:binding>
    <wsdl:service name="JavaService">
        <wsdl:port binding="tns:Service" name="Service">
            <soap:address location="http://my.org/Service"/>
        </wsdl:port>
    </wsdl:service>
</wsdl:definitions>
SOAP Binding and SOAP Encoding  Locate

The default values for generated WSDLs are set in the WSO2 SOA Enablement Server configuration (please see Preferences in wasp/conf/clientconf.xml). They are initially set during the installation phase. The default value is the document binding style with literal encoding.

You can override the default values using:

Java2WSDL [--soap-binding-style [[document] | [rpc] | [wrapped]] ] [--soap-encoding-style [[encoded] | [literal]] ]

Please see the section SOAP Binding and Encoding Styles for a full description of binding styles.

The following command changes from default to RPC/encoded binding for the RpcVsDocumentService:

Java2WSDL --soap-encoding-style encoded --soap-binding-style
                rpc example.tools.java2wsdl.RpcVsDocument.Service

To change back to document/literal, use:

Java2WSDL --soap-encoding-style literal --soap-binding-style document
            example.tools.java2wsdl.RpcVsDocument.Service

Example 178. RPC/Encoded Web Service

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.RpcVsDocument;

public interface Service {
    public int serviceMethodA();

    public void serviceMethodB(String s);
}
Partially Generated WSDL File  Locate

The --disable-bindings parameter in the following command causes Java2WSDL to exclude the binding and service sections of the WSDL file for the PartialWSDL service:

Java2WSDL --disable-bindings example.tools.java2wsdl.PartialWSDL.Service

Example 179. Generating a WSDL Without binding and service

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.PartialWSDL;

public interface Service {
    public int serviceMethodA();

    public void serviceMethodB(String s);
}
Method Signature Listing  Locate

To simplify creation of method signatures, use the Java2WSDL --list-signatures class option, which prints the signatures of all class methods. The following command performs this for the class shown in Example 180:

Java2WSDL --list-signatures example.tools.java2wsdl.MethodSignatures.Service

Example 180. Method Signature Listing

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.MethodSignatures;


/**
 * Methods in class Service have following signatures:
 *
 * example.tools.java2wsdl.MethodSignatures.Service.echoVoid()V
 * example.tools.java2wsdl.MethodSignatures.Service.echoInt(I)I
 * example.tools.java2wsdl.MethodSignatures.Service.echoList(
 * Ljava/util/List;)Ljava/lang/String;
 */
public class Service {
    public void echoVoid() {
    }

    public int echoInt(int i) {
        return i;
    }

    public String echoList(java.util.List list) {
        return list.toString();
    }
}
One-Way Methods  Locate

Methods in a Web service are normally two-way, request-response. In some cases you may need to treat a method as one-way. For example, imagine a service with two methods. The first method returns an integer representing a status code. The second takes a parameter which might be heavily processed. In this case, it is better to process the second method as one-way. The following command uses the --one-way parameter to generate serviceMethodB in the OneWay service as one-way, while other methods are still generated as request-response:

Java2WSDL --one-way example.tools.java2wsdl.OneWay.Service.serviceMethodB
(Ljava/lang/String;)V example.tools.java2wsdl.OneWay.Service

Example 181. One-Way Service

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.OneWay;

public interface Service {
    public int serviceMethodA();

    public void serviceMethodB(String s);
}
Reusing Types  Locate

Sometimes a number of services might share common types. The default behavior of Java2WSDL is to generate such types into the WSDL for each service. Java2WSDL can be told to generate all types into one common WSDL and let the services reuse the definitions.

Each of the services ServiceA, ServiceB and ServiceC uses the common type Struct. The following command generates three WSDL files for these services. Each file contains a definition of the Struct type.

Java2WSDL --reuse-types example.tools.java2wsdl.ReuseTypes.a.ServiceA
                    example.tools.java2wsdl.ReuseTypes.b.ServiceB example.tools.java2wsdl.ReuseTypes.c.ServiceC

Example 182. Reusing Types

//Service A

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.OneWay;

public interface Service {
  public int serviceMethodA();
  public void serviceMethodB(String s);
}

//Service B


// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.ReuseTypes.b;
import example.tools.java2wsdl.ReuseTypes.common.Structure;

public interface ServiceB {
  Structure echo(Structure p0);
}


//Service C


// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.ReuseTypes.c;
import example.tools.java2wsdl.ReuseTypes.common.Structure;

public interface ServiceC {
  Structure echo(Structure p0);
}

//Common Structure

// Copyright WSO2 Inc. All rights reserved.
// Use is subject to license terms.
package example.tools.java2wsdl.ReuseTypes.common;

public class Structure {
  public int i;
  public java.lang.String s;
}


By contrast, the following command does not reuse types. It generates four WSDL files. The fourth file contains only XML Schema definitions and this file is just imported by the others.

Java2WSDL example.tools.java2wsdl.ReuseTypes.a.ServiceA
                    example.tools.java2wsdl.ReuseTypes.b.ServiceB example.tools.java2wsdl.ReuseTypes.c.ServiceC

Default Schemas  Locate

WSO2 SOA Enablement Server includes pregenerated XML Schemas that define various structures that WSO2 SOA Enablement Server supports. Each Schema is tied to a namespace (mostly it is its target namespace). If this namespace is used or referenced, the appropriate Schema will be included in the generated file.

Please see WSO2 SOA Enablement Server Built-in XML Schema Files for all pre-generated XML Schemas.