运行样本测试用例

您可以使用样本 Web 应用程序或命令行测试已部署 SOA Policy Gateway Basic Runtime Sample 上的样本应用程序。 可在样本应用程序上运行六个命令行测试变体。

要部署 Basic Sample Runtime,请参阅部署 Basic Runtime Sample 模式

运行样本 Web 应用程序测试用例

要运行 Web 应用程序测试用例,请执行以下操作:
  1. 通过打开已部署的“虚拟系统实例”,找到已部署 WSRR 环境的主机名。要查找主机名,请展开虚拟机部分,并选择 WSRR 独立服务器的虚拟机以查看虚拟机详细信息。在硬件和网络部分,主机名为网络接口 0 值。
  2. 在 Web 浏览器中打开 URL:http://<wssrHostName>:9080/SoaPolicyTester
  3. 可以使用下列选项:
    • 标准请求 - 将 findInventory 请求发送至店铺服务。上下文标识为 Silver。使用者标识为 CEO。成功的结果显示文本“Part: SKU10 Price: 401.73”。
    • 路由策略测试 - 与标准请求相同,但上下文标识为 Gold。该请求将路由至运行该服务的备用端点。成功的结果返回“Part: GOLDSKU10 Price: 401.73”。
    • 验证策略测试 - 发送具有无效内容的请求。验证策略要求 DataPower® 验证该请求,并拒绝那些无效消息。成功的结果是来自 DataPower 的响应消息:“Internal Error (from client)”
    • REST Gold - 将使用者标识为 CEO 且上下文标识为 Gold 的请求发送至 SKU RESTful 服务。 Gold 请求遵从 90 秒内只允许 5 条消息的策略。成功的请求显示结果“Part: SKU33 Price: 136.43”。
    • REST Silver - 与 Rest GOLD 相同,但上下文标识为 Silver。 允许 Silver 请求在 90 秒内有 3 个单独请求。成功的请求显示结果“Part: SKU33 Price: 136.43”。
    • 用户标识 -“用户标识”选项具有两个可能值:“完整内容”或“编辑内容”。每个选项将产生来自不同用户的请求。 该样本使用 XACML 策略,此策略只允许经理查看价格。将编辑响应消息中 Price 的值,除非选择了“完整内容”。选择“编辑内容”时请求的成功结果包含“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>
假定示例请求 XML 包含在名为 silver.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 的路由策略,上下文标识和使用者标识必须匹配。 在此情况下,针对 Gold 客户的 SLA 具有上下文标识 Gold,使用方服务版本具有使用者标识 CEO。以下是样本请求的内容(您可能看到,上下文标识和使用者标识已按照要求进行匹配):

<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>
假定示例请求 XML 包含在名为 gold.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 是一位经理,因此,针对前五次运行会显示完整价格信息,如下所示:
<?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,因此使用者标识设置为其他任何内容的请求将导致实施匿名 SLA 上的策略。 在本例中,ConsumerX 是一位经理,因此显示完整价格信息:

要使用命令行测试此功能,请创建一个名为 anon.xml 的文件,其中包含以下 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 客户机一样,上下文标识 Gold 每 90 秒允许 5 条消息,Silver 只允许 2 条消息。

要使用命令行测试此功能,请创建一个名为 restRequest.xml 的文件,其中包含以下 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。 通知将出现在 DataPower 日志中,如先前针对 Web Service 示例所述的那样。


概念 概念

反馈


时间戳记图标 最近一次更新时间: 2014 年 3 月 5 日


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