전환 조건 스크립트 작성- DataPower Gateway (v5 compatible)
GatewayScript를 사용하여 DataPower® Gateway (v5 compatible) 에서 switch 정책에 대한 조건 스크립트를 작성합니다.
switch 조건을 참조하려면
apim.getvariable('context.location.variable')
양식을 사용하십시오. 여기서 context는 참조할 컨텍스트이고
location은 해당 컨텍스트 내 변수 위치이며 variable은 변수의 이름입니다.
호출된 조작을 기반으로
switch 조건을 정의하려면 다음 양식 중 하나를 사용하십시오.- condition: "((request.verb==='GET')&&(api.operation.path==='/path-1'))"- condition: "((api.operation.id=='Operation_ID'))"여기서,
컨텍스트 변수 request.verb 및 api.operation.path는
케이스를 적용하려는 API 및 오퍼레이션의 HTTP verb 및 경로 세그먼트를 검색하는 반면,
api.operation.id는 지정된 경우 오퍼레이션의 오퍼레이션 ID를 검색합니다.사용 가능한 컨텍스트 변수와 스크립트에서 이를 참조하는 방법에 대한 자세한 내용은 API Connect 의 컨텍스트 변수 항목을 참조하십시오.
예제 switch 정책
- switch:
version: 1.0.0
title: switch
case:
- condition: message.status.code===200
execute:
- invoke:
title: invoke
timeout: 60
verb: GET
cache-response: protocol
cache-ttl: 900
target-url: 'https://example.com/1'
- condition: ((request.verb==='GET')&&(api.operation.path==='/path-2'))||((request.verb==='GET')&&(api.operation.path==='/path-1'))
execute:
- invoke:
title: invoke
timeout: 60
verb: GET
cache-response: protocol
cache-ttl: 900
target-url: 'https://example.com/2'
- otherwise:
- set-variable:
title: set-variable
actions:
- set: message.body
value: Default result
description: Set the default result for the otherwise case