Generating a Java client from WADL

You can generate the Java client for a WADL file by using the wadl2java tool. To download the ZIP file containing wadl2java, go to https://github.com/javaee/wadl.

After downloading the ZIP file, perform the following steps:

  1. Extract the contents and set the path to the bin folder that contains the wadl2java.bat file (for example, <wadl-dist-1.1.6>/bin).
  2. Set JAVA_HOME pointing to a valid JDK home folder.
  3. Now, execute wadl2java as follows:
wadl2java -o outputDir -p package [-a] [-s jaxrs20] [-c customization]  outputfile.wadl 

Here is a brief description of the arguments used for wadl2java:

  • -o outputDir: This argument specifies the target folder for storing the generated client source
  • -p package: This argument specifies the Java package name for the generated client source
  • -a: If you specify this parameter, each schema namespace name is mapped to a package and the element types for the namespace are generated in appropriate packages
  • -c customization: This argument specifies the path or URL of a JAXB binding customization file
  • -s jaxrs20: This argument specifies that the client code should be compatible with JAXRS2.0; the default value is jersey1x
  • outputfile.wadl: Here, you can specify the path or the URL of the WADL file to process

The following example uses the wadl2java tool to generate the Java client for the WADL file located at http://<host>:<port>/rest-chapter7-jaxrs2wadl/webresources/application.wadl:

wadl2java -o gen-src -p com.packtpub.demo.client -s jaxrs20 http://localhost:8080/rest-chapter7-jaxrs2wadl/webresources/application.wadl
  
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.4.191