Wso2 向ESB发送POST请求

Wso2 向ESB发送POST请求,wso2,wso2esb,google-custom-search,synapse,Wso2,Wso2esb,Google Custom Search,Synapse,我正在尝试创建一个谷歌自定义搜索连接器。创建连接器后,我将连接器添加到ESB。然后我想测试一下 我的test init文件如下所示: <template name="listVolume" xmlns="http://ws.apache.org/ns/synapse"> <parameter name="apiKey" description="Full-text search query string." /> <parameter name="c

我正在尝试创建一个谷歌自定义搜索连接器。创建连接器后,我将连接器添加到ESB。然后我想测试一下

我的test init文件如下所示:

<template name="listVolume" xmlns="http://ws.apache.org/ns/synapse">
    <parameter name="apiKey" description="Full-text search query string." />
    <parameter name="csiKey" description="Full-text search query string." />
    <parameter name="searchPara" description="Full-text search query string." />
    <sequence>
    <property name="uri.var.apiKey" expression="$func:apiKey" />
    <property name="uri.var.csiKey" expression="$func:csiKey" />
    <property name="uri.var.searchPara" expression="$func:searchPara" />
    <call>
        <endpoint>
            <http method="get"
                  uri-template="https://www.googleapis.com/customsearch/v1?key={uri.var.apiKey}&amp;cx={uri.var.csiKey}&amp;q={uri.var.searchPara}" />
        </endpoint>
    </call>
    </sequence>
</template>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="googlecustomsearch_list"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
     <property name="apiKey" expression="json-eval($.apiKey)"/>
     <property name="csiKey" expression="json-eval($.csiKey)"/>
     <property name="searchPara" expression="json-eval($.searchPara)"/>
     <googleCustomSearch.listSearch>
        <apiKey>{$ctx:apiKey}</apiKey>
        <csiKey>{$ctx:csiKey}</csiKey>
        <searchPara>{$ctx:searchPara}</searchPara>
     </googleCustomSearch.listSearch>
     <respond/>
      </inSequence>
      <outSequence>
     <log/>
     <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
POST http://nilash-TECRA-M11:8280/services/googlecustomsearch_list

{
"apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
 "csiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
 "searchPara":"google"
}
Status Code: 202 Accepted
Connection: keep-alive
Date: Sat, 14 Jun 2014 05:22:34 GMT
Server: WSO2-PassThrough-HTTP
Transfer-Encoding: chunked
然后我得到如下输出:

<template name="listVolume" xmlns="http://ws.apache.org/ns/synapse">
    <parameter name="apiKey" description="Full-text search query string." />
    <parameter name="csiKey" description="Full-text search query string." />
    <parameter name="searchPara" description="Full-text search query string." />
    <sequence>
    <property name="uri.var.apiKey" expression="$func:apiKey" />
    <property name="uri.var.csiKey" expression="$func:csiKey" />
    <property name="uri.var.searchPara" expression="$func:searchPara" />
    <call>
        <endpoint>
            <http method="get"
                  uri-template="https://www.googleapis.com/customsearch/v1?key={uri.var.apiKey}&amp;cx={uri.var.csiKey}&amp;q={uri.var.searchPara}" />
        </endpoint>
    </call>
    </sequence>
</template>
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="googlecustomsearch_list"
       transports="https,http"
       statistics="disable"
       trace="disable"
       startOnLoad="true">
   <target>
      <inSequence>
     <property name="apiKey" expression="json-eval($.apiKey)"/>
     <property name="csiKey" expression="json-eval($.csiKey)"/>
     <property name="searchPara" expression="json-eval($.searchPara)"/>
     <googleCustomSearch.listSearch>
        <apiKey>{$ctx:apiKey}</apiKey>
        <csiKey>{$ctx:csiKey}</csiKey>
        <searchPara>{$ctx:searchPara}</searchPara>
     </googleCustomSearch.listSearch>
     <respond/>
      </inSequence>
      <outSequence>
     <log/>
     <send/>
      </outSequence>
   </target>
   <description/>
</proxy>
POST http://nilash-TECRA-M11:8280/services/googlecustomsearch_list

{
"apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
 "csiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
 "searchPara":"google"
}
Status Code: 202 Accepted
Connection: keep-alive
Date: Sat, 14 Jun 2014 05:22:34 GMT
Server: WSO2-PassThrough-HTTP
Transfer-Encoding: chunked
但搜索结果将不会显示。我在控制台中列出了以下错误

ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.apiKey>. Returning  empty result. Error>>> invalid path
[2014-06-14 10:52:34,883] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON  Path <$.csiKey>. Returning empty result. Error>>> invalid path
[2014-06-14 10:52:34,884] ERROR - SynapseJsonPath #stringValueOf. Error evaluating JSON Path <$.searchPara>. Returning empty result. Error>>> invalid path
ERROR-SynapseJsonPath#stringValueOf。计算JSON路径时出错。返回空结果。错误>>>无效路径
[2014-06-14 10:52:34883]错误-SynapseJsonPath#stringValueOf。计算JSON路径时出错。返回空结果。错误>>>无效路径
[2014-06-14 10:52:34884]错误-SynapseJsonPath#stringValueOf。计算JSON路径时出错。返回空结果。错误>>>无效路径
但如果我像这样将GoogleAPI密钥直接放在init文件的配置中,我可以得到预期的结果

 <http method="get" uri-template="https://www.googleapis.com/customsearch/v1?q={uri.var.searchQuery}&amp;key=XXXXXXXXXXXXXXXXXXX&amp;cx=XXXXXXXXXXXXXXXX"/>


有什么问题吗?

看来您在JSON路径上有错误,请更改

  <googleCustomSearch.listSearch>


试试看。使用下面列出的博客获取更多信息


JSON请求无效。你错过了“,”

{
“apiKey”:“XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX”,
“csiKey”:“XXXXXXXXXXXXXXXXXXXXXXXXXXXX”,
“searchPara”:“谷歌”

}
即使我更改了路径,我也收到了以下错误消息:{error:{errors:[1]0:{domain:“usageLimits”原因:“keyInvalid”消息:“Bad Request”}代码:400消息:“Bad Request”}因此它包含了您的错误..keyInvalid。。尝试使用其他一些应用程序帐户凭据