我可以使用RESTeasy获取application.wadl文件吗? [英] Can I get application.wadl file using RESTeasy?
问题描述
我需要获取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章.RESTEasy WADL支持
49.1。 RESTEasy WADL支持Servlet容器
49.2。 RESTEasy WADL对Sun JDK HTTP Server的支持
49.3。 RESTEasy WADL对Netty容器的支持
49.4。 RESTEasy WADL支持Undertow容器
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.xml中显示
: ResteasyWadlServlet
的用法的示例
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
旧版本的解决方法
有一种解决方法:由泽西人提供的名为 maven-wadl-plugin
的maven插件也可用于为服务生成WADL使用RESTEasy编码。
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>
注意 baseUri
和 packagesResourceConfig
元素。您必须更改它们以反映项目的配置。您可能还想更改插件的版本(我使用的是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
文件 \\\getget \classes \application.wadl
(WADL本身)和 \\\ target \classes \ xsd0。应该生成xsd
(资源的模式 - 它由application.wadl使用)。
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:请记住,这是对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屋!