I need to get WADL file for RESTful service. I know that in case using jersey it's available as http://localhost:8080/application.wadl
. But I use RESTeasy.
Can I do the same in my framework case?
I need to get WADL file for RESTful service. I know that in case using jersey it's available as http://localhost:8080/application.wadl
. But I use RESTeasy.
Can I do the same in my framework case?
Quoting Chapter 49. RESTEasy WADL Support:
Chapter 49. RESTEasy WADL Support
49.1. RESTEasy WADL Support for Servlet Container
49.2. RESTEasy WADL support for Sun JDK HTTP Server
49.3. RESTEasy WADL support for Netty Container
49.4. RESTEasy WADL Support for Undertow ContainerRESTEasy has its own support to generate WADL for its resources, and it supports several different containers. The following text will show you how to use this feature in different containers.
49.1. RESTEasy WADL Support for Servlet Container
RESTEasy WADL uses
ResteasyWadlServlet
to support servlet container. It can be registered intoweb.xml
to enable WADL feature. Here is an example to show the usages ofResteasyWadlServlet
inweb.xml
:<servlet> <servlet-name>RESTEasy WADL</servlet-name> <servlet-class>org.jboss.resteasy.wadl.ResteasyWadlServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>RESTEasy WADL</servlet-name> <url-pattern>/application.xml</url-pattern> </servlet-mapping>
The preceding configuration in
web.xml
shows how to enableResteasyWadlServlet
and mapped it to/application.xml
. And then the WADL can be accessed from the configured URL:/application.xml
There is a workaround: a maven plugin called maven-wadl-plugin
by the jersey folks that also works to generate WADL for services coded using RESTEasy.
Here's how to use it.
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 baseUri
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).
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" />
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 in http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip
WADL generation in RESTeasy is a feature not yet implemented. If you want it go vote for it.
https://issues.jboss.org/browse/RESTEASY-166
See RESTEasy WADL Support (3.1.0). The snipped below is copied from there
<servlet>
<servlet-name>RESTEasy WADL</servlet-name>
<servlet-class>org.jboss.resteasy.wadl.ResteasyWadlServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RESTEasy WADL</servlet-name>
<url-pattern>/application.xml</url-pattern>
</servlet-mapping>
This uses the ResteasyWadlServlet
and will make the WADL accessible at /application.xml
.
Note: Rex and Jaskirat have already mentioned previously that RESTEASY-166 was used to manage the implementation for this feature. It seems this was completed in 3.0.14.
we can generate a wadl with the help of maven project with POM.XML
https://issues.jboss.org/browse/RESTEASY-166 check the comments here..!!