简体   繁体   English

消费不提供WADL的REST服务

[英]Consuming REST service that doesn't offer WADL

I need to work with a REST service that has a relatively simple and fixed (meaning predictably not very variant structure), yet I can't find a WADL anywhere on their site. 我需要使用一个具有相对简单和固定的REST服务(可以预期不是非常可变的结构),但是在他们站点上的任何地方都找不到WADL。 I have previously worked with SOAP services, which had a decent WSDL and I used it to generate my Java classes to which my client app was marshalling the service data using Axiom2. 我以前曾使用过具有不错的WSDL的SOAP服务,并使用它来生成Java类,客户端应用程序使用Axiom2将Java类编组到该Java类。

My question is: is there an easy way to reverse engineer a WADL with which to easily generate corresponding Java classes if the site is lacking one, using some implementation of JAX-RS (eg Jersey)? 我的问题是:是否有一种简单的方法可以对WADL进行逆向工程,如果站点缺少Java,则可以使用JAX-RS的某些实现(例如Jersey)轻松地生成相应的Java类? Another way to ask it is: given only a REST service, no WADL, and some form of JAX-RS, what is the easiest way to generate marshalled classes on the client side? 提出此问题的另一种方法是:仅提供REST服务,不提供WADL,并且使用某种形式的JAX-RS,在客户端生成编组类的最简单方法是什么?

Currently, as the structure is simple, I do it the hard way of using straight DOM from Java SE ( org.w3c.dom ) to parse the document. 当前,由于结构很简单,我很难用Java SE( org.w3c.dom )中的org.w3c.dom DOM来解析文档。 It works fine but I do not like all the traversing I have to do within the document structure and I feel like I reinvented the wheel. 它工作正常,但是我不喜欢在文档结构中进行所有遍历,感觉就像是在重新发明轮子。 I am sure there is a more elegant way. 我敢肯定有一种更优雅的方法。

If you're just doing this once why not just do it by hand? 如果您只做一次,为什么不手工做呢? If you need to do this regularly then you may be out of luck wrt WADL (as an aside see: https://softwareengineering.stackexchange.com/questions/133145/should-i-use-wadl-to-describe-my-restful-api ). 如果您需要定期执行此操作,则可能对WADL感到不走运(顺便一提,请参阅: https : //softwareengineering.stackexchange.com/questions/133145/should-i-use-wadl-to-describe-my- restful-api )。

Are you just trying to generate Java classes for the DTOs from the service? 您是否只是想从服务为DTO生成Java类? In this case you could take some sample XML from the service and use this to generate a possible XSD (maybe using trang ). 在这种情况下,您可以从服务中获取一些示例XML,并使用它生成可能的XSD(也许使用trang )。 Then use XJC to generate the corresponding Java classes. 然后使用XJC生成相应的Java类。

If the REST service is implemented in Jersey, Jersey should auto generate the WADL at runtime. 如果REST服务在Jersey中实现,则Jersey应该在运行时自动生成WADL。 The default location is http://server:port/appcontextroot/application.wadl . 默认位置为http://server:port/appcontextroot/application.wadl If the REST service uses other implementation such as RESTEasy, you are out of luck. 如果REST服务使用其他实现(例如RESTEasy),那么您很不走运。 https://issues.jboss.org/browse/RESTEASY-166 https://issues.jboss.org/browse/RESTEASY-166

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM