Flex Gateway新着情報
Governance新着情報
Monitoring API ManagerAPIkit を使用して、WSDL 宣言に基づいて、アプリケーションの応答にヘッダーを追加します。
この例を実行するには、tshirt2.wsdl API 定義をダウンロードして、それに基づいて Mule アプリケーションを作成する必要があります。
詳細は、「APIkit for SOAP を使用する場合の前提条件」と「APIkit for SOAP プロジェクトの作成」を参照してください。
次の例では、アプリケーションの応答に APIUsageInformation ヘッダーを追加しています。
Anypoint Studio で、src/main/resources/api の tshirt2.wsdl を開き、コントラクトで必要な APIUsageInformation 要素までスクロールします。
キャンバスで、OrderTshirt:/soapkit-config フローの Transform Message コンポーネントを選択します。
次の DataWeave コードを使用できます。
{
body : {
ns0#OrderTshirtResponse: {
orderId: "I got a request from "
++ payload.body.ns0#OrderTshirt.name
++ " using the following auth header "
++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
}
} write "application/xml"
}
APIUsageInformation ヘッダー宣言を追加します。
{
body : {
ns0#OrderTshirtResponse: {
orderId: "I got a request from "
++ payload.body.ns0#OrderTshirt.name
++ " using the following auth header "
++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
}
} write "application/xml",
headers: { (1)
header: {
ns0#APIUsageInformation: {
}
} write "application/xml"
}
}
| 1 | この DataWeave コードは、Transform Message コンポーネントで生成される出力にヘッダーを追加します。 |
apiCallsRemaining ヘッダーを APIUsageInformation 要素に追加します。
{
body : {
ns0#OrderTshirtResponse: {
orderId: "I got a request from "
++ payload.body.ns0#OrderTshirt.name
++ " using the following auth header "
++ (payload.headers["AuthenticationHeader"].ns0#AuthenticationHeader.apiKey default "")
}
} write "application/xml",
headers: {
header: {
ns0#APIUsageInformation: {
apiCallsRemaining: 10 (1)
}
} write "application/xml"
}
}
| 1 | apiCallsRemaining を 10 に設定します。 |
保存してプロジェクトをもう一度実行します。
SoapUI で、OrderTshirt 要求をもう一度実行します。
APIkit for SOAP の応答エンベロープは次のようになります。
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ns0:APIUsageInformation xmlns:ns0="http://mulesoft.org/tshirt-service">
<apiCallsRemaining>10</apiCallsRemaining>
</ns0:APIUsageInformation>
</soap:Header>
<soap:Body>
<ns0:OrderTshirtResponse xmlns:ns0="http://mulesoft.org/tshirt-service">
<orderId>I got a request from John, using the following auth header 987654321</orderId>
</ns0:OrderTshirtResponse>
</soap:Body>
</soap:Envelope>