Generate wadl from existing CXF rest service

别说谁变了你拦得住时间么 提交于 2019-12-22 08:41:57

问题


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.wadl out there already? is there a maven plugin just like for wsdl, java to wsdl? I've searched for answers couldn't find.


回答1:


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




回答2:


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

  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:
    • http://app.com/purchase/?_wadl - create WADL for purchase API
    • http://app.com/profile/?_wadl - create WADL for user profile API
  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.

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:

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



来源:https://stackoverflow.com/questions/10807668/generate-wadl-from-existing-cxf-rest-service

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!