Axis2的与Groovy中复合类型 [英] Axis2 with complexTypes in Groovy

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

问题描述

所以我有一对夫妇使用Groovy来处理复杂的计算正常ANT不能做(至少据我所知)ANT脚本。我试图通过使用Groovy的一个SOAP信封访问Axis2 Web服务。请求和响应是pretty简单,除了两个复杂类型属性(一个请求,一个在响应)。

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的肥皂。这是很容易使用,只需要简单的一个SoapClient的,并调用Web服务方法。不幸的是它不能处理复杂类型属性的要求,我需要:

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:自定义数据类型不能被使用与当前常规-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 ,javac的和$ GROOVY_HOME可用(如在的项目速成指南页面)。葡萄莫名其妙地检索常春藤,当我刚开始剧本(我有葡萄的经验,但我怀疑这是非常相似的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客户端(不包括在classpath中的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功能),在classpath中我有:

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香皂,我得到了错误。

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

所以我的问题是:如何通过ANT使用复杂类型参数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.

推荐答案

我终于想出了一个解决方案:常规 - 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") }
    }
  }
}

其中,状态模式复合类型其中包括一值属性(作为一个例子)。

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

println(response.myFunctionResponse.return)

给我由Web服务返回的对象。当然,标记的名称取决于WSDL。在我的情况下请求的响应被称为 myFunctionResponse ,其中有一个字段 NAME =回归,给我一个复杂类型对象。对象的字段可以根据在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

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

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