为什么JSON路径无效为WSO2 ESB 5.0的JSON请求

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么JSON路径无效为WSO2 ESB 5.0的JSON请求相关的知识,希望对你有一定的参考价值。

我最近使用的是wso2 esb 5.0,我在wso2网站上关于医疗保健示例的教程。

我实际上是在“将一些服务作为单一服务公开”教程,我在信中一直关注它。

问题是,当我使用curl向后端发送请求时,我在日志和控制台中有一些我不明白的错误消息。

请参阅日志中的以下错误消息:

INFO - LogMediator To: /healthcare/categories/surgery/reserve, MessageID: urn:uuid:caca8c20-03db-4632-9f34-0b53f40d5950, Direction: request, message = Routing to grand oak community hospital
    [2018-09-14 17:22:28,616] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.actualFee>. Returning empty result. Error>>> invalid path
    [2018-09-14 17:22:35,025]  INFO - LogMediator To: /healthcare/categories/surgery/reserve, MessageID: urn:uuid:605abc38-6543-44f3-963e-0412b0e7ad12, Direction: request, message = Routing to grand oak community hospital
    [2018-09-14 17:22:35,629] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.actualFee>. Returning empty result. Error>>> invalid path

在控制台中:

Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying ::1...
* TCP_NODELAY set
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 8280 (#0)
> POST /healthcare/categories/surgery/reserve HTTP/1.1
> Host: localhost:8280
> User-Agent: curl/7.55.1
> Accept: */*
> Content-Type:application/json
> Content-Length: 234
>
* upload completely sent off: 234 out of 234 bytes
< HTTP/1.1 500 Internal Server Error
< Set-Cookie: SERVERID=s0; path=/
< Content-Type: application/octet-stream
< Date: Fri, 14 Sep 2018 15:22:35 GMT
< Transfer-Encoding: chunked
<
Error in executing request: POST /healthcare/payments* Connection #0 to host localhost left intact

通常,后端会发送一个JSON文件,其中包含有关费用,医生和患者的一些信息。

我不明白错误信息;显然错误将来到$ .actualfee的JSON路径,但我没有看到它的问题。也许错误是可见的,但我是wso2的初学者而且我不会在esb中取消所有。

亚瑟

PS:我的HealthCareAPI.xml文件的XML源代码:

<?xml version="1.0" encoding="UTF-8"?>
<api context="/healthcare" name="HealthcareAPI" xmlns="http://ws.apache.org/ns/synapse">
    <resource methods="GET" uri-template="/querydoctor/{category}">
        <inSequence>
            <log description="Request Log" level="custom">
                <property name="message" value="&quot;Welcome to HealthcareService&quot;"/>
            </log>
            <send>
                <endpoint key="QueryDoctorEP"/>
            </send>
        </inSequence>
        <outSequence>
            <send/>
        </outSequence>
        <faultSequence/>
    </resource>
    <resource uri-template="/categories/{category}/reserve">
        <inSequence>
            <property description="Get Hospital" expression="json-eval($.hospital)" name="Hospital" scope="default" type="STRING"/>
            <property description="Get Card Number" expression="json-eval($.cardNo)" name="card_number" scope="default" type="STRING"/>
            <datamapper config="gov:datamapper/RequestMapping.dmc" description="DataMapper" inputSchema="gov:datamapper/RequestMapping_inputSchema.json" inputType="JSON" outputSchema="gov:datamapper/RequestMapping_outputSchema.json" outputType="JSON"/>
            <switch source="get-property('Hospital')">
                <case regex="grand oak community hospital">
                    <log description="Grand Oak Log">
                        <property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
                    </log>
                    <property description="Set Hospital Variable" name="uri.var.hospital" scope="default" type="STRING" value="grandoaks"/>
                    <call>
                        <endpoint key="GrandOakEP"/>
                    </call>
                </case>
                <case regex="clemency medical center">
                    <log description="Clemency Log">
                        <property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
                    </log>
                    <property description="Set Hospital Variable" name="uri.var.hospital" scope="default" type="STRING" value="clemency"/>
                    <call>
                        <endpoint key="ClemencyEP"/>
                    </call>
                </case>
                <case regex="pine valley community hospital ">
                    <log description="Pine Valley Log" level="custom">
                        <property expression="fn:concat('Routing to ', get-property('Hospital'))" name="message"/>
                    </log>
                    <property description="Set Hospital Variable" name="uri.var.hospital" scope="default" type="STRING" value="pinevalley"/>
                    <call>
                        <endpoint key="PineValleyEP"/>
                    </call>
                </case>
                <default>
                    <log description="Fault Log" level="custom">
                        <property expression="fn:concat('Invalid hospital - ', get-property('Hospital'))" name="message"/>
                    </log>
                    <respond description="Respond"/>
                </default>
            </switch>
            <property description="Get Appointment Number" expression="json-eval($.appointmentNumber)" name="uri.var.appointment_id" scope="default" type="STRING"/>
            <property description="Get Doctor Details" expression="json-eval($.doctor)" name="doctor_details" scope="default" type="STRING"/>
            <property description="Get Patient Details" expression="json-eval($.patient)" name="patient_details" scope="default" type="STRING"/>
            <call>
                <endpoint key="ChannelingFeeEP"/>
            </call>
            <property description="Get Actual Fee" expression="json-eval($.actualFee)" name="actual_fee" scope="default" type="STRING"/>
            <payloadFactory media-type="json">
                <format>{&#xd;
"appointmentNumber":$1,&#xd;
"doctor":$2,&#xd;
"patient":$3,&#xd;
"fee":$4,&#xd;
"confirmed":"false",&#xd;
"card_number":"$5"&#xd;
}</format>
                <args>
                    <arg evaluator="xml" expression="$ctx:uri.var.appointment_id"/>
                    <arg evaluator="xml" expression="$ctx:doctor_details"/>
                    <arg evaluator="xml" expression="$ctx:patient_details"/>
                    <arg evaluator="xml" expression="$ctx:actual_fee"/>
                    <arg evaluator="xml" expression="$ctx:card_number"/>
                </args>
            </payloadFactory>
            <call>
                <endpoint key="SettlePaymentEP"/>
            </call>
            <respond/>
        </inSequence>
        <outSequence/>
        <faultSequence/>
    </resource>
</api>
答案

尝试在调用mediator之后使用Property mediator,如下所示。

  <call>
         <endpoint key="ChannelingFeeEP"/>
        </call>

 <property description="messageType" value="application/json"  scope="default" type="STRING"/>
 <property description="contentType" value="application/json"  scope="default" type="STRING"/>
 <property description="Get Actual Fee" expression="json-eval($.actualFee)" name="actual_fee" scope="default" type="STRING"/>

以上是关于为什么JSON路径无效为WSO2 ESB 5.0的JSON请求的主要内容,如果未能解决你的问题,请参考以下文章

WSO2 ESB 无法将完整的 JSON 数据转换为 XML

WSO2:将CSV消息转换为json wso2 esb。在prolog中出现意外字符'“'(代码34)失败;预期'

WSO2:wso2中的xml到json数据映射esb:json消息包含在soap信封中

WSO2 ESB PayloadFactory 中介器中的 JSON 格式

WSO2 ESB 5.0.0 一些组件的使用教程

WSO2 ESB 5.0.0 一些组件的使用教程