【发布时间】:2020-11-21 10:00:21
【问题描述】:
我使用 Integrator 工具创建了一个 REST API。我可以连续调用,但我不知道如何存储和使用第一次调用的响应作为标题来调用下一个端点。
场景是:我必须首先调用一个端点来获取一个令牌,响应我想设置一个带有承载令牌的标头来检索一个调用下一个端点的 JSON 文件。
我的代码:
<?xml version="1.0" encoding="UTF-8"?>
<api context="/example" name="example" xmlns="http://ws.apache.org/ns/synapse">
<resource methods="POST GET">
<inSequence>
<log description="request log" level="full"/>
<payloadFactory description="body" media-type="json">
<format>
{
"grant_type": "authorization_code"
}
</format>
<args/>
</payloadFactory>
<call>
<endpoint>
<http method="post" statistics="enable" trace="enable" uri-template="http://localhost:5000/token">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
<property name="grant_type" scope="transport" value="authorization_code"/>
</endpoint>
</call>
<filter regex="200" source="get-property('axis2', 'HTTP_SC')">
<then>
<log level="custom">
<property name="switchlog" value="Case: first call successful"/>
</log>
<call>
<endpoint>
<http method="get" uri-template="http://localhost:5000/json">
<suspendOnFailure>
<initialDuration>-1</initialDuration>
<progressionFactor>1</progressionFactor>
</suspendOnFailure>
<markForSuspension>
<retriesBeforeSuspension>0</retriesBeforeSuspension>
</markForSuspension>
</http>
</endpoint>
</call>
<respond description="final"/>
</then>
<else>
<log level="custom">
<property name="switchlog" value="Case: first call unsuccessful"/>
</log>
<respond/>
</else>
</filter>
</inSequence>
<outSequence/>
<faultSequence/>
</resource>
</api>
我该怎么做?
【问题讨论】: