Class ConditionalRequestMatcher
- All Implemented Interfaces:
HttpRequestMatcher,Matcher<RequestDefinition>
ConditionalRequestDefinition (if-then-else request matching).
Composes the existing HttpRequestMatcher machinery for each branch rather than
reimplementing matching: the if, then and else branches are each
compiled to their own HttpRequestMatcher via MatcherBuilder. Evaluation is:
if (ifMatcher.matches(request)) {
result = thenMatcher.matches(request)
} else {
result = elseMatcher != null ? elseMatcher.matches(request) : true
}
The branch matchers are built in the same plane (control vs data) as this matcher so that
the conditional behaves consistently whether it is created from an Expectation
(data plane) or a RequestDefinition filter (control plane).
Concurrency: like HttpRequestPropertiesMatcher, a single instance is
shared between the control plane (which rebuilds the compiled branch matchers in apply(org.mockserver.model.RequestDefinition)
— a single-writer path) and the data plane (which reads them in matches(org.mockserver.matchers.MatchDifference, org.mockserver.model.RequestDefinition) from many Netty
event-loop threads). All per-criterion compiled state lives in an immutable ConditionalRequestMatcher.Compiled
holder built fully inside apply() and published through a single volatile
reference (compiled); matches() snapshots that reference once on entry, so it
sees either the whole old set of branch matchers or the whole new one — never a torn mix.
- Author:
- jamesdbloom
-
Field Summary
Fields inherited from class org.mockserver.matchers.AbstractHttpRequestMatcher
BECAUSE, COLON_NEW_LINES, configuration, controlPlaneMatcher, DID_NOT_MATCH, didNotMatchExpectationBecause, didNotMatchExpectationWithoutBecause, didNotMatchRequestBecause, expectation, EXPECTATION, EXPECTATION_DID_MATCH, MATCHED, matcherDescription, mockServerLogger, REQUEST_DID_MATCH, REQUEST_DID_NOT_MATCH, REQUEST_MATCHER -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedConditionalRequestMatcher(Configuration configuration, MockServerLogger mockServerLogger) -
Method Summary
Modifier and TypeMethodDescriptionbooleanapply(RequestDefinition requestDefinition) booleanmatches(MatchDifference context, RequestDefinition requestDefinition) Methods inherited from class org.mockserver.matchers.AbstractHttpRequestMatcher
applyNotOperators, equals, getExpectation, getSource, hashCode, isActive, isBlank, isResponseInProgress, matches, setControlPlaneMatcher, setDescription, setResponseInProgress, tryScheduleRemoval, update, update, withSourceMethods inherited from class org.mockserver.matchers.NotMatcher
notMatcherMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode, toString
-
Constructor Details
-
ConditionalRequestMatcher
-
-
Method Details
-
getHttpRequests
-
apply
-
matches
- Specified by:
matchesin interfaceHttpRequestMatcher- Specified by:
matchesin interfaceMatcher<RequestDefinition>- Specified by:
matchesin classAbstractHttpRequestMatcher
-