Package org.mockserver.mock.breakpoint
Class BreakpointCallbackDispatcher
java.lang.Object
org.mockserver.mock.breakpoint.BreakpointCallbackDispatcher
Dispatches breakpoint-held exchanges to a callback WebSocket client for
interactive resolution, reusing the same
WebSocketClientRegistry
dispatch primitives that object-callback (forwardObject /
responseObject) features already use.
Protocol
- REQUEST phase: the paused request is sent to the client
(with a
WebSocketCorrelationIdheader). The client replies with either:- An
HttpRequest— interpreted as MODIFY (forward the replacement) if different from the original, or CONTINUE if identical. - An
HttpResponse— interpreted as ABORT (write that response directly, do not forward).
- An
- RESPONSE phase: the paused request+response are sent to the
client. The client replies with an
HttpResponse— the decision is MODIFY (write the replacement) or CONTINUE (if the client echoes the original). In practice the continuation code treats any reply as the response to write.
Safety rails
- Timeout: auto-completes to CONTINUE after
Configuration.breakpointTimeoutMillis(). - Max-held cap: shared across all breakpoint dispatchers — if the cap
is already reached, returns
null(caller skips the breakpoint). - Disconnect: all in-flight dispatches for a disconnected client are
auto-completed to CONTINUE via
autoCompleteForClient(String).
This class is thread-safe. Correlation handlers are registered before the WS message is sent, and cleaned up on completion/timeout/disconnect.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionintautoCompleteForClient(String clientId) Auto-completes all in-flight WS breakpoint dispatches for the given client with CONTINUE.dispatchRequest(String clientId, String breakpointId, HttpRequest request, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a REQUEST-phase breakpoint over the callback WebSocket, tagging the message with the matched breakpoint id so the client can route it to the correct per-breakpoint handler.dispatchRequest(String clientId, HttpRequest request, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a REQUEST-phase breakpoint over the callback WebSocket.dispatchResponse(String clientId, String breakpointId, HttpRequest request, HttpResponse response, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a RESPONSE-phase breakpoint over the callback WebSocket, tagging the message with the matched breakpoint id.dispatchResponse(String clientId, HttpRequest request, HttpResponse response, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a RESPONSE-phase breakpoint over the callback WebSocket.static BreakpointCallbackDispatcherintReturns the number of in-flight WS breakpoint dispatches.voidreset()Resets all in-flight dispatches (auto-continue) — called on server reset.
-
Constructor Details
-
BreakpointCallbackDispatcher
public BreakpointCallbackDispatcher()
-
-
Method Details
-
getInstance
-
dispatchRequest
public CompletableFuture<BreakpointDecision> dispatchRequest(String clientId, HttpRequest request, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a REQUEST-phase breakpoint over the callback WebSocket.- Parameters:
clientId- the owning callback clientrequest- the captured request to holdwebSocketClientRegistry- the WS registry for sending messagesconfiguration- for timeout and max-heldlogger- for logging- Returns:
- a future that completes with the breakpoint decision, or
nullif the max-held cap is reached or the client is not connected
-
dispatchRequest
public CompletableFuture<BreakpointDecision> dispatchRequest(String clientId, String breakpointId, HttpRequest request, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a REQUEST-phase breakpoint over the callback WebSocket, tagging the message with the matched breakpoint id so the client can route it to the correct per-breakpoint handler.- Parameters:
clientId- the owning callback clientbreakpointId- the matched breakpoint's id (may be null for backward compat)request- the captured request to holdwebSocketClientRegistry- the WS registry for sending messagesconfiguration- for timeout and max-heldlogger- for logging- Returns:
- a future that completes with the breakpoint decision, or
nullif the max-held cap is reached or the client is not connected
-
dispatchResponse
public CompletableFuture<BreakpointDecision> dispatchResponse(String clientId, HttpRequest request, HttpResponse response, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a RESPONSE-phase breakpoint over the callback WebSocket.- Parameters:
clientId- the owning callback clientrequest- the original request (for context)response- the upstream response to holdwebSocketClientRegistry- the WS registryconfiguration- for timeout and max-heldlogger- for logging- Returns:
- a future that completes with the breakpoint decision, or
nullif the max-held cap is reached or the client is not connected
-
dispatchResponse
public CompletableFuture<BreakpointDecision> dispatchResponse(String clientId, String breakpointId, HttpRequest request, HttpResponse response, WebSocketClientRegistry webSocketClientRegistry, Configuration configuration, MockServerLogger logger) Dispatches a RESPONSE-phase breakpoint over the callback WebSocket, tagging the message with the matched breakpoint id.- Parameters:
clientId- the owning callback clientbreakpointId- the matched breakpoint's id (may be null)request- the original request (for context)response- the upstream response to holdwebSocketClientRegistry- the WS registryconfiguration- for timeout and max-heldlogger- for logging- Returns:
- a future that completes with the breakpoint decision, or
nullif the max-held cap is reached or the client is not connected
-
autoCompleteForClient
Auto-completes all in-flight WS breakpoint dispatches for the given client with CONTINUE. Called when the client's WebSocket connection closes.- Parameters:
clientId- the disconnecting client- Returns:
- the number of in-flight dispatches auto-completed
-
inFlightCount
public int inFlightCount()Returns the number of in-flight WS breakpoint dispatches. -
reset
public void reset()Resets all in-flight dispatches (auto-continue) — called on server reset.Takes a snapshot and clears the map BEFORE completing futures, so that asynchronous
whenCompletecallbacks cannot race with subsequent dispatches that re-populate the map.
-