8

我遇到了使用 GroovyWS 发送复杂请求的问题。

这是由 soapUI 生成的示例请求:

<soapenv:Envelope 
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:dex="http://www.temp.com/com/dex" 
>
 <soapenv:Header/>
 <soapenv:Body>
  <dex:executeRequest>
     <!--Optional:-->
     <a>?</a>
     <!--Optional:-->
     <b>?</b>
     <!--Optional:-->
     <parameters>
        <!--Zero or more repetitions:-->
        <parameter>
           <!--Optional:-->
           <key>?</key>
           <!--Optional:-->
           <value>?</value>
        </parameter>
     </parameters>
     <!--Optional:-->
     <c>?</c>
     <!--Optional:-->
     <d>?</d>
  </dex:feedrequest>
 </soapenv:Body>
</soapenv:Envelope>

一段时髦的代码:

def proxy = webService.getClient(grailsApplication.config.ws.endpoint);
proxy.processdRequest(?);

那么我应该通过什么而不是.

谢谢你的帮助。

-vova。

4

3 回答 3

6

GroovyWS 为您需要的每个参数类型动态创建类,以便将数据传递给 Web 服务调用。例如,如果 web 服务调用是:

public int passSomeArgs( Arg1Type a, Arg2Type b );

GroovyWS 将动态创建 Arg1Type 类和 Arg2Type 类,您可以通过代理上的方法访问它们。

// this will instantiate an Arg1Type for you
def arg1 = proxy.create( "ns1.ns2.Arg1Type" );  
// this will instantiate an Arg2Type for you
def arg2 = proxy.create( "ns1.ns2.Arg2Type" );  

然后,您可以使用数据填充 arg1/arg2 实例并进行调用:

int ret = proxy.passSomeArgs( arg1, arg2 );

请注意,正在创建的类中可能涉及一些命名空间。我使用了在 GroovyWS 处理 WSDL 时打印的 CXF 日志记录,以查看 CXF 认为类名实际上应该是什么。

于 2010-07-25T06:34:07.613 回答
5

Many thanks Bill.

I just want to add some info for future readers.

To turn on logging for GroovyWS in Grails:

log4j = {
   debug 'grails.app',
         'groovyx.net.ws',
         'org.apache.cxf'
}

With this as mentioned Bill you can see the names of the classes.


One more thing: parameters may have different type. Not List<?>. That's why it should be created too.

def params = proxy.create('com.temp.feeds.FeedRequestType$Parameters');

To retrieve available methods and fields for newly created objects you can use Groovy reflection:

params.class.methods.each{
        println it;
}
params.class.fields.each{
        println it;
}

That's all!

-vova

于 2010-07-28T07:58:19.420 回答
3

谢谢!我让 GroovyWS 与一个非常复杂的 Web 服务一起工作!

我的步骤:我打开调试以获取根类,然后执行反射代码以获取内部类,然后继续设置属性并检查它是字符串还是列表。

瞧!

def proxy = new WSClient(wsdl,this.class.classLoader)
proxy.initialize()

def f2bCobranca = proxy.create("br.com.f2b.soap.wsbilling.F2BCobranca") //got with debug on

//Show me inner classes of root class
f2bCobranca.class.fields.each { log.debug it }
f2bCobranca.class.methods.each { log.debug it }

f2bCobranca.cobranca = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Cobranca')
f2bCobranca.cobranca.demonstrativo << 'teste' //it's a list!
f2bCobranca.cobranca.sacadorAvalista = 'teste jose'
f2bCobranca.cobranca.desconto = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Cobranca$Desconto')
f2bCobranca.cobranca.multa = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Cobranca$Multa')

def sacado1 = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Sacado')
sacado1.nome = "teste ${new Date()}"
sacado1.email << 'teste@wanswins.com.br'
sacado1.endereco = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Sacado$Endereco')
sacado1.telefone = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Sacado$Telefone')
sacado1.telefoneCom = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Sacado$TelefoneCom')
sacado1.telefoneCel = proxy.create('br.com.f2b.soap.wsbilling.F2BCobranca$Sacado$TelefoneCel')
sacado1.cpf = ''
sacado1.cnpj = ''
sacado1.observacao = ''
f2bCobranca.sacado << sacado1  

def retorno = proxy.RegisterWSBilling(f2bCobranca)
log.debug retorno
于 2010-09-05T07:55:19.323 回答