我有一个场景,REST服务在后台调用SOAP Web服务。我正在寻找一种方法来构造和XML文件(将成为SOAP的请求)与URL中的一些参数。
从网址获取电话
http://myurl/changeAddress?id=1001&name=Steve&salary=3
SOAP webserivce的XML请求:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:unk="http://unknown.namespace/">
<soapenv:Header/>
<soapenv:Body>
<unk:changeAddress>
<arg0>1001</arg0>
<arg1>Steve</arg1>
</unk:changeAddress>
</soapenv:Body>
</soapenv:Envelope>
我已经尝试过MLE,我可以从URL中提取键值。但不确定如何从这些参数构造XML。
任何指针都将受到赞赏。
答案 0 :(得分:0)
Theres有很多选择。 XSLT,Jaxb或Datamapper变换器。一个简单的方法就是使用Groovy的XML MarkupBUilder或MVEL解析模板转换器:
<scripting:transformer>
<scripting:script engine="Groovy">
<scripting:text>
def writer = new StringWriter()
def xml = new groovy.xml.MarkupBuilder(writer)
xml.'soap:Envelope'('xmlns:soap':'http://schemas.xmlsoap.org/soap/envelope/') {
'soap:Body'{
'unk:changeAddress'('xmlns:unk':'http://unknown.namespace/'){
'arg0'(message.inboundProperties.id)
'arg1'(message.inboundProperties.name)
}
}
}
return writer.toString()
</scripting:text>
</scripting:script>
</scripting:transformer>
答案 1 :(得分:0)
除Ryan之外的另一种方法是直接使用set-payload 您可以在有效负载中直接创建 SOAP 请求,并将入站属性设置为 id 和名称在其中动态如下: -
<set-payload value="<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:unk="http://unknown.namespace/"><soapenv:Header/><soapenv:Body><unk:changeAddress><arg0>#[message.inboundProperties.id]</arg0><arg1>#[message.inboundProperties.name]</arg1></unk:changeAddress></soapenv:Body></soapenv:Envelope>" doc:name="Set Payload"/>
在创建 SOAP 请求时,这将是简单和动态 因此,完整的示例如下: -
<flow name="setSOAPRequestFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/changeAddress" doc:name="HTTP"/>
<set-payload value="<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:unk="http://unknown.namespace/"><soapenv:Header/><soapenv:Body><unk:changeAddress><arg0>#[message.inboundProperties.id]</arg0><arg1>#[message.inboundProperties.name]</arg1></unk:changeAddress></soapenv:Body></soapenv:Envelope>" doc:name="Set Payload"/>
<logger level="INFO" message="#[message.payload]" doc:name="Logger"/>
</flow>