I'm trying to create a Google Custom Search connector for WSO2 ESB. After creating the connector I have added the connector to ESB. Then I want to test it.
My test init file like this:
<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>
After I have configured a custom proxy service within the ESB like this:
<?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>
Then I test it in a REST client like this:
POST http://nilash-TECRA-M11:8280/services/googlecustomsearch_list
{
"apiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"csiKey":"XXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
"searchPara":"google"
}
Then I get the output like this:
Status Code: 202 Accepted
Connection: keep-alive
Date: Sat, 14 Jun 2014 05:22:34 GMT
Server: WSO2-PassThrough-HTTP
Transfer-Encoding: chunked
But the searched results will not appears.I got below listed this error in console.
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
But if I put Google API keys directly in my configuration in init file like this I can get expected results.
<http method="get" uri-template="https://www.googleapis.com/customsearch/v1?q={uri.var.searchQuery}&key=XXXXXXXXXXXXXXXXXXX&cx=XXXXXXXXXXXXXXXX"/>
What can be the problem?