Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WADL Generation Tool

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.

like image 744
Sven Malvik Avatar asked Feb 28 '12 17:02

Sven Malvik


People also ask

What is WADL and WSDL?

WADL is equivalent to SOAP's web services description language. WSDL is a machine-readable description with the current version of 2.0. 05. It is lightweight, easy to understand and write as compared to WSDL. Difficult to understand and write as compared to WADL.

Can swagger generate WADL?

If you add a Swagger specification, SoapUI Open Source automatically converts it to WADL and work with your service as if it had a WADL definition.

What is WADL in API?

The Web Application Description Language (WADL) is a machine-readable XML description of HTTP-based web services. WADL models the resources provided by a service and the relationships between them. WADL is intended to simplify the reuse of web services that are based on the existing HTTP architecture of the Web.


1 Answers

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).

like image 199
acdcjunior Avatar answered Oct 02 '22 12:10

acdcjunior