如何在 JAVA 中为 WSDL 中定义的 REST 生成 RESTful 客户端

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

How to generate RESTful client in JAVA for REST defined in WSDL

javaweb-servicesrestwsdl

提问by Milan

I know that WSDL is for defining SOAP based web services but in most of the WSDLs I saw on net, in the WSDL is defined also RESTful "web service"-http:binding.

我知道 WSDL 用于定义基于 SOAP 的 Web 服务,但在我在网上看到的大多数 WSDL 中,WSDL 中还定义了 RESTful“Web 服务”-http:binding。

To generate client for the SOAP I used wsimport tool from JAX-WS (it also generates client classes for the REST but it doesnt work).

为了为 SOAP 生成客户端,我使用了 JAX-WS 的 wsimport 工具(它还为 REST 生成客户端类,但它不起作用)。

So the question is, how to generate REST client based on the WSDL?

那么问题来了,如何基于WSDL生成REST客户端呢?

回答by Darrel Miller

I've never heard of anyone using WSDL for generating REST clients. WADL yes, but not WSDL.

我从未听说过有人使用 WSDL 来生成 REST 客户端。WADL 是的,但不是 WSDL。

Anyway, generating clients for REST services does not make sense. If you think you want to do that then you are missing the benefits of REST and trying to follow the REST constraints is going to make you do extra work for nothing.

无论如何,为 REST 服务生成客户端是没有意义的。如果您认为您想这样做,那么您就错过了 REST 的好处,而尝试遵循 REST 约束将使您白费力气地做额外的工作。

回答by Adam Gent

Actually you can auto-generate a SOAP like stub for JAX-RS but it uses WADL which I believe is a WSDL variant.

实际上,您可以为 JAX-RS 自动生成类似 SOAP 的存根,但它使用 WADL,我认为这是 WSDL 变体。

Apache CXF does thisand if that doesn't work for you it will also automatically create SOAP endpoints and SOAP clients.

Apache CXF 会这样做,如果这对您不起作用,它还会自动创建 SOAP 端点和 SOAP 客户端。

回答by GG.

You can use RestDescribeto generate and compile WSDL, you can generate clients in php, ruby, python, java and C# using this. It generates clean code and there is a good change that you have to tweak it a bit after code generation, you can find good documentation and underlying thoughts behind the tool here.

您可以使用RestDescribe生成和编译 WSDL,您可以使用它生成 php、ruby、python、java 和 C# 中的客户端。它生成干净的代码,并且有一个很好的更改,您必须在代码生成后对其进行一些调整,您可以在此处找到该工具背后的良好文档和基本思想。

There are few interesting and useful WADL toolsmentioned on wintermute.

在 Wintermute 上提到的有趣和有用的WADL 工具很少。

回答by Jacek Cz

IBM Developer network: WSDL2 can describe REST services.

IBM 开发人员网络:WSDL2 可以描述 REST 服务。

I think in programmers mainstream is holy war SOAP (classic) - REST services. Nobody want this war, these conceptions can coexist - i see this is opinion not only from my and few people, but has grooving support in standards.

我认为程序员的主流是圣战 SOAP(经典)- REST 服务。没有人想要这场War,这些概念可以共存 - 我认为这不仅是我和少数人的意见,而且在标准中得到了广泛的支持。