[英]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.