執行範例測試案例

您可以使用範例 Web 應用程式或指令行,在已部署的「SOA Policy Gateway 基本執行時期範例」上測試「範例」應用程式。您可在範例應用程式上執行六個指令行測試變式。

若要部署「基本範例執行時期」,請參閱部署基本執行時期範例型樣

執行範例 Web 應用程式測試案例

若要執行 Web 應用程式測試案例,請執行下列動作:
  1. 開啟已部署的「虛擬系統實例」,尋找已部署之 WSRR 環境的主機名稱。若要尋找主機名稱,請展開虛擬機器區段,然後選取 WSRR 獨立式伺服器的虛擬機器,以檢視虛擬機器詳細資料。在硬體與網路區段中,主機名稱為網路介面 0 值。
  2. 在 Web 瀏覽器中開啟 URL:http://<wssrHostName>:9080/SoaPolicyTester
  3. 下列為可用的選項:
    • 標準要求 - 將 findInventory 要求傳送至儲存服務。環境定義 ID 為 Silver。消費者 ID 為 CEO。成功的結果會顯示文字 Part: SKU10 Price: 401.73
    • 遞送原則測試 - 與「標準要求」相同,但其「環境定義 ID」為 Gold。要求會遞送至執行服務的替代端點。成功的結果會傳回 Part: GOLDSKU10 Price: 401.73
    • 驗證原則測試 - 傳送具有無效內容的要求。驗證原則需要 DataPower® 驗證要求,並拒絕那些無效的訊息。成功的結果為來自 DataPower "Internal Error (from client)" 的回應訊息。
    • REST Gold - 將要求傳送至「消費者 ID」為 CEO 且「環境定義 ID」為 Gold 的 SKU RESTful 服務。Gold 要求受制於 90 秒內僅允許 5 則訊息的原則。成功的要求會顯示結果 Part: SKU33 Price: 136.43
    • REST Silver - 與 Rest GOLD 相同,但具有「環境定義 ID」Silver。容許 Silver 要求在 90 秒內有個別的 3 個要求。成功的要求會顯示結果 Part: SKU33 Price: 136.43
    • 使用者 ID -「使用者 ID」選項具有兩個可能值:「完整內容」或「已編寫的內容」。每一個選項都會導致源自不同使用者的要求。範例會使用 XACML 原則,僅容許「經理」看到價格。除非選取了「完整內容」,否則會編寫回應訊息中「價格」的值。當選取「已編寫的內容」時,成功的要求結果包含 Price: 0.0。RESTful 服務不支援編寫。選取的使用者沒有任何效果。
  4. 開啟 WSRR 主控台,並瀏覽服務及原則。如需相關資訊,請參閱連接至 WSRR - Business Space

也可以使用指令行來練習範例。這是傳送使用「匿名 SLA」資料流量的唯一方法

使用指令行,利用「編寫」實務範例示範「XACML 允許/拒絕」

下列要求 XML 可以傳送至「DataPower StoreAddLTPA 服務」:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:stor="http://company.ibm.com/store">
  <soapenv:Header>
    <store:ConsumerIdentifier xmlns:store="http://store.com">CEO</store:ConsumerIdentifier>
    <store:ContextIdentifier xmlns:store="http://store.com">silver</store:ContextIdentifier>
  </soapenv:Header>
  <soapenv:Body>
  <stor:findInventory>
    <findInventoryReq>
      <sku>SKU10</sku>
    </findInventoryReq>
  </stor:findInventory>
  </soapenv:Body>
