網路服務整合類型預設回傳的回應是什麼?
問題
Web Service Integration 預設會回傳什麼回應?
解答
每種回應的結構會根據所選的 Content-type 設定而有所不同。
Content-type 格式說明:
- application/json:以 json 格式字串呈現,資訊會包在 { 大括號 } 內
- text/xml:標準 XML 格式。使用像 Insomnia 這類視覺化工具查看時,會自動排版讓內容更易讀。
- application/soap-xml:同上為標準 XML 格式,但會以 SOAP 訊息方式傳送,而非純文字
- text:未經格式化的 XML 回應。
%response% 變數
XML 格式的範例回應:
<Response Version="2.0" AppName="BarTender" AppVersion="2016 R8" AppVersionId="1100" AppVersionMajor="11" AppVersionMinor="0" AppVersionBuild="3146" AppInstancePid="29400" AppInstanceGuid="{303F1806-45E6-451E-9EA6-4C13CA93B299}">
<User>XXXXXX</User>
<Server>XXXXX</Server>
<Command Name="Print Document">
<Print ID="25" GUID="{59C2B1CF-B7E9-4572-B97B-66E4955993D7}" JobLastStatus="Queued" JobCompleted="true" JobName="resttest2.btw">
<JobStatus Completed="true">
<TimeJobStart>2018-07-05T10:38:38.183</TimeJobStart>
<TimeJobQueued>2018-07-05T10:38:38.261</TimeJobQueued>
<TimeJobSent>2018-07-05T10:38:38.261</TimeJobSent>
<LastStatus>Queued</LastStatus>
<Description>Print job now waiting to be sent to printer.</Description>
</JobStatus>
<Message Id="1750" Guid="{889B2413-F92A-4774-A0E8-E931F25F12EC}" Severity="Information" Category="Printing" Response="OK">
<Text>BarTender successfully sent the print job to the spooler.
Job Name: resttest2.btw
Document: resttest2.btw
Printer: Zebra 140XiIII Plus</Text>
</Message>
</Print>
</Command>
</Response>
如果你想查詢列印狀態,可以參考 print 標籤中的這個參數:
JobCompleted="true"
或是以下這個:
JobStatus Completed="true"
這些標籤代表列印工作已成功送到列印佇列。此時,該工作已經離開整合的控制範圍。Message 標籤中的訊息也會以更易懂的方式顯示相同資訊。如果有錯誤導致列印工作無法送入佇列,回應會是:
%Response%
如果 Printer Maestro 服務沒有運作,你可能會收到誤判(或這裡的誤判為 false negative):
<Print ID="29988" GUID="{22999A4F-40C7-4F30-BB44-BED5F93691C8}" JobLastStatus="Unknown" JobCompleted="false" JobName="Label_v1.btw">
<JobStatus Completed="false">
.....
<LastStatus>Unknown</LastStatus>
<Description>Print job status is unknown because the Printer Maestro Service that is running on the computer that the printer is attached to is not responding.</Description>
</JobStatus>
即使工作實際上已經完成,回應仍會顯示未完成,因為無法與 Printer Maestro 服務溝通。
回應變數的值
- JobLastStatus:幾乎總是 "queued",表示工作已送入佇列。如果顯示 unknown,代表整合無法與 Maestro 服務溝通。
- JobCompleted:如果工作已送入佇列,會顯示 "True"。若 Maestro 服務未正常運作,可能會顯示 false。
- Job Status Completed:確認工作已完成
- Command Name:整合中列印動作的名稱
動作摘要
JSON 格式的成功回應範例:
{
"Version": "1.0",
"Status": "RanToCompletion",
"WaitStatus": "Completed",
"Validated": true,
"Messages": [
{
"ActionName": "Print Document",
"Level": 2,
"Text": "BarTender successfully sent the print job to the spooler.\r\n\r\nJob Name: resttest.btw\r\nDocument: resttest.btw\r\nPrinter: Datamax I-4208"
}
]
}
錯誤回應範例:
{
"Version": "1.0",
"Status": "Faulted",
"WaitStatus": "Faulted",
"Validated": true,
"Messages": [
{
"ActionName": "Print Document",
"Level": 4,
"Text": "BarTender cannot use printer 'fakeprinter' to design, print, or export a template due to a printer setup problem."
}
]
}
這個回應範例很簡短,因為這個整合只包含一個動作。這裡回應的動作,就是整合中設定的動作:
動作回應的值
- Status:值為 "RanToCompletion" 或 "Faulted"
- WaitStatus:值為 "Completed" 或 "Faulted"
- ActionName:正在列印的動作名稱。動作回應只會回報列印動作的資訊,即使有其他動作也不會顯示。
- Text:你也可以在管理主控台或 Integration Builder 的整合訊息中看到的訊息內容。
另請參閱
如何將印表機資料放入 Web Service Integration 的回應中
Web service integration 回應誤報列印工作未完成
內部備註
雖然列印工作資訊看起來依賴於佇列服務,但實際上似乎是從 Printer Maestro 服務取得。如果 Maestro 服務未正常運作,回應可能會出現誤判(或這裡的誤判為 false negative)。由於開發端沒有明確說明兩者如何溝通,我們只能根據這些現象來判斷。
這會影響 XML 變數 JobLastStatus 和 LastStatus,以及 JSON 變數 Status 和 WaitStatus
變數回應
這個回應中可以傳送任何內容。本文僅說明 BarTender 產生的回應。只要整合未失敗,這些回應會包含較多有用的工作資訊。如果整合失敗,就只會回傳變數。
動作回應
這個回應完全沒有相關文件說明,甚至在說明文件中也沒提到。據說這是後來新增的,但 JIRA 上也沒有明確記錄是什麼時候加入的。
目前還不清楚 Status 和 WaitStatus 有什麼差別。它們看起來回報的是同樣的資訊,只是用不同的詞。
Level 參數似乎是指目前動作在動作清單中的位置,從 "Action" 區段開始為 1。所以上圖中,Action 是 1,Print Document 是 2。這可能跟整合的寫法有關,但對客戶來說應該沒什麼實際用途。