我可以使用 RESTeasy 获取 application.wadl 文件吗? [英] Can I get application.wadl file using RESTeasy?

查看:27
本文介绍了我可以使用 RESTeasy 获取 application.wadl 文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为 RESTful 服务获取 WADL 文件.我知道如果使用球衣,它可以作为 http://localhost:8080/application.wadl 使用.但我使用 RESTeasy.

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?

推荐答案

最新版本:

引用 第 49 章 RESTEasyWADL 支持:

49.1.RESTEasy WADL 对 Servlet 容器的支持
49.2.RESTEasy WADL 支持 Sun JDK HTTP Server
49.3.对 Netty 容器的 RESTEasy WADL 支持
49.4.对 Undertow 容器的 RESTEasy WADL 支持

RESTEasy 有自己的支持为其资源生成 WADL,并且它支持多种不同的容器.以下文字将向您展示如何在不同的容器中使用此功能.

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.

RESTEasy WADL 使用 ResteasyWadlServlet 来支持 servlet 容器.它可以注册到 web.xml 以启用 WADL 功能.下面是一个例子来展示web.xmlResteasyWadlServlet的用法:

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>

web.xml 中的上述配置展示了如何启用ResteasyWadlServlet 并将其映射到 /application.xml.然后可以从配置的 URL 访问 WADL:

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

<小时>

旧版本的解决方法

有一个变通方法:jersey 人员使用一个名为 maven-wadl-plugin 的 maven 插件,它也可以为使用 RESTEasy 编码的服务生成 WADL.


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.

这是如何使用它.

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

注意 baseUripackagesResourceConfig 元素.您必须更改它们以反映您的项目配置.您可能还想更改插件的版本(我使用的是 1.17).

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

创建 src/main/doc/ 文件夹并创建下面的两个文件.

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

文件:application-doc.xml

内容:

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

文件:application-grammars.xml

内容:

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

3.运行 maven 命令.

转到项目文件夹并运行以下命令:

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

文件 argetclassesapplication.wadl(WADL 本身)和 argetclassesxsd0.xsd(资源的架构 - 它被使用由 application.wadl) 生成.

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.: 请记住,这是 maven-wadl-plugin 的一个非常简单的用法.它可以做更多的事情.要更好地了解它,请参阅 http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip

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

这篇关于我可以使用 RESTeasy 获取 application.wadl 文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