</soapenv:Envelope>
假設名稱為 silver.xml 的檔案中包含範例要求 XML,請輸入下列 curl 指令:
curl -k --data-bin @./silver.xml -H "Content-Type: text/xml"
-u ConsumerX:passw0rd http://<yourDataPowerHostName>:62005/Store/Store
在此範例中,ConsumerX 為「經理」,因此可在回應中看到完整價格資訊:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<KD4NS:KD4SoapHeaderV2
xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkZmExODgzNTQtY2Q1ZC0z
YjU0LWEyMzItZGM3MmEzNWY0MTAzACRmYWVjYjA1Mi1jMWUxLTMyODEtOWY3Ni0wY2IxN
mRhMDc4MjkAAw==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
  <b:findInventoryResponse xmlns:a="http://company.ibm.com/"
     xmlns:b="http://company.ibm.com/store">
  <findInventoryRes>
<sku>SKU10</sku>
<price>461.73</price>
<inventory>460</inventory>
<msrp>923.46</msrp>
<supplierID>IBM</supplierID>
</findInventoryRes>
</b:findInventoryResponse>
</soapenv:Body></soapenv:Envelope>

使用指令行執行「編寫」實務範例

ConsumerA 不是經理,因此看到不同回應。請輸入 curl 指令:
curl -k --data-bin @./silver.xml -H "Content-Type: text/xml"
-u ConsumerA:passw0rd http://<yourDataPowerHostName>:62005/Store/Store
請注意,回應已編寫價格。價格顯示為 0.0:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header><KD4NS:KD4SoapHeaderV2
xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkZmExODgzNTQtY2Q1ZC0zYjU0L
WEyMzItZGM3MmEzNWY0MTAzACRmYWVjYjA1Mi1jMWUxLTMyODEtOWY3Ni0wY2IxNm
RhMDc4MjkAAw==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
<b:findInventoryResponse xmlns:a="http://company.ibm.com/"
xmlns:b="http://company.ibm.com/store">
<findInventoryRes>
<sku>SKU10</sku>
<price>0.0</price>
<inventory>460</inventory>
<msrp>923.46</msrp>
<supplierID>IBM</supplierID>
</findInventoryRes>
</b:findInventoryResponse>
</soapenv:Body></soapenv:Envelope>

使用指令行測試遞送原則

若要強制執行附加至 Gold SLA 的遞送原則,則環境定義 ID 與消費者 ID 必須相符。在此情況下,Gold 客戶的 SLA 具有環境定義 ID Gold,而消費服務版本具有消費者 ID CEO。以下是範例要求的內容(您可以看到環境定義 ID 與消費者 ID 如同要求是相符的):

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:stor="http://company.ibm.com/store">
<soapenv:Header>
  <store:ConsumerIdentifier xmlns:store="http://store.com">CEO</store:ConsumerIdentifier>
  <store:ContextIdentifier xmlns:store="http://store.com">Gold</store:ContextIdentifier>
</soapenv:Header><soapenv:Body>
<stor:findInventory><findInventoryReq>
  <sku>SKU10</sku>
  </findInventoryReq>
</stor:findInventory>
</soapenv:Body></soapenv:Envelope>
假設名稱為 gold.xml 的檔案中包含範例要求 XML,請輸入下列 curl 指令:
curl -k --data-bin @./gold.xml -H "Content-Type: text/xml"
-u ConsumerX:passw0rd http://<yourDataPowerHostName>:62005/Store/Store
回應如下:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
  <KD4NS:KD4SoapHeaderV2
  xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkZmExODgzNTQtY2Q1ZC0zYjU0L
  WEyMzItZGM3MmEzNWY0MTAzACRmYWVjYjA1Mi1jMWUxLTMyODEtOWY3Ni0wY2IxNm
  RhMDc4MjkAAw==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header><soapenv:Body>
<b:findInventoryResponse xmlns:a="http://company.ibm.com/"
xmlns:b="http://company.ibm.com/store">
<findInventoryRes>
  <sku>GOLDSKU10</sku>
  <price>461.73</price>
  <inventory>460</inventory>
  <msrp>923.46</msrp>
  <supplierID>IBM</supplierID>
