2014-06-14 6 views
3

WSO2 ESB에 대한 Google 맞춤 검색 커넥터를 만들려고합니다. 커넥터를 만든 후에는 커넥터를 ESB에 추가했습니다. 그런 다음 테스트 해보고 싶습니다.ESB에 POST 요청 보내기

이 같은

내 테스트 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> 

나는이 같은 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 키를 설정 파일에 직접 입력하면 예상되는 결과를 얻을 수 있습니다.

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

무엇이 문제 일 수 있나요?

답변

3

당신이 JSON 경로에 오류가있는 것 같다,

<googleCustomSearch.listSearch> 

<googleCustomSearch.listVolume> 

을 변경하려고합니다. 아래에 나열된 블로그를 사용하여 자세한 정보를 얻으십시오.

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

+0

심지어 내가 경로를 변경해야 ','부재중, 나는 다음과 같은 오류 메시지를 가지고 : { 오류 : { 오류 : [1] 0 : { 도메인 : "usageLimits" 이유 : "keyInvalid" 메시지 : "잘못된 요청" } 코드 : 400 메시지 : "잘못된 요청" } } – nilashan

+1

그래서 귀하의 오류를 포함합니다 ..keyInvalid .. 다른 앱 계정 인증 정보로 시도하십시오 https://developers.google.com/custom-search/json-api/v1/using_rest – Dakshika

0

json으로 요청이 잘못되었습니다. 당신이

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