java 我可以使用 RESTeasy 获取 application.wadl 文件吗?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5301744/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Can I get application.wadl file using RESTeasy?
提问by Tioma
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.
我需要为 RESTful 服务获取 WADL 文件。我知道如果使用球衣,它可以作为http://localhost:8080/application.wadl
. 但我使用 RESTeasy。
Can I do the same in my framework case?
我可以在我的框架案例中做同样的事情吗?
采纳答案by acdcjunior
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 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
第 49 章 RESTEasy WADL 支持
49.1. RESTEasy WADL 对 Servlet 容器的支持
49.2。RESTEasy WADL 支持 Sun JDK HTTP Server
49.3。RESTEasy WADL 支持 Netty Container
49.4。对 Undertow 容器的 RESTEasy WADL 支持RESTEasy 有自己的支持为其资源生成 WADL,并且它支持多种不同的容器。下面的文字将向您展示如何在不同的容器中使用此功能。
49.1. RESTEasy WADL 对 Servlet 容器的支持
RESTEasy WADL 用于
ResteasyWadlServlet
支持 servlet 容器。它可以注册到web.xml
启用 WADL 功能。下面是一个例子来展示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:/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.
有一个解决方法:一个maven-wadl-plugin
由球衣人员调用的 maven 插件,它也可以为使用 RESTEasy 编码的服务生成 WADL。
Here's how to use it.
这是如何使用它。
1. Add this to your pom.xml
:
1. 将此添加到您的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).
注意baseUri
和packagesResourceConfig
元素。您必须更改它们以反映您的项目配置。您可能还想更改插件的版本(我使用的是 1.17)。
2. Create a /doc folder and add some files.
2. 创建一个 /doc 文件夹并添加一些文件。
Create the src/main/doc/
folder and create the two files below.
创建src/main/doc/
文件夹并创建下面的两个文件。
File: application-doc.xml
文件:应用程序-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
文件: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.
3.运行maven命令。
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.
应该生成文件\target\classes\application.wadl
(WADL 本身)和\target\classes\xsd0.xsd
(资源的架构 - 它由 application.wadl 使用)。
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
PS.: 请记住,这是 maven-wadl-plugin 的一个非常简单的使用。它可以做更多的事情。要更好地了解它,请参阅http://search.maven.org/remotecontent?filepath=com/sun/jersey/samples/generate-wadl/1.12/generate-wadl-1.12-project.zip 中的 zip 文件
回答by Rex Sheridan
WADL generation in RESTeasy is a feature not yet implemented. If you want it go vote for it.
RESTeasy 中的 WADL 生成功能尚未实现。如果你想要它,就去投票吧。
回答by Kariem
See RESTEasy WADL Support(3.1.0). The snipped below is copied from there
请参阅RESTEasy WADL 支持(3.1.0)。下面的剪辑是从那里复制的
<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
.
这将使用ResteasyWadlServlet
和 将使 WADL 可访问/application.xml
。
Note: Rex and Jaskirat have already mentioned previously that RESTEASY-166was used to manage the implementation for this feature. It seems this was completed in 3.0.14.
注意:Rex 和 Jaskirat 之前已经提到RESTEASY-166用于管理此功能的实现。这似乎是在 3.0.14 中完成的。
回答by jaskirat Singh
we can generate a wadl with the help of maven project with POM.XML
我们可以借助带有 POM.XML 的 maven 项目生成一个 wadl
https://issues.jboss.org/browse/RESTEASY-166check the comments here..!!
https://issues.jboss.org/browse/RESTEASY-166检查这里的评论..!!