</findInventoryRes></b:findInventoryResponse>
</soapenv:Body>
</soapenv:Envelope>
請注意,回覆回應具有 GOLDSKU 代表 SKU 值,指出已使用 Gold 端點。

使用指令行測試綱目的驗證

驗證原則會對 Store.wsdl 及其相關聯的 Company.xsd 檢查要求的綱目。
下列 XML (badvalid.xml) 顯示無效的要求,無效的原因為內文包含名稱為 <skubad> 的元素,但它應該為 <sku>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:stor="http://company.ibm.com/store">
<soapenv:Header>
<store:ConsumerIdentifier xmlns:store="http://store.com">CEO</store:ConsumerIdentifier>
<store:ContextIdentifier xmlns:store="http://store.com">silver</store:ContextIdentifier>
</soapenv:Header>
<soapenv:Body>
<stor:findInventory>
<findInventoryReq>
<skubad>SKU10</skubad>
</findInventoryReq>
</stor:findInventory>
</soapenv:Body></soapenv:Envelope>

如果輸入下列 curl 要求:
curl -k --data-bin @./badvalid.xml -H "Content-Type: text/xml"
-u ConsumerX:passw0rd
http://<yourDataPowerHostName>:62005/Store/Store
畫面上會顯示下列錯誤:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault><faultcode>env:Client</faultcode>
<faultstring>Internal Error (from client)</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>

使用指令行測試調解原則中的拒絕

訊息計數在 90 秒內執行 5 次之後,範例中所包含的其中一個調解原則會測試拒絕。請執行下列指令 6 次:
curl -k --data-bin @./silver.xml -H "Content-Type: text/xml" -u ConsumerX:passw0rd
http://<yourDataPowerHostName>:62005/Store/Store
範例要求如下:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<KD4NS:KD4SoapHeaderV2
xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkZmExODgzNTQtY2Q1ZC0z
YjU0LWEyMzItZGM3MmEzNWY0MTAzACRmYWVjYjA1Mi1jMWUxLTMyODEtOWY3Ni0wY2IxN
mRhMDc4MjkAAw==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
<b:findInventoryResponse xmlns:a="http://company.ibm.com/"
xmlns:b="http://company.ibm.com/store">
<findInventoryRes>
在此情況下,ConsumerX 為「經理」,因此,在前面 5 次執行中會顯示完整價格資訊:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header>
<KD4NS:KD4SoapHeaderV2
xmlns:KD4NS="http://www.ibm.com/KD4Soap">AFIAAgAkZmExODgzNTQtY2Q1ZC0z
YjU0LWEyMzItZGM3MmEzNWY0MTAzACRmYWVjYjA1Mi1jMWUxLTMyODEtOWY3Ni0wY2IxN
mRhMDc4MjkAAw==</KD4NS:KD4SoapHeaderV2>
</soapenv:Header>
<soapenv:Body>
<b:findInventoryResponse xmlns:a="http://company.ibm.com/"
xmlns:b="http://company.ibm.com/store">
<findInventoryRes>
<sku>SKU10</sku>
<price>461.73</price>
<inventory>460</inventory>
<msrp>923.46</msrp>
<supplierID>IBM</supplierID>
</findInventoryRes></b:findInventoryResponse>
</soapenv:Body>
</soapenv:Envelope>
在第六次執行時,發生下列錯誤:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope
xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
<env:Body>
<env:Fault>
<faultcode>env:Client</faultcode>
<faultstring>Rejected (from client)</faultstring>
</env:Fault>
</env:Body>
</env:Envelope>
註: 如果在 90 秒間隔內執行其他測試,則會更快看到此錯誤。

使用指令行測試調解原則中的通知

通知原則會附加至匿名 SLA。當要求來自沒有既定 SLA 的消費者時,即會強制執行此原則。在此範例中,唯一有既定 SLA 的消費者為 CEO,因此要求若包含設為任何其他值的消費者 ID,則會導致強制執行匿名 SLA 上的原則。在此情況下,ConsumerX 為「經理」,因此會顯示完整價格資訊:

