How to Create a Response Message
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).
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, as shown below.
headers = processContext.getVariable("newMsg").getTransportHeaders(); headers.add("HeaderName", "headerValue");