Package org.mockserver.mock
Class HttpState
java.lang.Object
org.mockserver.mock.HttpState
- Author:
- jamesdbloom
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionHttpState(Configuration configuration, MockServerLogger mockServerLogger, Scheduler scheduler) -
Method Summary
Modifier and TypeMethodDescriptionadd(Expectation... expectations) add(OpenAPIExpectation openAPIExpectation) allMatchingExpectation(HttpRequest request) voidclear(HttpRequest request) booleancontrolPlaneRequestAuthenticated(HttpRequest request, ResponseWriter responseWriter) The single control-plane gate: authenticates the request and, whencontrolPlaneAuthorizationEnabledis on, authorizes it (coarse read/mutate role check), auditing the outcome.debugMismatch(HttpRequest request) explainUnmatched(HttpRequest request) Retrieves recent requests that matched no expectation and, for each, computes ranked closest-expectation diagnostics with remediation hints.findClosestMatchDiff(HttpRequest request) firstMatchingEarlyExpectation(HttpRequest headersOnly) Returns the first expectation whose matcher has respondBeforeBody=true, has no body matcher, and matches the supplied headers-only request.static IntegergetPort()Returns the pluggable state backend (G10 phase 2a).booleanhandle(HttpRequest request, ResponseWriter responseWriter, boolean warDeployment) booleanvoidSide-effect-free probe: returns the first matching expectation WITHOUT consuming the match (no Times decrement, no scenario transition, no responseInProgress, no metrics).voidpostProcess(Expectation expectation) voidreset()retrieve(HttpRequest request) voidsetControlPlaneAuthenticationHandler(AuthenticationHandler controlPlaneAuthenticationHandler) voidsetLlmCompletionService(LlmCompletionService llmCompletionService, LlmBackend llmBackend) Install the LLM completion service and default backend for runtime features that call out to an LLM (e.g.static voidstatic voidstatic voidstatic voidsetPort(HttpRequest request) voidsetReplayHandler(Function<HttpRequest, CompletableFuture<HttpResponse>> replayHandler) Install the replay handler that re-issues anHttpRequestto its target and returns the upstream response.voidstop()verify(Verification verification) voidverify(Verification verification, Consumer<String> resultConsumer) verify(VerificationSequence verification) voidverify(VerificationSequence verificationSequence, Consumer<String> resultConsumer)
-
Field Details
-
LOG_SEPARATOR
-
PATH_PREFIX
- See Also:
-
-
Constructor Details
-
HttpState
public HttpState(Configuration configuration, MockServerLogger mockServerLogger, Scheduler scheduler)
-
-
Method Details
-
setPort
-
setPort
-
setPort
-
setPort
-
getPort
-
isInitializationComplete
public boolean isInitializationComplete()- Returns:
- true once the HttpState constructor (including synchronous expectation initializers and OpenAPI seeding) has completed. Backs the readiness probe (/mockserver/ready), which returns 503 until this is true and 200 thereafter — distinct from the liveness/status endpoints, which answer 200 the instant the port binds.
-
getGrpcDescriptorStore
-
getFileStore
-
getCrudDispatcher
-
getControlPlaneAuthenticationHandler
-
setControlPlaneAuthenticationHandler
public void setControlPlaneAuthenticationHandler(AuthenticationHandler controlPlaneAuthenticationHandler) -
setReplayHandler
Install the replay handler that re-issues anHttpRequestto its target and returns the upstream response. Called by the runtime (e.g.HttpRequestHandlerin the Netty module) after construction, wiring the existingNettyHttpClientso thatPUT /mockserver/replaycan delegate without core depending on the client directly. -
getConfiguration
-
setLlmCompletionService
public void setLlmCompletionService(LlmCompletionService llmCompletionService, LlmBackend llmBackend) Install the LLM completion service and default backend for runtime features that call out to an LLM (e.g. AI stub generation). Called by LifeCycle when a backend is configured; null-safe — when not called the stub generation endpoint falls back to template-based stubs. -
getMockServerLogger
-
clear
-
reset
public void reset() -
add
-
add
-
firstMatchingExpectation
-
peekFirstMatchingExpectation
Side-effect-free probe: returns the first matching expectation WITHOUT consuming the match (no Times decrement, no scenario transition, no responseInProgress, no metrics). Note: the underlying matcher evaluation may still emit INFO-level EXPECTATION_MATCHED / EXPECTATION_NOT_MATCHED diagnostic logs; this method avoids the consuming side-effects only. Used by the gRPC bidi router to inspect the action type before committing to a handler — the real consuming match happens separately on the committed path. -
firstMatchingEarlyExpectation
Returns the first expectation whose matcher has respondBeforeBody=true, has no body matcher, and matches the supplied headers-only request. Used by the early-response path that runs before the request body is aggregated. -
allMatchingExpectation
-
postProcess
-
findClosestMatchDiff
-
debugMismatch
-
explainUnmatched
Retrieves recent requests that matched no expectation and, for each, computes ranked closest-expectation diagnostics with remediation hints.- Parameters:
request- the control-plane request (body may contain{"limit":N})- Returns:
- a JSON response containing an array of unmatched requests with diagnostics
-
log
-
retrieve
-
verify
-
verify
-
verify
-
verify
-
handle
-
controlPlaneRequestAuthenticated
The single control-plane gate: authenticates the request and, whencontrolPlaneAuthorizationEnabledis on, authorizes it (coarse read/mutate role check), auditing the outcome. Returns true to proceed; on failure writes the 401/403 response itself and returns false.Public so control-plane choke points serviced directly in the Netty layer (e.g.
PUT /mockserver/configuration, which mutates live configuration outsidehandle(org.mockserver.model.HttpRequest, org.mockserver.responsewriter.ResponseWriter, boolean)) route through the SAME authn + authz + audit decision rather than calling the legacy boolean authentication SPI directly — which would authenticate but skip Wave-2 authorization, letting a read-only principal mutate. Operations dispatched throughhandle(org.mockserver.model.HttpRequest, org.mockserver.responsewriter.ResponseWriter, boolean)already call this internally. -
getWebSocketClientRegistry
-
getRequestMatchers
-
getMockServerLog
-
getScheduler
-
getUniqueLoopPreventionHeaderName
-
getUniqueLoopPreventionHeaderValue
-
stop
public void stop() -
getStateBackend
Returns the pluggable state backend (G10 phase 2a). The default implementation is in-memory with zero behaviour change.
-