Xml 在WSO2 ESB中组合迭代/聚合器和XSLT中介器并不像预期的那样工作
我在一个使用代理服务的场景中工作,代理服务调用数据服务并向其发送以下消息:Xml 在WSO2 ESB中组合迭代/聚合器和XSLT中介器并不像预期的那样工作,xml,xslt,wso2,wso2esb,Xml,Xslt,Wso2,Wso2esb,我在一个使用代理服务的场景中工作,代理服务调用数据服务并向其发送以下消息: <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"
<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>
473906852857651
并收到以下回复:
<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>
796243010946586
473906852857651
2500000000
473906852857651
代理在每个Datalist节点上迭代,并使用clientid和partybranchid的值创建另一个请求,并发送到另一个数据服务:
请求1:
<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>
796243010946586
473906852857651
请求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>
2500000000
473906852857651
答复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>
这是正确的配置
这是我的意外:
<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>
<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作为聚合消息的根,并在onComplete配置中使用enclosuringElementProperty=“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>
指令1
796243010946586
473906852857651
指令3
796243010946586
473906852857651
哟
2500000000
473906852857651
我更新了我的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>
指令1
796243010946586
473906852857651
指令3
796243010946586
473906852857651
哟
2500000000
473906852857651
问题是,您对XSLT中介的请求没有根元素。也就是说,在soap主体中,所有三个
元素都处于同一级别。它们没有根元素。当esb将消息发送到xslt时,它将传递正文消息。在这里,xslt将只选择第一个
元素并进行转换。要克服这个问题,请使用包装根元素创建soap主体。
例如:
<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>
指令1
796243010946586
473906852857651
指令3
796243010946586
473906852857651
哟
2500000000
473906852857651
如果你这样发送,你会得到这样的输出
<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。关于配置/信封问题,我刚刚发现另一篇SO帖子提到了此类问题并提供了一种方法。不确定是否适用,但只是想分享一下,以防这会有所帮助:谢谢,我会尝试这种方法,然后带着results@JorgeInfanteOsorio在聚合中介程序结束后记录聚合中介程序的输出。就在发送到xslt中介并查看记录的消息格式之前。然后,您可以轻松地识别issue@Ratha输出在我的帖子中,没有问题,我用它来测试XMLSPY,XSL结果很好,问题与ESB有关。@JorgeInfanteOsorio我发布了答案。请检查
<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>
<?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>
<?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>
<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>