java 从现有的 CXF 休息服务生成 wadl

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10807668/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 02:40:19  来源:igfitidea点击:

Generate wadl from existing CXF rest service

javacxfjax-rs

提问by Gandalf StormCrow

I have working JAX-RS service implemented with CXF. How can I generate wadl? Or is there something like with jersey http://path.to.your/restapp/application.wadlout there already? is there a maven plugin just like for wsdl, java to wsdl? I've searched for answers couldn't find.

我有使用 CXF 实现的 JAX-RS 服务。我怎样才能生成wadl?或者已经有像球衣 http://path.to.your/restapp/application.wadl这样的东西了?有没有像 wsdl、java 到 wsdl 一样的 maven 插件?我搜索过没有找到的答案。

回答by Daniel Kulp

If you are using a recent version of CXF, just hit the service with a ?_wadl parameter.

如果您使用的是最新版本的 CXF,只需使用 ?_wadl 参数点击该服务。

回答by Raman Yelianevich

There are a lot of possible ways to generate WADL using CXF:

使用 CXF 生成 WADL 有很多可能的方法:

  1. You can sent REST call (using Postman, for example) to the base REST URL and it will automatically create WADL for all services available from there. It can help to structure REST API. For example:
  2. CXF 3.0.0 and 2.7.11 introduce java2wadl plugin for generating WADL at the build time. Details clould be found here.
  3. All available feature of CXF regarding WADL are located in CXF docs.
  1. 您可以将 REST 调用(例如使用Postman)发送到基本 REST URL,它会自动为从那里可用的所有服务创建 WADL。它可以帮助构建 REST API。例如:
  2. CXF 3.0.0 和 2.7.11 引入了 java2wadl 插件,用于在构建时生成 WADL。详细信息可在此处找到。
  3. CXF 关于 WADL 的所有可用功能都位于CXF 文档中

After WADL has been generated it would be nice to transform XML to more readable form. One of the solutions that I found was XSL usage to generate HTML. I have used XSL from github project. Steps to link XSL to XML and generate pretty HTML report:

在生成 WADL 之后,最好将 XML 转换为更易读的形式。我发现的解决方案之一是使用 XSL 来生成 HTML。我使用了github 项目中的XSL 。将 XSL 链接到 XML 并生成漂亮的 HTML 报告的步骤:

  1. Download wadl.xsl;
  2. Copy wadl.xsl to the folder that contains wadl.xml file that was generated by CXF;
  3. Add required header to wadl.xml to the very beginning of the file:

    <?xml version="1.0" encoding="UTF-8"?>

    <?xml-stylesheet type="text/xsl" href="wadl.xsl"?>

  4. Replace in wadl.xml generated <application ...>header using <wadl:application xmlns:wadl="http://wadl.dev.java.net/2009/02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd ">

  5. Add to every tag 'wadl' namespace. For example:

    <resource>-> <wadl:resource>

    </resource>-> </wadl:resource>

  6. Open wadl.xml using IE

  7. You will get something like this (example_wadl.xml from github project): HTML page generated from WADL file

  1. 下载wadl.xsl;
  2. 将 wadl.xsl 复制到包含由 CXF 生成的 wadl.xml 文件的文件夹;
  3. 将所需的 wadl.xml 标头添加到文件的最开头:

    <?xml version="1.0" encoding="UTF-8"?>

    <?xml-stylesheet type="text/xsl" href="wadl.xsl"?>

  4. 使用 wadl.xml 替换生成的<application ...>标头 <wadl:application xmlns:wadl="http://wadl.dev.java.net/2009/02" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://wadl.dev.java.net/2009/02 wadl.xsd ">

  5. 添加到每个标签 'wadl' 命名空间。例如:

    <resource>-> <wadl:resource>

    </resource>-> </wadl:resource>

  6. 使用 IE 打开 wadl.xml

  7. 你会得到这样的东西(来自github项目的example_wadl.xml ): 从 WADL 文件生成的 HTML 页面