注册。在 wso2 EI 中使用数据映射器获得空响应
Regd. getting empty response with data mapper in wso2 EI
我正在尝试使用数据映射器将 json 转换为 xml,但我得到的是空的 xml 结构,但在 wso2 中没有得到任何值。我已经创建了数据映射器依赖项并加载了输入和输出结构并使用 AI 来映射 json -> xml 并且它们映射正确。
我也尝试了 eclipse oxygen(esb-6.2.0) 和 integration studio(v8) 并部署在 EI(6.5.0) 中,但行为仍然是相同的空响应结构。我按顺序保留了一个日志,它记录了 json 请求而不是 xml 响应。我不明白为什么会出现这个问题。
请提供您的想法并将代码附加到此 post。请做有需要的
问题出在 API。在 API 中,我们需要指定输入和输出数据类型。在您的情况下,由于转换是从 JSON 到 XML,因此输入类型需要是 JSON,而输出类型需要是 XML。但是您将两者都定义为 xml 导致了这个问题。修改输入类型为JSON,你会得到预期的结果
<api xmlns="http://ws.apache.org/ns/synapse" name="DataMapper" context="/data">
<resource methods="POST" url-mapping="/mapper">
<inSequence>
<log separator="/">
<property name="payload" expression="json-eval($.body)"/>
</log>
<datamapper config="gov:datamapper/Wso2DataMapper.dmc" inputSchema="gov:datamapper/Wso2DataMapper_inputSchema.json" outputSchema="gov:datamapper/Wso2DataMapper_outputSchema.json" xsltStyleSheet="gov:datamapper/Wso2DataMapper_xsltStyleSheet.xml" inputType="JSON" outputType="XML"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
输入
{
"studNo":"Sample studNo",
"studName":"Sample studName",
"StudGroup":"Sample StudGroup",
"studAddress":{
"addrLine1":"Sample addrLine1",
"AddrLine2":"Sample AddrLine2",
"Mandal":"Sample Mandal",
"District":"Sample District",
"State":"Sample State",
"Country":"Sample Country",
"Zip":"Sample Zip"
}
}
输出
<Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<studentNo>Sample studNo</studentNo>
<studentName>Sample studName</studentName>
<studentGroup>Sample StudGroup</studentGroup>
<studentAddress>
<AddressLine1>Sample AddrLine2</AddressLine1>
<AddressLine2>Sample addrLine1</AddressLine2>
<Mandal>Sample Mandal</Mandal>
<District>Sample District</District>
<State>Sample State</State>
<Country>Sample Country</Country>
<ZIP>Sample Zip</ZIP>
</studentAddress>
</Student>
我正在尝试使用数据映射器将 json 转换为 xml,但我得到的是空的 xml 结构,但在 wso2 中没有得到任何值。我已经创建了数据映射器依赖项并加载了输入和输出结构并使用 AI 来映射 json -> xml 并且它们映射正确。
我也尝试了 eclipse oxygen(esb-6.2.0) 和 integration studio(v8) 并部署在 EI(6.5.0) 中,但行为仍然是相同的空响应结构。我按顺序保留了一个日志,它记录了 json 请求而不是 xml 响应。我不明白为什么会出现这个问题。
请提供您的想法并将代码附加到此 post。请做有需要的
问题出在 API。在 API 中,我们需要指定输入和输出数据类型。在您的情况下,由于转换是从 JSON 到 XML,因此输入类型需要是 JSON,而输出类型需要是 XML。但是您将两者都定义为 xml 导致了这个问题。修改输入类型为JSON,你会得到预期的结果
<api xmlns="http://ws.apache.org/ns/synapse" name="DataMapper" context="/data">
<resource methods="POST" url-mapping="/mapper">
<inSequence>
<log separator="/">
<property name="payload" expression="json-eval($.body)"/>
</log>
<datamapper config="gov:datamapper/Wso2DataMapper.dmc" inputSchema="gov:datamapper/Wso2DataMapper_inputSchema.json" outputSchema="gov:datamapper/Wso2DataMapper_outputSchema.json" xsltStyleSheet="gov:datamapper/Wso2DataMapper_xsltStyleSheet.xml" inputType="JSON" outputType="XML"/>
<respond/>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
输入
{
"studNo":"Sample studNo",
"studName":"Sample studName",
"StudGroup":"Sample StudGroup",
"studAddress":{
"addrLine1":"Sample addrLine1",
"AddrLine2":"Sample AddrLine2",
"Mandal":"Sample Mandal",
"District":"Sample District",
"State":"Sample State",
"Country":"Sample Country",
"Zip":"Sample Zip"
}
}
输出
<Student xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<studentNo>Sample studNo</studentNo>
<studentName>Sample studName</studentName>
<studentGroup>Sample StudGroup</studentGroup>
<studentAddress>
<AddressLine1>Sample AddrLine2</AddressLine1>
<AddressLine2>Sample addrLine1</AddressLine2>
<Mandal>Sample Mandal</Mandal>
<District>Sample District</District>
<State>Sample State</State>
<Country>Sample Country</Country>
<ZIP>Sample Zip</ZIP>
</studentAddress>
</Student>