[英]WSO2 ESB / WSO2 EI JSON Request to backend service
我使用WSO2 EI将JSON消息发送到后端服务器。 但它发送错误的json格式。 我已经使用wso2ei-6.4.0来完成这项任务。 我添加了我使用的示例XML请求。
<jsonObject>
<checkInDate>2019-03-25</checkInDate>
<checkOutDate>2019-03-26</checkOutDate>
<cityCode>3086</cityCode>
<hotelCode />
<roomOccupancyList>
<jsonArray>
<?xml-multiple jsonElement?>
<jsonElement>
<childAges>0</childAges>
<numberOfAdults>1</numberOfAdults>
<numberOfChildren>0</numberOfChildren>
<roomNo>1</roomNo>
</jsonElement>
</jsonArray>
</roomOccupancyList>
</jsonObject>
但我收到了ESB方面的JSON请求。 一旦通过ESB服务发送消息。
{
"checkInDate": "2019-06-04",
"checkOutDate": "2019-06-05",
"cityCode": "1344",
"hotelCode": "",
"roomOccupancyList": {
"childAges": "0",
"numberOfAdults": "1",
"numberOfChildren": "0",
"roomNo": "1"
}
}
这个“ roomOccupancyList ”应该有JSONArray对象,默认情况下它显示为JSONObject。 如果我在这里添加了多个jsonElement,它显示为JSONArray。 但我甚至还需要一个jsonElement。 你能帮我修一下这个问题吗? 我已经为上述任务提供了以下链接。 wso2 doc链接
JSON响应应加载以下格式。
{
"checkInDate": "2019-06-04",
"checkOutDate": "2019-06-05",
"cityCode": "1344",
"hotelCode": "",
"roomOccupancyList": [
{
"childAges": "0",
"numberOfAdults": "1",
"numberOfChildren": "0",
"roomNo": "1"
}
]
}
我使用了以下xslt,它没有任何问题。 您还需要在synapse.properties / ESB_HOME / conf文件夹中添加以下属性。
synapse.json.to.xml.processing.instruction.enabled=true
这个样本XSLT供您进一步参考。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:strip-space elements="*"/>
<xsl:output indent="yes"/>
<xsl:template match="/request">
<availabilityRequest>
<jsonObject>
<checkInDate>2019-03-25</checkInDate>
<checkOutDate>2019-03-26</checkOutDate>
<cityCode>3086</cityCode>
<xsl:variable name="roomCount" select="count(roomsInformation)" />
<xsl:for-each select="roomsInformation">
<xsl:if test="$roomCount = 1">
<xsl:processing-instruction name="xml-multiple"/>
</xsl:if>
<xsl:variable name="roomIndex" select="position()" />
<roomOccupancyList>
<jsonArray>
<childAges>0</childAges>
<numberOfAdults>1</numberOfAdults>
<numberOfChildren>1</numberOfChildren>
<roomNo><xsl:value-of select="$roomIndex" /></roomNo>
</jsonArray>
</roomOccupancyList>
<xsl:if test="$roomCount = 1">
<xsl:copy-of select="Objects"></xsl:copy-of>
</xsl:if>
</xsl:for-each>
</jsonObject>
</availabilityRequest>
</xsl:template>
</xsl:stylesheet>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.