Groovy 中具有复杂类型的 Axis2 [英] Axis2 with complexTypes in Groovy

查看:29
本文介绍了Groovy 中具有复杂类型的 Axis2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有几个 ANT 脚本使用 Groovy 来处理普通 ANT 无法执行的复杂计算(至少是 afaik).我正在尝试通过 Groovy 使用 SOAP 信封访问 Axis2 Web 服务.请求和响应非常简单,除了两个 complexType 属性(一个在请求中,一个在响应中).

So I'm having a couple of ANT scripts using Groovy to process complex calculations normal ANT can't do (at least afaik). I'm trying to access an Axis2 web service using a SOAP-envelope via Groovy. The request and response is pretty simple, except for two complexType attributes (one in the request, one in the response).

我偶然发现的第一件事是Groovy Soap.它非常易于使用,您只需实例化一个 SoapClient 并调用 Web 服务方法.不幸的是,它无法处理请求中的 complexType 属性,这是我需要的:

The first thing I've stumbled across was Groovy Soap. It is quite easy to use, you simply instantiate a SoapClient and call the web service method. Unfortunately it cannot handle complexType attributes in the request, which I need:

当前限制:

....

4:在当前 groovy-1.0 版本中使用 Groovy SOAP 模块时,无法在客户端处理自定义数据类型.

4: Custom data types cannot be processed on client side when using the Groovy SOAP module with the current groovy-1.0 release.

然后我阅读了很多关于 GroovyWS 的内容.我在 user.home 中创建了我的 Grape 配置文件,javac 和 $GROOVY_HOME 可用(基本上按照 项目快速指南页面).当我第一次启动脚本时,Grape 以某种方式检索了 Ivy(我没有使用 Grape 的经验,但我怀疑它与 Maven 非常相似).

Then I've read a lot about GroovyWS. I created my Grape config file in my user.home, javac and $GROOVY_HOME are available (basically did everything as described on the project quick guide page). Grape somehow retrieved Ivy, when I first started the script (I have no experience with Grape, but I suspect it's very similar to Maven).

然后开始我的简单脚本:

Then started my simple script:

@Grab(group='org.codehaus.groovy.modules', module='groovyws',version='0.5.2')
import groovyx.net.ws.WSClient
proxy = new WSClient("http://127.0.0.1/axis2/services/ReleaseService?wsdl", this.class.classLoader)
proxy.initialize()

不幸的是,我什至无法初始化 Web 客户端(类路径中没有 Groovy Soap 库):

Unfortunately I couldn't even initialize the web client (without the Groovy Soap library in the classpath):

SEVERE: Could not compile java files for http://127.0.0.1/axis2/services/ReleaseService?wsdl.
Caught: java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated: javax.xml.bind.JAXBException: "com.intershop.qa.tae.ws.xsd" doesnt contain ObjectFactory.class or jaxb.index java.lang.IllegalStateException: Unable to create JAXBContext for generated packages: Provider com.sun.xml.bind.v2.ContextFactory could not be instantiated [...]

在我的类路径中使用 Groovy Soap 库(它似乎重载了 GroovyWS 的某些功能):

With the Groovy Soap library (which seems to overload some of GroovyWS' functionality) in the classpath I've got:

Caught: java.lang.NoSuchMethodError: javax.wsdl.xml.WSDLReader.readWSDL(Ljavax/wsdl/xml/WSDLLocator;Lorg/w3c/dom/Element;)Ljavax/wsdl/Definition; java.lang.NoSuchMethodError:

这看起来与我最初使用 Groovy Soap 时遇到的错误非常相似.

which looks very similar to the error I've got when I was using Groovy Soap in the first place.

所以我的问题是:如何通过 ANT 使用 complexType 参数与 Axis2 Web 服务进行通信.我不仅限于 Groovy,而且出于部署原因(约 50 个 VM 快照),我想要一些简单的东西.一个 Java 客户端可以工作,但由于部署相当费力(特别是如果我想在将来更改内容时),我需要一些更接近 ANT 且更易于部署的东西.

So my question is: How can I communicate with an Axis2 web service using complexType parameters via ANT. I'm not limited to Groovy only, but for deployment reasons (~50 VM snapshots) I want something simple. A Java client worked, but since the deployment is quite some effort (especially if I want to change stuff in the future) I need something which is closer to ANT and easier to deploy.

预先感谢您对其他技术的建议或为我的 GroovyWS 实现修复想法.

Thanks in advance for suggestions of other technologies or fix ideas for my GroovyWS implementation.

推荐答案

我终于想出了一个解决方案:groovy-wslight 实际上解决了我的问题,并且最终能够轻松部署并毫无问题地访问 Web 服务.

I finally came up with a solution: groovy-wslight actually solved my problem and was finally able to deploy easily and access the web service without problems/exceptions.

脚本:

@Grab(group='com.github.groovy-wslite', module='groovy-wslite', version='0.7.1')
import wslite.soap.*
def client = new SOAPClient("http://127.0.0.1/axis2/services/ReleaseService")
def response = client.send  {
  body {
    myFunction(xmlns:"http://my.namespace.com") {
       stringParameter("6.3.0.0")
       status() { value("default") }
       mode() { value("full") }
    }
  }
}

其中 statusmodecomplexTypes,它们由一个值"属性组成(例如).

Where status and mode are complexTypes which consist of one "value" attribute (as an example).

println(response.myFunctionResponse.return)

给我 Web 服务返回的对象.当然,令牌的名称取决于 WSDL.在我的例子中,请求的响应称为 myFunctionResponse,它有一个字段 name="return" 并给我一个 complexType 对象.可以根据 WSDL 中给出的名称检索对象的字段:

gives me the object returned by the web service. Of course the names of the tokens depend on the WSDL. In my case the response of the request is called myFunctionResponse, which has a field name="return" and gives me a complexType object. The fields of the object can be retrieved according to the names given in the WSDL:

println(response.myFunctionResponse.return.location) // gives me the field value of the field "location" for my complexType

这篇关于Groovy 中具有复杂类型的 Axis2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