简体   繁体   English

groovy Web服务客户端

[英]groovy web service client

I need to write a web service client in Groovy. 我需要在Groovy中编写一个Web服务客户端。 The author of the web service has proposed various unappealing blobs of Java code that I could use to call the service from my Grails application. 该Web服务的作者提出了各种吸引人的Java代码,我可以使用它们从Grails应用程序中调用该服务。

At this point, I think it might be better if I just ask them to give me the WSDL and I'll take care of the client code myself. 在这一点上,我认为如果我只要求他们给我WSDL,我会自己处理客户端代码,那可能会更好。 I'm looking for suggestions about the best way to go about writing a Groovy web service client using only a WSDL document? 我正在寻找有关仅使用WSDL文档编写Groovy Web服务客户端的最佳方法的建议?

I expect most suggestions will involve using some tool to generate a client-side API that I'll call from my Grails app. 我希望大多数建议都涉及使用一些工具来生成客户端API,我将从Grails应用程序中调用该API。 If so, then it's important that I can integrate generation of this API into a Grails build, because the WSDL document will probably change frequently. 如果是这样,那么将这个API的生成集成到Grails构建中就很重要,因为WSDL文档可能会经常更改。

I've looked at using GroovyWS which provides a very simple way of calling web services. 我研究过使用GroovyWS ,它提供了一种非常简单的调用Web服务的方式。 However, it seems to lack any concept of a contract which concerns me from the point-of-view of testing. 但是,从测试的角度来看,它似乎缺少任何与我有关的合同概念。 I would like to define a contract (interface) for the web service, for which I provide a real implementation that the app will use and a mock implementation that my unit tests will use. 我想为Web服务定义一个合同(接口),为此我提供了应用程序将使用的真实实现以及单元测试将使用的模拟实现。

Given your desire for more stability than the very dynamic GroovyWS, I'd suggest the easy way: 考虑到您想要比动态GroovyWS更高的稳定性,我建议采用以下简单方法:

Use JAX-WS to generate a Java client , compile that and use it from Groovy. 使用JAX-WS 生成Java客户端 ,进行编译并从Groovy中使用它。 It's all statically typed and the generate Java source is reasonably clean (definitely much better than older WS client frameworks such as Axis 1). 所有这些都是静态类型的,并且生成的Java源代码相当干净(绝对比诸如Axis 1之类的早期WS客户端框架要好得多)。

Of course that would require that you have access to the WSDL. 当然,这将要求您有权访问WSDL。

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

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