Groovy的SOAP请求XML与MarkupBuilder的
问题描述:
我有我试图在Groovy使用MarkupBuilder的创建以下SOAP请求Groovy的SOAP请求XML与MarkupBuilder的
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<SignRequest xmlns="http://www.tw.com/tsswitch">
<InputType>string</InputType>
<JobType>string</JobType>
<OutputType>string</OutputType>
<Document>base64Binary</Document>
<SenderTag>string</SenderTag>
<ReceiverTag>string</ReceiverTag>
<NrOfItems>int</NrOfItems>
<SignerIdentifier>string</SignerIdentifier>
<AgreementIdentifier>string</AgreementIdentifier>
<ClientData>string</ClientData>
</SignRequest>
</soap:Body>
</soap:Envelope>
builder.encoding = "UTF-8"
def xmlBody = builder.bind {
mkp.xmlDeclaration()
mkp.declareNamespace(xsd:("http://www.w3.org/2001/XMLSchema"),xsi:("http://www.w3.org/2001/XMLSchema-instance"),soap:("http://schemas.xmlsoap.org/soap/envelope/"))
'soap:Envelope'() {
"soap:Body"() {
"SignRequest"(xmlns:"http://www.tw.com/tsswitch"){
"InputType"(){'GENERIC'}
"JobType"(){'CADESA'}
"OutputType"(){'SMIME'}
"Document"(){file.data}
"SenderTag"(){'US'}
"ReceiverTag"(){'US'}
"NrOfItems"(){1}
"SignerIdentifier"(){null}
"AgreementIdentifier"(){null}
}
}
}
}
Butam得到下面的响应从服务器
Server was unable to read request. ---> There is an error in XML document (2, 400). ---> Input string was not in a correct format.
有人可以帮我修复xmlBody
?
答
我能找出我自己
def xmlBody = builder.bind {
mkp.xmlDeclaration()
mkp.declareNamespace(xsd:("http://www.w3.org/2001/XMLSchema"),xsi:("http://www.w3.org/2001/XMLSchema-instance"),soap:("http://schemas.xmlsoap.org/soap/envelope/"))
'soap:Envelope'() {
"soap:Body"() {
"SignRequest"(xmlns:"http://www.tw.com/tsswitch"){
"InputType"('GENERIC')
"JobType"('CADESA')
"OutputType"('SMIME')
"Document"(file.data)
"SenderTag"('US')
"ReceiverTag"('US')
"NrOfItems"(1)
"SignerIdentifier"(null)
"AgreementIdentifier"(null)
}
}
}
}
你并不需要周围的标签名称的报价然后将看起来更优雅,'代码数据,数据code' – Rao
cool..thanks为知识共享...我不知道 – RanPaul
可能是这个示例有助于更好地形象化 - http://*.com/questions/42352565/groovy-script-to-read-and-transform-xml/42359005#42359005 – Rao