【问题标题】:Sending POST request to ESB向 ESB 发送 POST 请求
【发布时间】:2014-08-04 16:54:31
【问题描述】:

我正在尝试为WSO2 ESB 创建一个 Google 自定义搜索连接器。创建连接器后,我已将连接器添加到 ESB。那我想测试一下。

我的测试初始化​​文件是这样的:

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

在 ESB 中像这样配置自定义代理服务后:

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

然后我在这样的 REST 客户端中对其进行测试:

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

但是,如果我像这样将 Google API 密钥直接放在我的配置中的 init 文件中,我可以获得预期的结果。

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

可能是什么问题?

【问题讨论】:

    标签: wso2 wso2esb google-custom-search synapse


    【解决方案1】:

    您的 JSON 路径似乎有错误,请更改

      <googleCustomSearch.listSearch>
    

     <googleCustomSearch.listVolume>
    

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

    http://chanakaindrajith.blogspot.com/2014/04/getting-started-with-wso2-esb-connectors.html

    【讨论】:

    • 即使我更改了路径,我也收到以下错误消息:{ error: { errors: [1] 0: { domain: "usageLimits" reason: "keyInvalid" message: "Bad Request " } 代码:400 消息:"错误请求" } }
    • 所以它包括你的错误..keyInvalid..尝试使用其他一些应用程序帐户凭据developers.google.com/custom-search/json-api/v1/using_rest
    【解决方案2】:

    JSON 请求无效。你错过了','

    {
    "apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
     "csiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX",
     "searchPara":"google"
    }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-29
      • 1970-01-01
      • 1970-01-01
      • 2017-02-07
      • 2015-09-20
      • 1970-01-01
      相关资源
      最近更新 更多