Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

wsdl2java - takes a WSDL document and generates fully annotated Java code from which to implement a service.

Synopsis

No Format

Usage : wsdl2java -fe|-frontend <front-end-name> -db|-databinding <data-binding-name> 
-wv <wsdl-version> -p <[wsdl-namespace =]package-name>* -sn <service-name> 
-b <binding-file-name>* -reserveClass <class-name>* -catalog <catalog-file-name> 
-d <output-directory> -compile -classdir <compile-classes-directory> -impl -server
-client -clientjar <jar-file-name> -all -autoNameResolution -allowElementReferences|-aer<=true> 
-defaultValues<=class-name-for-DefaultValueProvider> -ant 
-nexclude <schema-namespace [= java-package-name]>* -exsh <(true, false)> -noTypes
-dns <(true, false> -dex <(true, false)> -validate -keep 
-wsdlLocation <wsdlLocation> -xjc<xjc-arguments>* -asyncMethods<[=method1,method2,...]>* 
-bareMethods<[=method1,method2,...]>* -mimeMethods<[=method1,method2,...]>* -noAddressBinding 
-faultSerialVersionUID <fault-serialVersionUID> -exceptionSuper <exceptionSuper> 
-mark-generated -h|-?|-help -version|-v -verbose|-V -quiet|-q|-Q -wsdlList <wsdlurl>

...

The wsdl2java command can be wrapped inside an Ant target as shown below:

Code Block
xml
xml

<?xml version="1.0"?>
<project name="cxf wsdl2java" basedir=".">   
   <property name="cxf.home" location ="/usr/myapps/cxf-2.5.1"/>

   <path id="cxf.classpath">
      <fileset dir="${cxf.home}/lib">
         <include name="*.jar"/>
      </fileset>
   </path>
      
   <target name="cxfWSDLToJava">
      <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">
         <arg value="-client"/>
         <arg value="-d"/>
         <arg value="src"/>
         <arg value="MyWSDL.wsdl"/>
         <classpath>
            <path refid="cxf.classpath"/>
         </classpath>
      </java>
   </target>
</project>

...

A: We don't have a command-line option to do this, but you can have a binding file like the following snippet to achieve this goal

Code Block
xml
xml

<bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    wsdlLocation="hello_world.wsdl"
    xmlns="http://java.sun.com/xml/ns/jaxws">
    <bindings node="wsdl:definitions/wsdl:portType[@name='GreeterSE']">
	<class name="GreeterSEI"/>
    </bindings>
</bindings>

...

Q: How to map xsd:dateTime to java.util.Date?
Well, people don't like the XMLGregorianCalendar which is the default mapping from the xsd:dateTime (xsd:time and xsd:date as well),
We can use the jaxws customization to change the default mapping, here are some sample binding files
If you have schema inside the wsdl, here is the binding file you can use:

Code Block

<jaxws:bindings wsdlLocation="YOUR_WSDL_LOCATION"
          xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"
          xmlns:xs="http://www.w3.org/2001/XMLSchema"
          xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
          xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">
  <jaxws:bindings  node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='THE_NAMESPACE_OF_YOUR_SCHEMA']">
      <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
        <jxb:javaType name="java.util.Date" xmlType="xs:dateTime"
                      parseMethod="org.apache.cxf.toolsxjc.commonruntime.DataTypeAdapter.parseDateTime"
                      printMethod="org.apache.cxf.toolsxjc.commonruntime.DataTypeAdapter.printDateTime"/>
      </jxb:globalBindings>
  </jaxws:bindings>
</jaxws:bindings>

This requires an additional dependency:

Code Block
<dependency>
   <groupId>org.apache.cxf.xjc-utils</groupId>
   <artifactId>cxf-xjc-runtime</artifactId>
</dependency>

 

If you want to use java.util.Calendar, just change the org.apache.cxf.toolsxjc.commonruntime.DataTypeAdapter to javax.xml.bind.DatatypeConverter, and change the name value to "java.util.Calendar"

If your schema is out of wsdl, here is an example you can try:

Code Block

<jxb:bindings version="2.0"
              xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
              xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <jxb:bindings schemaLocation="file:<path><name>.xsd" node="/xs:schema">
    <jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <jxb:javaType name="java.util.Date" xmlType="xs:dateTime" 
                    parseMethod="org.apache.cxf.toolsxjc.commonruntime.DataTypeAdapter.parseDateTime" 
                    printMethod="org.apache.cxf.toolsxjc.commonruntime.DataTypeAdapter.printDateTime"/>
    </jxb:globalBindings>
  </jxb:bindings>
</jxb:bindings>

...

A: Create an external binding file and set the value of <enableWrapperStyle/> to true or false as desired:

Code Block

<jaxws:bindings
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    wsdlLocation="your.wsdl"
    xmlns="http://java.sun.com/xml/ns/jaxws"
    xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
    <enableWrapperStyle>false</enableWrapperStyle>
</jaxws:bindings>

Alternatively you can embed this instruction within the WSDL file directly, as the immediate child of the wsdl:portType:

Code Block

<wsdl:portType name="MyWebServicePortType">
    <jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">
        <jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>
        ... other binding settings if needed ...
    </jaxws:bindings>
    <wsdl:operation name="sayHello">
    ...
</wsdl:portType>

...