Class BreakpointCallbackDispatcher

java.lang.Object
org.mockserver.mock.breakpoint.BreakpointCallbackDispatcher

public class BreakpointCallbackDispatcher extends Object
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 WebSocketCorrelationId header). 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).
  • 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 Details

    • BreakpointCallbackDispatcher

      public BreakpointCallbackDispatcher()
  • Method Details

    • getInstance

      public static BreakpointCallbackDispatcher 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 client
      request - the captured request to hold
      webSocketClientRegistry - the WS registry for sending messages
      configuration - for timeout and max-held
      logger - for logging
      Returns:
      a future that completes with the breakpoint decision, or null if 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 client
      breakpointId - the matched breakpoint's id (may be null for backward compat)
      request - the captured request to hold
      webSocketClientRegistry - the WS registry for sending messages
      configuration - for timeout and max-held
      logger - for logging
      Returns:
      a future that completes with the breakpoint decision, or null if 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 client
      request - the original request (for context)
      response - the upstream response to hold
      webSocketClientRegistry - the WS registry
      configuration - for timeout and max-held
      logger - for logging
      Returns:
      a future that completes with the breakpoint decision, or null if 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 client
      breakpointId - the matched breakpoint's id (may be null)
      request - the original request (for context)
      response - the upstream response to hold
      webSocketClientRegistry - the WS registry
      configuration - for timeout and max-held
      logger - for logging
      Returns:
      a future that completes with the breakpoint decision, or null if the max-held cap is reached or the client is not connected
    • autoCompleteForClient

      public int autoCompleteForClient(String clientId)
      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 whenComplete callbacks cannot race with subsequent dispatches that re-populate the map.