若要使用指令行測試此功能,請建立包含下列 XML、名稱為 anon.xml 的檔案:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:stor="http://company.ibm.com/store">
<soapenv:Header>
  <store:ConsumerIdentifier xmlns:store="http://store.com">ABC</store:ConsumerIdentifier>
  <store:ContextIdentifier xmlns:store="http://store.com">Gold</store:ContextIdentifier>
</soapenv:Header><soapenv:Body>
<stor:findInventory><findInventoryReq>
  <sku>SKU10</sku>
  </findInventoryReq>
</stor:findInventory>
</soapenv:Body></soapenv:Envelope>
然後輸入下列指令:
curl -k --data-bin @./anon.xml -H "Content-Type: text/xml"
-u ConsumerX:passw0rd http://<yourDataPowerHostName>:62005/Store/Store
下列訊息為網域預設日誌中的輸出:
Notify action triggered ('operation_38_2_sla1-1-filter_1-notify') from source policy (
   'LogEveryTime_287d0790-83d9-11e1-a255-9187e20cddb0_05aec6ec-3674-4165-85de-a0f7be48a938'
註: 記載必須設為「通知」,才能看到此訊息。如果未設定,請按一下「DataPower Web 主控台」中的疑難排解圖示。在「記載」區段中,將「記載層次」值變更為「通知」,然後按一下設定記載層次。若要尋找日誌,請回到「控制台」,然後按一下檢視日誌圖示。

使用指令行測試 RESTful 服務

您也可以使用 curl 從指令行存取 RESTful 介面。如同 Web 用戶端一般,ContextID 若為 Gold,每 90 秒允許 5 則訊息,若為 Silver,則允許 2 則訊息。

若要使用指令行測試此功能,請建立包含下列 XML、名稱為 restRequest.xml 的檔案:

<?xml version="1.0" encoding="UTF-8"?>
<a:WarehouseSKUPost xmlns:a="http://company.ibm.com/">
   <postRequest>
      <sku>SKU33</sku>
      <purchaseCost>136.43</purchaseCost>
      <inventory>429</inventory>
      <msrp>272.86</msrp>
      <returns>0</returns>
   </postRequest>
</a:WarehouseSKUPost>

然後輸入下列指令,利用 contextID Gold 進行測試:

curl -k --data-bin @./restRequest.xml -H "Content-Type: text/xml" -H "consumerID:CEO" -H "contextID:Gold"  http://<yourDataPowerHostName>:62006/WarehouseSKU

若要利用 Silver contextID 進行測試,請使用相同指令,但將 Gold 取代為 Silver。

成功回應為:

<?xml version="1.0" encoding="UTF-8"?>
<a:WarehouseSKUGet xmlns:a="http://company.ibm.com/">
<getRequest>
<sku>SKU33</sku>
<purchaseCost>136.43</purchaseCost>
<inventory>429</inventory>
<msrp>272.86</msrp>
<returns>0</returns>
<supplierID>ABB</supplierID>
<purchaseID/>
</getRequest>
</a:WarehouseSKUGet>
在違反臨界值之後,您會收到下列訊息:
<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"><env:Body><env:Fault><faultcode>env:Client</faultcode><faultstring>Rejected (from client)</faultstring></env:Fault></env:Body></env:Envelope>

若要練習 RESTful 服務的匿名 SLA,其中僅附加通知原則,請使用已登錄以外的任何 ContextID 及 ConsumerID。如同先前「Web 服務」範例所說明,通知會出現在 DataPower 日誌中。


概念 概念

反饋


「時間戳記」圖示 前次更新: 2014 年 3 月 5 日


http://publib.boulder.ibm.com/infocenter/prodconn/v1r0m0/topic/com.ibm.scenarios.soawdpwsrr25.doc/topics/csoa2_sample_run.htm