简体   繁体   English

无法以API读取wso2 ESB中的JSON请求主体参数

[英]Cannot Read JSON request body parameters in wso2 ESB as an api

I have created an API in the WSO2 ESB (4.8.1) and I wanted to send a PUT request to that API with a request body. 我已经在WSO2 ESB(4.8.1)中创建了一个API,我想使用请求正文将PUT请求发送到该API。 I have tried with the sample and I wanted to log a property values in the insequence of the defined API. 我已经尝试过该示例,并且想以已定义API的顺序记录属性值。

This is my request body: 这是我的请求正文:

请求正文(JSON)

This is the way how I tried to log the location name: 这是我尝试记录位置名称的方式:

XML日志

But I'm getting an error like this: 但我收到这样的错误:

(ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path . Returning empty result. Error>>> invalid path) (错误-SynapseJsonPath #stringValueOf。评估JSON路径时出错。返回空结果。错误>>>无效路径)

错误截图

So how can I read these values? 那么我该如何读取这些值?

To achieve your requirement, you should send the "Content-Type" HTTP header with the request like below, 为了满足您的要求,您应该使用以下请求发送“ Content-Type” HTTP标头,

    "Content-Type : application/json"

enter image description here 在此处输入图片说明

Then you can log the specific JSON element like below. 然后,您可以记录特定的JSON元素,如下所示。

 <log>
    <property name="location" expression="json-eval($.coordinates.location[0].name)"></property>
 </log>

Then you can see following log, 然后您可以看到以下日志,

enter image description here 在此处输入图片说明

Thanks. 谢谢。

If you want to get single variable from user in json request you can use this code 


Use This json:
    {

    "namee":"UsmanYaqooooooooooob"
    }


Api Code: 
        <api xmlns="http://ws.apache.org/ns/synapse" name="Hello" context="/hello">
           <resource methods="POST" uri-template="/post">
              <inSequence>
                 <log level="custom">
                    <property name="===========inSequence" value="****"></property>
                    <property name="locationsssssssss" expression="json-eval(.namee)"></property>
                 </log>
                 <payloadFactory media-type="json">
                    <format>{"hello":"world"}</format>
                    <args></args>
                 </payloadFactory>
                 <property name="messageType" value="text/xml"></property>
                 <respond></respond>
              </inSequence>
           </resource>
        </api>

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

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