WADL Generation Tool
Asked Answered
R

2

17

Is there a tool which takes a Java File what describes a REST service as a parameter and generates a wadl file out of that.

Recognizor answered 28/2, 2012 at 17:31 Comment(0)
U
22

I had the same problem: was using RESTeasy and wanted to find a way to generate the WADL automatically.

Did some research and came to the solution below.

1. Add this to your pom.xml:

<build>
<plugins>
    <plugin>
        <groupId>com.sun.jersey.contribs</groupId>
        <artifactId>maven-wadl-plugin</artifactId>
        <version>1.17</version>
        <executions>
            <execution>
                <id>generate</id>
                <goals>
                    <goal>generate</goal>
                </goals>
                <phase>${javadoc-phase}</phase>
            </execution>
        </executions>
        <configuration>
            <wadlFile>${project.build.outputDirectory}/application.wadl
            </wadlFile>
            <formatWadlFile>true</formatWadlFile>
            <baseUri>http://example.com:8080/rest</baseUri>
            <packagesResourceConfig>
                <param>com.example.rs.resource</param>
            </packagesResourceConfig>
            <wadlGenerators>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorApplicationDoc
                    </className>
                    <properties>
                        <property>
                            <name>applicationDocsFile</name>
                            <value>${basedir}/src/main/doc/application-doc.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
                <wadlGeneratorDescription>
                    <className>com.sun.jersey.server.wadl.generators.WadlGeneratorGrammarsSupport
                    </className>
                    <properties>
                        <property>
                            <name>grammarsFile</name>
                            <value>${basedir}/src/main/doc/application-grammars.xml</value>
                        </property>
                    </properties>
                </wadlGeneratorDescription>
            </wadlGenerators>
        </configuration>
    </plugin>
</plugins>
</build>

Pay attention to the buildUri and packagesResourceConfig elements. You have to change them to reflect your project's configuration. You may also want to change the plugin's version (I used 1.17).

2. Create a /doc folder and add some files.

Create the src/main/doc/ folder and create the two files below.

File: application-doc.xml

Content:

<?xml version="1.0" encoding="UTF-8"?>
<applicationDocs targetNamespace="http://wadl.dev.java.net/2009/02">
    <doc xml:lang="en" title="A message in the WADL">This is added to the start of the generated application.wadl</doc>
</applicationDocs>

File: application-grammars.xml

Content:

<?xml version="1.0" encoding="UTF-8" ?>
<grammars xmlns="http://wadl.dev.java.net/2009/02" />

3. Run the maven command.

Go to the project folder and run the following command:

$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate

The files \target\classes\application.wadl (the WADL itself) and \target\classes\xsd0.xsd (the schema of the resources - it's used by the application.wadl) should be generated.

Edit and use them as you wish.

PS.: Bear in mind that this is a very simple use of the maven-wadl-plugin. It can do a lot more. To know it better, please refer to the zip file mentioned in the other answer (by Pavel Bucek).

Unapproachable answered 7/2, 2013 at 2:0 Comment(4)
Documentation is really lacking. Is the packagesResourceConfig supposed to the location of the classes with the actual endpoints?Kilovoltampere
@Kilovoltampere packagesResourceConfig is the java package where your resources (services) classes are located.Unapproachable
How does the xsd get generated? None is being produced.Creosote
Thanks for the well-documented tip on creating a WADL. I was having an issue trying to run the NetBeans sample 'CustomerDB' when deploying to TomEE Plume 7.0.4 since that setup would not auto-generate the WADL (ergo: missing WADL.) Off to fixing the next issue outside of WADL.Gallion
S
3

Yes, please see gerenate-wadl [1] sample from Jersey samples (look for maven-wadl-plugin).

[1] http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip

Stratosphere answered 10/5, 2012 at 11:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.