简体   繁体   English

WSO2 ESB 4.8 JSON本机支持-尝试通过脚本介体使用介体操作JSON和日志

[英]WSO2 ESB 4.8 json native support - trying to manipulate json and log using mediator via Script mediator

From WSO2 ESB 4.8 - json is supported natively, information can be found in WSO2 websit. 从WSO2 ESB 4.8开始-本地支持json,可以在WSO2网站上找到信息。 Referring below blog wrtjson formatter & builder 在下面引用博客wrtjson格式化程序和生成器

http://charithaka.blogspot.co.uk/2013/10/the-difference-between-json-streaming.html http://charithaka.blogspot.co.uk/2013/10/the-difference-between-json-streaming.html

My use-case is to use JSON format over HTTP/1.1 REST, main point to note here is: 我的用例是在HTTP / 1.1 REST上使用JSON格式,这里要注意的重点是:

  • not to tranform the json data within ESB (keep the json format natively within ESB) 不转换ESB中的json数据(保持ESB中本机的json格式)
  • manipulate the json using mediator in json format (mediator which support json natively - script/custom mediators) 使用json格式的中介程序来操作json(本机支持json的中介程序-脚本/自定义中介程序)

trying to use : 尝试使用:

org.apache.axis2.json.JSONStreamBuilder
org.apache.axis2.json.JSONStreamFormatter

as mentioned in Charitha blog. 如Charitha博客中所述。 Now, I am not seeing json being converted to soap in the soap message (using Log Mediator). 现在,在肥皂消息中(使用Log Mediator)我看不到json被转换为肥皂。

does that mean, WSO2 ESB 4.8 does not convert a json request to soap under the hood avoiding data loss for some data format (eg, Array, etc., as mentioned in https://github.com/erny/jsonbuilderformatter ) 这是否意味着,WSO2 ESB 4.8不会在幕后将json请求转换为soap,从而避免了某些数据格式(例如Array等,如https://github.com/erny/jsonbuilderformatter所述 )的数据丢失。

Can anyone share me an example of logging / manipulating json message using org.apache.axis2.json.JSONStreamBuilder & org.apache.axis2.json.JSONStreamFormatter (or) any other builder and formatter for json without converting into soap message in the message context. 谁能分享给我一个使用org.apache.axis2.json.JSONStreamBuilder和org.apache.axis2.json.JSONStreamFormatter(或其他任何JSON生成器和格式化程序)记录/处理JSON消息的示例,而无需转换为消息中的soap消息上下文。

As mentioned in http://docs.wso2.org/display/ESB480/JSON+Support doc, from ESB 4.8 onwards you have to use following builder and formatter to keep the JSON representation intact without converting to XML. http://docs.wso2.org/display/ESB480/JSON+Support文档中所述,从ESB 4.8开始,您必须使用以下构建器和格式化程序来保持JSON表示形式不变,而无需转换为XML。 These two are the default option in ESB 4.8 这两个是ESB 4.8中的默认选项

org.apache.synapse.commons.json.JsonStreamBuilder    
org.apache.synapse.commons.json.JsonStreamFormatter

To log as JSON use, 要使用JSON记录,

<log>
    <property name="JSON-Payload" expression="json-eval($.)"/>
</log>

You can manipulate the JSON body using Payload Factory or Script mediators. 您可以使用Payload FactoryScript中介程序来操作JSON主体。 For eg- 对于例如

<payloadFactory media-type="json">
        <format>
                {
                    "location_response" : {
                        "name" : "$1",
                        "tags" : $2
                    }
                }
        </format>
    <args>
        <arg evaluator="json" expression="$.name"/>
        <arg evaluator="json" expression="$.types"/>
    </args>
</payloadFactory>

Refer the documentation for more details. 有关更多详细信息,请参考文档

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

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