GroovyWS 和复杂请求

发布于 2024-09-10 23:06:31 字数 1120 浏览 6 评论 0原文

我遇到了使用 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。

I've faced with a problem of sending complex requests with GroovyWS.

This is sample request generated by 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>

the piece of groovy code:

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

So what I should pass instead of ?.

Thanks for you help.

-vova.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

久伴你 2024-09-17 23:06:31

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 认为类名实际上应该是什么。

GroovyWS dynamically creates classes for each of the argument types you need in order to pass data to the web service call. For instance, if the webservice call was:

public int passSomeArgs( Arg1Type a, Arg2Type b );

GroovyWS would dynamically create an Arg1Type class and an Arg2Type class, which you could access via a method on the proxy.

// 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" );  

You can then populate the arg1/arg2 instance with data and make your call:

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

Note, there are probably some namespaces involved in the classes being created. I used the CXF logging that was printed as GroovyWS was processing the WSDL to see what CXF thought the class names should actually be.

心房的律动 2024-09-17 23:06:31

非常感谢比尔。

我只是想为未来的读者添加一些信息。

要在 Grails 中打开 GroovyWS 的日志记录:

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

通过 Bill 提到的,您可以看到类的名称。

另一件事:参数可能有不同的类型。不是列表。这就是为什么它也应该被创建。

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

要检索新创建的对象的可用方法和字段,您可以使用 Groovy 反射:

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

仅此而已!

-沃瓦

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

醉态萌生 2024-09-17 23:06:31

谢谢!我让 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 << '[email protected]'
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

Thanks! I got GroovyWS working with a really complex webservice!

My steps: I turned on debug to get the root class, then did that reflection code to get inner classes, and go on setting properties and check if it is string or list.

And voilá!

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 << '[email protected]'
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文