Response
Return a fixed or templated HTTP response.
Forward
Proxy the request to another server, optionally modifying it.
Callback
Invoke a Java class or closure to generate the response dynamically.
Error
Return invalid bytes or drop the connection to simulate network failures.
Response
A response action returns an HTTP response you define. You can set the status code, reason phrase, headers, cookies, body, and delay.Status code and reason phrase
Headers, cookies, and body
Delay
Connection options
UseconnectionOptions to suppress or override automatically-added headers, or to close the socket:
Respond differently for the same request
Register multiple expectations with the same matcher and differenttimes values. MockServer fires them in registration order:
Response templates
You can use Mustache, Velocity, or JavaScript templates to generate responses dynamically from the incoming request. See Response Templates.Forward
A forward action proxies the incoming request to another server.Forward exact request
"scheme": "HTTPS" to forward over TLS:
Override the forwarded request
Replace specific fields of the request before forwarding:Override both request and response
You can override the forwarded request and also replace the response body returned to the caller:Add delay to a forward
Callback
A callback action dynamically generates the response (or the forwarded request) by invoking code you provide. There are two variants: a class callback (server-side, Java only) and a method/closure callback (client-side, via WebSocket).Class callback
ImplementExpectationResponseCallback and register it by class name. The class must be on MockServer’s classpath and have a zero-argument constructor.
When using the Maven plugin with forked goals, add callback classes as plugin
dependencies so MockServer can load them from the classpath.Error
An error action simulates network-level failures by sending invalid bytes or dropping the TCP connection.Drop the connection
Send random bytes then drop
responseBytes is a base64-encoded byte array.