Can I get application.wadl file using RESTeasy?

安稳与你 提交于 2019-11-27 21:31:06

Latest versions:

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 Container

RESTEasy 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 into web.xml to enable WADL feature. Here is an example to show the usages of ResteasyWadlServlet in web.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 enable ResteasyWadlServlet and mapped it to /application.xml. And then the WADL can be accessed from the configured URL:

/application.xml

Workaround for Older versions

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.

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

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

jaskirat Singh

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!