06 August 2007 - 1.7.5 |
A MockResponse holds an actual response to returned from a MockOperation. The response can be configured in regard to response content, http headers, attachments and dynamic processing using groovy (for example to process the input or read data from some external source).
MockResponses are added to a MockOperation from their popup menu or from the Request popup/editor with the "Add to MockService" action/button.
Right-clicking a MockResponse node in the navigator or in the MockOperation editor
shows a popup menu with the following actions:
| ![]() |
The bottom left details tab for a MockResponse displays the following properties:
| ![]() |
Double-clicking a MockResponse in the navigator or MockOperation editor opens the MockResponse editor as seen below:
This editor is more or less a copy of the standard request editor, but shifts focus to the right-hand response area where the MockResponse is configured. The left hand request area shows the latest request handled by this MockResponse, including its HTTP Headers and Attachments.
The Response Area contains the same XML Source editor, HTTP Headers tab and Attachments tab as in the Request Editor (but now all editable). Additionally, a "Response Script" tab is available that displays a groovy script editor for creating scripts that should be executed before returning the actual response content (see more below).
The toolbar at the top of the MockResponse editor contains the following actions (left to right):
The "Response Script" tab shows a standard groovy editor for a script that will be executed prior to returning the configured response message, opening for the possibility to create response specific scripts that can dynamically create content of the outgoing response.
The script has access to the following objects:
log
- a standard log4j Logger for logging arbitrary information to the groovy logcontext
- an instance of
MockRunContext
that can hold dynamically user-defined properties. The context is service scoped, ie shared between
all MockOperations/MockResponses for a MockService during its lifetime. Since this object implements the Map
interface
it can be accessed using groovy's built-in collection support (see example screenshot above)requestContext
- an instance of
MockRunContext
that can hold dynamically user-defined properties. The context is request scoped, ie is only available during this
request and not shared with other mockoperations. Use this to pass values from the dispatch script to the handling
MockResponse. Since this object implements the Map
interface
it can be accessed using groovy's built-in collection support.mockRequest
- an instance of
WsdlMockRequest
which provides access to request-related objects, including the underlying HttpServletRequest/HttpServletResponse objectsmockResponse
- an instance of
WsdlMockResponse
which provides access to the current MockResponse object (for example for dynamic manipulation of attachments)The Run button in the script toolbar will attempt to run the script, setting the context to either the currently available context (if the MockService is running) or an empty one. The mockRequest will be set to the last handled request if available.
Properties set in the context can the be used using standard property expansion in the response, for example the following script:
context.randomValue = Math.random()
creates a "randomValue" property which can then be "used" in the outgoing response:
<detail>${randomValue}</detail>