How to Create a Response Msg
This article describes how to create a virtual service process that creates a response message using input from the request message and returns this response to the consumer. This is useful for creating sandbox services. In this case I am adding a protocol header that is specific to SOAP, this header would only be returned via a SOAP binding, but the process generates a normalized XML message that can be returned via any of the bindings, including being mediated to JSON if that is required.
NOTE: this article doesn’t cover configuring the bindings, all it does is tell you how to create the response message and wire that into your process.
Step 1 - Define a Variable
Use the ‘A’ button on the process editor palette to define a new variable name of type message. To match the script below we’ll call this new message variable ‘newMsg’. Note: all adding a variable here does is to make the variable name available to other activities in the process editor.
Step 2 - Set the Reply to use the new Variable
Edit the reply activity and pick your new message variable as the response message (the field labelled variable).
Step 3 - Add a Script Activity between the receive and the reply
Add a script activity between the receive and the reply, and use the script below. This script performs a few operations:
- creates a new normalized message
- adds a new protocol (binding) header to the new message - this is Optional, and is here simply to show how this works between SOAP and REST bindings (it’s ignored by the REST binding)
NOTE: there is a known issue in releases prior to 7.2.10 that means that setProtocolHeader() only works on newly created messages. After 7.2.10 you will be able to use setProtocolHeader() to add new headers to the input message (after normalization).
Step 4 - Preserve Binding Headers - Optional
Edit the operation, select Header Propagation, and set Preserved Binding Headers to all, or add the specific header you want to pass through the downstream binding in this list.
This is only needed if you want to pass specific headers back to the consumer. For REST consumers you would typically enable Preserve Transport Headers and would use the setTransportHeaders() function:
headers = processContext.getVariable("newMsg").getTransportHeaders(); headers.add("HeaderName", "headerValue");