Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
181 views
Welcome To Ask or Share your Answers For Others

1 Answer

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 argetclassesapplication.wadl (the WADL itself) and argetclassesxsd0.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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...