我正在使用代理服务调用dataservice并向其发送此消息:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:add="http://www.example.org/Address/">
<soap:Body>
<dat:getmpartybranch xmlns:dat="http://ws.wso2.org/dataservice">
<dat:clientid>473906852857651</dat:clientid>
</dat:getmpartybranch>
</soap:Body>
</soap:Envelope>
并收到此回复:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<DataCollection xmlns="http://ws.wso2.org/dataservice">
<Datalist>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Datalist>
<Datalist>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Datalist>
</DataCollection>
</soapenv:Body>
</soapenv:Envelope>
代理遍历每个Datalist节点,并且使用clientid和partybranchid的值,它创建另一个请求,发送到另一个dataservice:
request1:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<dat:getselect_addresses xmlns:dat="http://ws.wso2.org/dataservice">
<dat:objectid>796243010946586</dat:objectid>
<dat:clientid>473906852857651</dat:clientid>
</dat:getselect_addresses>
</soapenv:Body>
</soapenv:Envelope>
请求2:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<dat:getselect_addresses xmlns:dat="http://ws.wso2.org/dataservice">
<dat:objectid>2500000000</dat:objectid>
<dat:clientid>473906852857651</dat:clientid>
</dat:getselect_addresses>
</soapenv:Body>
</soapenv:Envelope>
响应1:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<Addresses xmlns="http://ws.wso2.org/dataservice">
<Address>
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address>
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</Addresses>
</soapenv:Body>
</soapenv:Envelope>
响应2:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Header></soapenv:Header>
<soapenv:Body>
<Addresses xmlns="http://ws.wso2.org/dataservice">
<Address>
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</Addresses>
</soapenv:Body>
</soapenv:Envelope>
在结果中我使用带有此表达式的agregator介体// add:Addresses / add:Address,所以我的输出消息看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<Address xmlns="http://ws.wso2.org/dataservice"><address>direccion1</address><partybranchid>796243010946586</partybranchid><clientid>473906852857651</clientid></Address>
<Address xmlns="http://ws.wso2.org/dataservice"><address>direccion3</address><partybranchid>796243010946586</partybranchid><clientid>473906852857651</clientid></Address>
<Address xmlns="http://ws.wso2.org/dataservice"><address>yo</address><partybranchid>2500000000</partybranchid><clientid>473906852857651</clientid></Address>
</soapenv:Body>
</soapenv:Envelope>
输出序列:
<outSequence>
<aggregate id="iterate1">
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:add="http://ws.wso2.org/dataservice"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
expression="//add:Addresses/add:Address">
<log level="full"/>
</onComplete>
</aggregate>
<xslt key="conf:/xslt/Tranformacion_DS_to_ESB.xsl"/>
<send/>
</outSequence>
现在我想用XSLT转换此消息,因此我使用ALTOVA XML SPY并构建此“Tranformacion_DS_to_ESB.xsl”:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:a="http://ws.wso2.org/dataservice" xmlns:b="http://www.example.org/Address/" exclude-result-prefixes="a fn xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<b:getAddressResponse>
<xsl:for-each select="//a:Address">
<address>
<address>
<xsl:value-of select="a:address"/>
</address>
<partybranchid>
<xsl:value-of select="a:partybranchid"/>
</partybranchid>
<clientid>
<xsl:value-of select="a:clientid"/>
</clientid>
</address>
</xsl:for-each>
</b:getAddressResponse>
</xsl:template>
</xsl:stylesheet>
如果我使用之前的soap消息在XML SPY中测试此转换,结果是:
<?xml version="1.0" encoding="UTF-8"?>
<b:getAddressResponse xmlns:b="http://www.example.org/Address/">
<address>
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
<address>
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
<address>
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</address>
</b:getAddressResponse>
没关系,但是当我在聚合调解器完成它之后将这个转换放在ESB中时,我收到了这个错误信息:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<b:getAddressResponse xmlns:b="http://www.example.org/Address/">
<address>
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
</b:getAddressResponse>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</soapenv:Body>
</soapenv:Envelope>
关于这个结果的任何想法??
编辑: 当我尝试matthias建议的代码时,我在XML SPY中得到了正确的输出,但在ESB中我得到另一个错误的输出:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<address xmlns:b="http://www.example.org/Address/">
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</soapenv:Body>
</soapenv:Envelope>
最后更新: 使用@Ratha建议我和这个链接wso2 ESB : Split / Gather Pattern - Single Response这是正确的配置。
这是我的后果:
<outSequence>
<property name="root" scope="default">
<root:rootelement xmlns:root="http://ws.wso2.org/dataservice"/>
</property>
<aggregate id="iterate1">
<completeCondition>
<messageCount min="-1" max="-1"/>
</completeCondition>
<onComplete xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
xmlns:add="http://ws.wso2.org/dataservice"
xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
expression="//add:Addresses/add:Address"
enclosingElementProperty="root">
<log level="full"/>
</onComplete>
</aggregate>
<xslt key="conf:/xslt/Tranformacion_DS_to_ESB.xsl"/>
<send/>
</outSequence>
正如您所看到的,我将带有rootelement的root属性作为我的聚合消息的根,并在onComplete配置中使用了enclosingElementProperty =“root”,所以我的聚合输出现在看起来像这样:
<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<root:rootelement xmlns:root="http://ws.wso2.org/dataservice">
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</root:rootelement>
</soapenv:Body>
</soapenv:Envelope>
我更新了我的XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:a="http://ws.wso2.org/dataservice" xmlns:b="http://www.example.org/Address/" exclude-result-prefixes="a fn xs">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<b:getAddressResponse>
<xsl:for-each select="//a:rootelement/a:Address">
<address>
<address>
<xsl:value-of select="a:address"/>
</address>
<partybranchid>
<xsl:value-of select="a:partybranchid"/>
</partybranchid>
<clientid>
<xsl:value-of select="a:clientid"/>
</clientid>
</address>
</xsl:for-each>
</b:getAddressResponse>
</xsl:template>
</xsl:stylesheet>
现在我的代理响应就是这样,我想要:
<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope">
<soapenv:Body>
<b:getAddressResponse xmlns:b="http://www.example.org/Address/">
<address>
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
<address>
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</address>
<address>
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</address>
</b:getAddressResponse>
</soapenv:Body>
</soapenv:Envelope>
答案 0 :(得分:1)
问题在于,您对XSLT介体的请求没有root元素。也就是说,在肥皂体内,所有三个<Address>
元素处于同一水平。他们没有根元素。当esb将消息发送到xslt时,它将传递正文消息。这里xslt将只选择第一个<Address>
元素并进行转换。要克服,请使用包裹根元素制作肥皂体。
例如:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://services.samples" xmlns:xsd="http://services.samples/xsd">
<soapenv:Header/>
<soapenv:Body>
<root xmlns="http://ws.wso2.org/dataservice">
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion1</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>direccion3</address>
<partybranchid>796243010946586</partybranchid>
<clientid>473906852857651</clientid>
</Address>
<Address xmlns="http://ws.wso2.org/dataservice">
<address>yo</address>
<partybranchid>2500000000</partybranchid>
<clientid>473906852857651</clientid>
</Address>
</root>
</soapenv:Body>
</soapenv:Envelope>
如果您这样发送,您将得到这样的输出;
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://services.samples/xsd" xmlns:ser="http://services.samples">
<soapenv:Body>
<b:getAddressResponse xmlns:b="http://www.example.org/Address/">
<address>
<address></address>
<partybranchid></partybranchid>
<clientid></clientid>
</address>
<address>
<address></address>
<partybranchid></partybranchid>
<clientid></clientid>
</address>
<address>
<address></address>
<partybranchid></partybranchid>
<clientid></clientid>
</address>
</b:getAddressResponse>
</soapenv:Body>
</soapenv:Envelope>
注意:使用正确的xpath编辑xslt。