我可以使用 RESTeasy 获取 application.wadl 文件吗?

发布于 2024-10-22 01:15:33 字数 146 浏览 7 评论 0原文

我需要获取 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

空气里的味道 2024-10-29 01:15:33

最新版本:

引用 第 49 章 RESTEasy WADL 支持:

第 49 章.RESTEasy WADL 支持

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

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

49.1。对 Servlet 容器的 RESTEasy WADL 支持

RESTEasy WADL 使用 ResteasyWadlServlet 来支持 servlet 容器。可以将其注册到 web.xml 中以启用 WADL 功能。以下示例展示了 web.xmlResteasyWadlServlet 的用法:

;
  RESTEasy WADL
  org.jboss.resteasy.wadl.ResteasyWadlServlet



  RESTEasy WADL
  /application.xml

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

<前><代码>/application.xml


旧版本的解决方法

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

以下是如何使用它。

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>

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

2. 创建一个/doc文件夹并添加一些文件。

创建 src/main/doc/ 文件夹并创建以下两个文件。

文件: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 命令。

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

$ mvn compile com.sun.jersey.contribs:maven-wadl-plugin:generate

文件 \target\classes\application.wadl (WADL 本身)和 \target\classes\xsd0.xsd (应该生成资源的架构 - 它由 application.wadl 使用。

根据需要编辑和使用它们。

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

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

黑白记忆 2024-10-29 01:15:33

RESTeasy 中的 WADL 生成功能尚未实现。如果你想要的话,就去投票吧。

https://issues.jboss.org/browse/RESTEASY-166

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

相守太难 2024-10-29 01:15:33

请参阅 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>

它使用 ResteasyWadlServlet 并使 WADL 可在 /application.xml 中访问。

注意
Rex 和 Jaskirat 之前已经提到 RESTEASY-166 用于管理这个功能。看来这已经在 3.0.14 完成了。

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.

往日情怀 2024-10-29 01:15:33

我们可以在 maven 项目的帮助下使用 POM.XML

https://issues.jboss 生成一个 wadl。 org/browse/RESTEASY-166 检查这里的评论..!!

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文