Retrieving SOAP headers from an inbound request message

You can retrieve SOAP headers from an inbound request message by writing some JavaScript code to capture data from the tw.system.header.soap.request system variable.

Before you begin

This task requires that you have access to an inbound web service integration that has at least one general system service associated with it.

About this task

IBM® Business Process Manager provides a system variable that you can use to retrieve SOAP headers. SOAP headers found in inbound request messages are automatically copied to the tw.system.header.soap.request system variable. You can write code to retrieve those SOAP headers.

Procedure

To retrieve SOAP headers from an inbound SOAP request message, write JavaScript code that uses the tw.system.header.soap.request system variable.
You can add a component, such as a server script component, to your general system service. You can then add your JavaScript code to this component's Properties view within the Pre-execution or Post-execution Assignments section or within the Implementation section. Alternatively, you can add the code to any location that is part of the general system service for the endpoint.

In this example, the code example is retrieving a header named subscriptionInfo of type SOAPHeader from the system variable tw.system.header.soap.request. If the request message contains SOAP headers, this variable will be initialized to contain them. If the request message does not contain SOAP headers, this variable will be null.

log.info(">>>>>> Checking to see if the subscriptionInfo SOAP header was received in the request message...")

var subscriptionInfoHeader = null

if (tw.system.header.soap.request != null) {
    for (var i = 0; i < tw.system.header.soap.request.headers.listLength; i++) {
        // search for the subscriptionInfo header
        if (tw.system.header.soap.request.headers[i].name == "subscriptionInfo") {
           subscriptionInfoHeader = tw.system.header.soap.request.headers[i]
       }
   }
}

if (subscriptionInfoHeader != null) {
    log.info("Found the subscriptionInfo SOAP header!")
}
else {
    log.info("The subscriptionInfo SOAP header was not present in the request message.")
}
Assume that the following SOAP header is in a request message:
<ns1:subscriptionInfo xmlns:ns1="http://acme.com">1234-56-7890-fc3a</ns1:subscriptionInfo>
The following output is produced by the code in that example:
Found the subscriptionInfo SOAP header!