Groovy:在不使用 wsdl(如 curl)的情况下从信封创建和发送 SOAP 请求。

Groovy: Creating and sending SOAP request from envelope without using wsdl (like curl).

我从数据库中提取了大量 xml 个字符串,我想将它们中的每一个都包装到 SOAP 消息中并发送给收件人。我想使用 groovy 脚本来执行此操作,就像我使用 curl 执行此操作一样。这意味着我想避免使用 wsdl,而是将现有的 xml 字符串主体包装到 soap 信封中,然后将其发送到收件人的地址和端口。有什么办法可以用例如wslite 或任何其他 SOAP api for groovy?

您可以使用 HttpBuilder:

HTTPBuilder http = new HTTPBuilder( 'http://some.com' )
http.request( POST ){
  uri.path = '/somepath'
  requestContentType = URLENC
  body = [ your:json, envelope:here ]
  headers.Accept = 'application/json'

  response.success = { resp, json ->
    println json
  } 
}

或普通 UrlConnection:

HttpURLConnection connection = new URL( 'http://some.com/somepath' ).openConnection()
connection.requestMethod = 'POST'
connection.doOutput = true
connection.outputStream.withWriter{ it << "{ some:value }" } // here comes your envelop
connection.connect()
String result
connection.content.withReader{ result = new JsonSlurper().parseText( it.readLine() ).someKey }
log.info "got result $result"