简体   繁体   English

在 wso2 中使用 json 值填充有效负载

[英]Populate payload with json values in wso2

Im having issue with payloads.我的有效载荷有问题。 I followed the https://docs.wso2.com/display/ESB500/Exposing+Several+Services+as+a+Single+Service我跟着https://docs.wso2.com/display/ESB500/Exposing+Several+Services+as+a+Single+Service

but cannot create a proper payload但无法创建适当的有效负载

<log level="custom">
        <property expression="fn:concat('VIN: ',get-property('vin'),' ModelName: ',get-property('modelName'),' Year: ',get-property('modelYear'))" name="vechicle"/>
</log>

<payloadFactory description="VIN message" media-type="json">
  <format>{&#xd;
    "VIN":$1,&#xd;
    }</format>
  <args>
  <arg evaluator="xml" expression="$ctx:vin"/>
</args>
</payloadFactory>

get-property('vin') is working becouse I see it in log BUT payload not replacing $1 with real value , something is wrong with evaluate get-property('vin') 正在工作,因为我在日志中看到它但有效负载没有用实际值替换 $1,评估有问题

Error message :错误信息 :

Could not get parser from data source for element jsonObject
TID[-1234] [ESB] [2017-03-07 23:46:37,611] ERROR {org.apache.axiom.om.impl.llom.OMSourcedElementImpl} - Could not get parser from data source for element jsonObject org.apache.synapse.commons.staxon.core.base.AbstractXMLStreamReader.initialize(AbstractXMLStreamReader.java:245) org.apache.synapse.commons.staxon.core.json.JsonXMLStreamReader.(JsonXMLStreamReader.java:66) org.apache.synapse.commons.staxon.core.json.JsonXMLInputFactory.createXMLStreamReader(JsonXMLInputFactory.java:165) org.apache.synapse.commons.json.JsonUtil.getReader(JsonUtil.java:302) org.apache.synapse.commons.json.JsonDataSource.getReader(JsonDataSource.java:153) org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getDirectReader(OMSourcedElementImpl.java:225) org.apache.axiom.om.impl.llom.OMSourcedElementImpl.forceExpand(OMSourcedElementImpl.java:254) org.apache.axiom.om.impl.llom.OMSourcedElementImpl.getFirstOMChild(OMSourcedElementImpl.java:867) org.apache.axiom.om.impl.OMNavigator._getFirstChild(OMNavigator.java:196) org.apache.axiom.om.impl.OMNavigator.updateNextNode(OMNavigator.java:140) org.apache.axiom.om.impl.OMNavigator.getNext(OMNavigator.java:112) org.apache.axiom.om.impl.SwitchingWrapper.updateNextNode(SwitchingWrapper.java:1113) org.apache.axiom.om.impl.SwitchingWrapper.(SwitchingWrapper.java:235) org.apache.axiom.om.impl.OMStAXWrapper.(OMStAXWrapper.java:74) org.apache.axiom.om.impl.llom.OMStAXWrapper.(OMStAXWrapper.java:52) org.apache.axiom.om.impl.llom.OMContainerHelper.getXMLStreamReader(OMContainerHelper.java:51) org.apache.axiom.om.impl.llom.OMElementImpl.getXMLStreamReader(OMElementImpl.java:736) org.apache.axiom.om.impl.llom.OMElementImpl.cloneOMElement(OMElementImpl.java:1038) org.apache.synapse.util.MessageHelper.cloneSOAPEnvelope(MessageHelper.java:690) 

help...帮助...

The problem seems to be in the JSON message.问题似乎出在 JSON 消息中。 Firstthe formatting of the JSON message itself should not matter therefore the carriage returns should be obsolete.首先,JSON 消息本身的格式无关紧要,因此回车应该已过时。 However that does not seem to be the problem.然而,这似乎不是问题。 Second, there is a comma after the $1, this suggests there will be another object but instead there is a carriage return and then the closing bracket, this is what actually breaks the parser:.其次,$1 后面有一个逗号,这表明会有另一个对象,但有一个回车,然后是右括号,这实际上是破坏解析器的原因:。 I would try it like this (although you can leave the carriage returns in, I've tested both on ESB 5.0.0)我会这样尝试(尽管您可以保留回车符,但我已经在 ESB 5.0.0 上测试了两者)

<payloadFactory description="VIN message" media-type="json">
  <format>{
    "VIN":$1
    }</format>
  <args>
  <arg evaluator="xml" expression="$ctx:vin"/>
</args>
</payloadFactory>

Also, if vin is a string then you might have to add quotes in your format as well.此外,如果 vin 是一个字符串,那么您可能还需要在您的格式中添加引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM