WSO2 ESB 4.8 JSON本机支持-尝试通过脚本介体使用介体来操作JSON和日志 [英] WSO2 ESB 4.8 json native support - trying to manipulate json and log using mediator via Script mediator

查看:127
本文介绍了WSO2 ESB 4.8 JSON本机支持-尝试通过脚本介体使用介体来操作JSON和日志的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从WSO2 ESB 4.8开始-本地支持json,可以在WSO2网站上找到信息.在下面引用博客w.r.t.json格式化程序&建造者

From WSO2 ESB 4.8 - json is supported natively, information can be found in WSO2 websit. Referring below blog w.r.t.json formatter & builder

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

我的用例是在HTTP/1.1 REST上使用JSON格式,这里要注意的重点是:

My use-case is to use JSON format over HTTP/1.1 REST, main point to note here is:

  • 不要在ESB内转换json数据(保持ESB内本机的json格式)
  • 使用json格式的中介程序(本地支持json的中介程序-脚本/自定义中介程序)来操纵json

尝试使用:

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

如Charitha博客中所述.现在,在肥皂消息中(使用Log Mediator)我看不到json被转换为肥皂.

as mentioned in Charitha blog. Now, I am not seeing json being converted to soap in the soap message (using Log Mediator).

的意思是,WSO2 ESB 4.8不会在幕后将json请求转换为soap,从而避免了某些数据格式(例如Array等)的数据丢失,如

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 (e.g., Array, etc., as mentioned in https://github.com/erny/jsonbuilderformatter)

谁能分享给我一个使用org.apache.axis2.json.JSONStreamBuilder& org.apache.axis2.json.JSONStreamFormatter(或其他任何用于json的构建器和格式化程序),而不会在消息上下文中转换为soap消息.

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.

推荐答案

http中所述从ESB 4.8开始,://://docs.wso2.org/display/ESB480/JSON+Support doc中,您必须使用以下构建器和格式化程序来保持JSON表示形式不变,而无需转换为XML.这两个是ESB 4.8中的默认选项

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. These two are the default option in ESB 4.8

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

要使用JSON记录,

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

您可以使用Payload FactoryScript介体来操纵JSON主体.例如-

You can manipulate the JSON body using Payload Factory or Script mediators. For e.g.-

<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.

这篇关于WSO2 ESB 4.8 JSON本机支持-尝试通过脚本介体使用介体来操作JSON和日志的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