向出局响应消息添加 SOAP 头
您可以使用系统变量和一些 JavaScript 代码将 SOAP 头添加到出站响应消息。
关于本任务
IBM® Business Process Manager 提供了一个系统变量,允许您将 SOAP 头添加到出站响应消息 tw.system.header.soap.response。 您可以从流程图上方的 变量 选项卡或在 JavaScript 代码中实例化 tw.system.header.soap.response 变量。
过程
要向出站响应消息添加 SOAP 头,请向 tw.system.header.soap.response 系统变量中的 SOAPHeaders 数组添加一个条目。
您可以将代码添加到常规系统服务的组件 (例如服务器脚本组件) 中的 部分。
要将名为 sessionToken 的头添加到响应消息,请使用 JavaScript 代码,如以下示例所示。 编写代码时,请遵循以下最佳实践来操作:
- 确保名称空间采用标准形式,如以下示例所示。
- 避免在构成 SOAP 头值的 XML 片段中出现空格。
- 如果 tw.system.header.soap.response 变量为 Null,请确保您只实例化此变量。 否则,最终可能会清除由 General System Service 内某些其他组件添加的 SOAP 头条目。
log.info(">>>>>> Adding a SOAP header to the response message...")
// Create the header object
var myResponseHeader = new tw.object.SOAPHeader()
myResponseHeader.name = "sessionToken"
myResponseHeader.nameSpace = "http://acme.com"
myResponseHeader.value = "<x:sessionToken xmlns:x=\"http://acme.com\">abdf-128974-33-33-fcea-10243-74-33</x:sessionToken>"
// If the response header system variable doesn't exist yet,
// then you must instantiate it
if (tw.system.header.soap.response == null) {
tw.system.header.soap.response = new tw.object.SOAPHeaders()
tw.system.header.soap.response.headers = new Array()
}
// Determine which index we need to use when adding the new header entry.
//Add the new header at the end of the array so that the processing does not
// overwrite any existing entries.
var nextIndex = tw.system.header.soap.response.headers.listLength
log.info("Adding new header at index: " + nextIndex)
tw.system.header.soap.response.headers[nextIndex] = myResponseHeader注:
- 只有 SOAPHeader 的值用于构造响应 soap 消息。 不使用名称和名称空间。 在此示例中,如果更改
myResponseHeader.name或myResponseHeader.nameSpace的值,但不更改myResponseHeader.value,那么此更改不会反映在响应消息中。 - 将新的 SOAP 头条目添加到 tw.system.header.soap.response 变量
头
字段 ( 这是 SOAP 头值的数组 ) 时,请使用下一个可用索引。 否则,可能会无意中清除由 General System Service 内某些其他组件添加的现有 SOAP 头条目。