本文介绍了用不适合我的新元素丰富 Json.请指导的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用不适合我的新元素丰富 Json.请指导.

Enrich Json with new elements not working for me .Please guide.

输入请求:

 {
        "id" : "1",     
        "make" : "NAHB"
    }

我创建了名为 eg1.xml 的 wso2 流.我正在尝试使用新元素名称"来丰富传入的 json 请求

I created wso2 flow named eg1.xml . I am trying to enrich the incoming json request with new element "name"

处理xml:(eg1.xml)

processing xml: (eg1.xml)

 <?xml version="1.0" encoding="UTF-8"?>
    <api context="/eg1" name="eg1" xmlns="http://ws.apache.org/ns/synapse">
        <resource methods="POST GET" uri-template="/hi">
            <inSequence>
                <log level="full"/>
                <log level="custom">
                    <property expression="//jsonObject" name="msg1"/>
                </log>
                <enrich description="">
                    <source clone="true" type="inline">
                        <name xmlns="">Home</name>
                    </source>
                    <target action="child" xpath="//jsonObject"/>
                </enrich>
                <log level="custom">
                    <property expression="//jsonObject" name="msg2"/>
                </log>
                <log level="full"/>
                <respond/>
            </inSequence>
            <outSequence/>
            <faultSequence/>
        </resource>
    </api>

电流输出:

 {
        "id" : "1",     
        "make" : "NAHB"
    }

所需的输出:

 {
        "id" : "1",     
        "make" : "NAHB"
        "name" : "Home"
    }

记录器输出:

Logger1 输出(日志级别已满):LogMediator To:/eg1/ MessageID: urn:uuid:2f627daf-ac9c-4492-84ea-2736670724e8, Direction: request, Payload:

Logger1 output(log level full) : LogMediator To: /eg1/ MessageID: urn:uuid:2f627daf-ac9c-4492-84ea-2736670724e8, Direction: request, Payload:

   {
        "id": "1",
        "make": "NAHB"
    }

Logger2 输出:LogMediator msg1 =

Logger2 output :LogMediator msg1 =

 <jsonObject>
        <id>1</id>
        <make>NAHB</make>
    </jsonObject>

Logger3 输出:LogMediator msg2 =

Logger3 output :LogMediator msg2 =

 <jsonObject>
        <id>1</id>
        <make>NAHB</make>
        <name>Home</name>
    </jsonObject>

Logger4 输出(日志级别已满):LogMediator To:/eg1/ MessageID: urn:uuid:2f627daf-ac9c-4492-84ea-2736670724e8, Direction: request, Payload:

Logger4 output(log level full) : LogMediator To: /eg1/ MessageID: urn:uuid:2f627daf-ac9c-4492-84ea-2736670724e8, Direction: request, Payload:

{"id": "1",制造":NAHB"}

{ "id": "1", "make": "NAHB"}

邮递员输出:

 {
        "id": "1",
        "make": "NAHB"
    }

问候,阿迪亚

推荐答案

您必须将响应添加回正文

You have to add the response back to body

<api xmlns="http://ws.apache.org/ns/synapse" name="eg1" context="/eg1">
<resource methods="POST GET" uri-template="/hi">
  <inSequence>
     <log level="full"/>
     <log level="custom">
        <property name="msg1" expression="//jsonObject"/>
     </log>
     <enrich description="">
        <source type="inline" clone="true">
           <name xmlns="">Home</name>
        </source>
        <target action="child" xpath="//jsonObject"/>
     </enrich>
     <log level="full">
        <property name="msg2" expression="//jsonObject"/>
     </log>
     <enrich>
        <source clone="true" xpath="//jsonObject"/>
        <target type="body"/>
     </enrich>
     <log level="full"/>
     <respond/>
  </inSequence>
  <outSequence/>
  <faultSequence/>

我已经尝试过这个 API

I have tried this API

请求

 {
    "id" : "1",     
    "make" : "NAHB"
}

回复

{
   "id": 1,
   "make": "NAHB",
   "name": "Home"
}

这篇关于用不适合我的新元素丰富 Json.请指导的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 13:36