【发布时间】: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}&cx={uri.var.csiKey}&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}&key=XXXXXXXXXXXXXXXXXXX&cx=XXXXXXXXXXXXXXXX"/>
可能是什么问题?
【问题讨论】:
标签: wso2 wso2esb google-custom-search synapse