2013-12-10 3 views
0

제대로 작동하는 Apigee로 만든 API 프록시가 있습니다. 그러나 자원 이름을 변경하려고합니다. 나는이 같은 프록시 자원 이름을 바꿀Apigee - 다른 리소스로 리디렉션하는 방법

<myService>/collection/{Id}/products에 리디렉션

<proxy>/collection/{Id}/product의 : 현재

, 나는 다음과 같은 자원이

<proxy>/collection/{Id}/apps<myService>/collection/{Id}/products

로 리디렉션 무엇 Apigee와 함께하는 가장 좋은 방법은?

건배, Chavdar

+0

기존의 XML은 무엇 당신이있어? 그리고 어떤 끝점 (프록시 또는 대상)이 켜져 있습니까? – brandonscript

+0

"리디렉션"의 의미를 명확히하십시오. 'Location' 헤더를 다시 보내시겠습니까, 아니면 타겟의 다른 경로를 프록시하려고합니까? – OmidTahouri

+0

다른 대상을 프록시하려고합니다. 감사! – Chavdar

답변

0

당신이 /collection/{id}/products-/collection/{id}/apps에 대한 프록시 요청에 같은 코드를 다음 코드로 대상 요청에 자바 스크립트 정책을 추가하려는 경우 :

var collection_id = 10; //you should get this using context.getVariable() 
var path = '/collection/' + collection_id + '/products'; //new path 
var current_target_url = context.getVariable('target.url'); //get the existing target url 
context.setVariable('target.copy.pathsuffix', false); //tell apigee to not copy the path over to the target 
context.setVariable('debug.js.path', current_target_url + path); //this line is only for seeing the value in the trace tool 
context.setVariable('target.url', current_target_url + path); //set the new path 
+0

시도해보십시오. 작동 방식처럼 보입니다. 유일한 문제는 앱뿐만 아니라 모든 리소스를 제품으로 리디렉션한다는 것입니다. 프록시 요청에서이 작업을 시도했습니다 : var collection_id = 1; // context.getVariable()을 사용하여 이것을 얻어야합니다. var path = '/ collection /'+ collection_id + '/ products'; // 새 경로 var current_request_path = context.getVariable ('request.path'); // 기존 요청 경로를 얻습니다. context.setVariable ('request.path', path);// 새 경로를 설정 이것은 작동하지 않았다 .. 어떤 아이디어? – Chavdar

+0

새 URL을 대상에 설정해야합니다. 요청이 도착할 곳이기 때문입니다. if (context.getVariable ('proxy.pathsuffix') == "/ collection/{id}/apps") {...}'조건으로 코드를 래핑 할 수 있습니다. 또는, JavaScript ''의''에 동일한 로직을 추가하십시오. – OmidTahouri

관련 문제