Class BreakpointMatcher

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

public class BreakpointMatcher extends Object
A registered breakpoint: a request matcher + set of phases at which matching forwarded exchanges should be paused for interactive inspection/modification.

The prebuilt HttpRequestMatcher is created once at registration time (via MatcherBuilder.transformsToMatcher(RequestDefinition)) and reused for every findMatch call — no allocation on the hot path.

The clientId identifies the owning callback WebSocket client. It is required -- matched exchanges are always dispatched over the callback WebSocket to the owning client for interactive resolution.

Conditional (Nth-hit / skip-count) breakpoints: an optional skipCount delays the first pause. The matcher still matches normally on every hit, but only pauses once it has been hit more than skipCount times. With skipCount = 2 the breakpoint does NOT pause on hits 1 and 2 and DOES pause from hit 3 onward. When skipCount is null (the default) the breakpoint pauses on every hit (legacy behaviour). The per-matcher hit counter (hitCount) is incremented atomically by shouldPause(), so the decision is thread-safe under concurrent matching.

Response-content conditional breakpoints: optional response conditions (responseStatusCodeMin/responseStatusCodeMax for an inclusive status-code range, and responseBodyContains for a regex searched within the response body) gate whether a RESPONSE-phase breakpoint pauses. They are only evaluated at the response phase (the response is not yet known at the request phase). When set, the breakpoint pauses only when the response satisfies all configured conditions (in addition to the request matcher and any skip-count). When all are null (the default) the breakpoint pauses regardless of response content (legacy behaviour). The responseBodyContains pattern is compiled once at registration (find semantics — pauses if the body contains a match).

Value-equality is on id only (UUID assigned at registration).

  • Constructor Details

  • Method Details

    • getId

      public String getId()
    • getRequestMatcher

      public RequestDefinition getRequestMatcher()
    • getPhases

      public Set<BreakpointPhase> getPhases()
    • getPrebuiltMatcher

      public HttpRequestMatcher getPrebuiltMatcher()
    • getClientId

      public String getClientId()
      The callback WebSocket client id that owns this breakpoint (required).
    • getSkipCount

      public Integer getSkipCount()
      The optional skip-count: the number of matching hits to skip before the breakpoint starts pausing. null (the default) means pause on every hit. A value of n means do not pause on the first n hits and pause from hit n + 1 onward.
    • getResponseStatusCodeMin

      public Integer getResponseStatusCodeMin()
      Lower bound (inclusive) of the optional response status-code condition, or null if no lower bound is configured.
    • getResponseStatusCodeMax

      public Integer getResponseStatusCodeMax()
      Upper bound (inclusive) of the optional response status-code condition, or null if no upper bound is configured.
    • getResponseBodyContains

      public String getResponseBodyContains()
      The optional regular expression searched (find semantics) within the response body, or null if no body condition is configured.
    • hasResponseCondition

      public boolean hasResponseCondition()
      Whether this breakpoint has any response-content condition (status-code range or body pattern) that must be satisfied for it to pause at the RESPONSE phase.
    • responseConditionMatches

      public boolean responseConditionMatches(HttpResponse response)
      Evaluates the optional response-content conditions against the given response.

      Returns true when the response satisfies all configured conditions (status-code within the inclusive [min, max] range, and the body matches the responseBodyContains regex via find semantics). When no conditions are configured this returns true (the legacy behaviour: pause regardless of response content). A null response or null status code fails any configured status-code condition; a null/empty body fails any configured body condition.

      Parameters:
      response - the response about to be written to the downstream client
      Returns:
      true if the response satisfies all configured conditions
    • getHitCount

      public long getHitCount()
      The number of times this breakpoint has matched (for diagnostics / tests).
    • shouldPause

      public boolean shouldPause()
      Records a matching hit and decides whether this hit should actually pause.

      Called exactly once per matching exchange/phase (from BreakpointMatcherRegistry.findMatch(org.mockserver.model.RequestDefinition, org.mockserver.mock.breakpoint.BreakpointPhase)). Increments the per-matcher counter atomically and returns true if the breakpoint should pause for this hit, false if the hit falls within the configured skip-count window. When skipCount is null this always returns true (pause every time).

      Returns:
      true to pause this hit, false to skip it
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object