Package org.mockserver.model
Class HttpForwardWithFallback
java.lang.Object
Forward a request to an upstream host; if upstream returns a configured
status code (default 500-599) or times out, return a fallback mock response.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.mockserver.model.Action
Action.Direction, Action.Type -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanstatic HttpForwardWithFallbackStatic builder to create a forward-with-fallback action.getType()inthashCode()withFallback(HttpResponse fallbackResponse) The mock response to return when the upstream forward fails or returns a status code that matches the fallback criteria.withFallbackOnStatusCodes(Integer... statusCodes) The HTTP status codes that should trigger the fallback response.withFallbackOnStatusCodes(List<Integer> statusCodes) The HTTP status codes that should trigger the fallback response.withFallbackOnTimeout(Boolean fallbackOnTimeout) Whether to return the fallback response when the upstream request times out or a connection error occurs.withForward(HttpForward httpForward) The forward definition specifying the upstream host, port and scheme.Methods inherited from class org.mockserver.model.Action
getDelay, getExpectationId, isPrimary, setExpectationId, withDelay, withDelay, withPrimaryMethods inherited from class org.mockserver.model.ObjectWithJsonToString
toStringMethods inherited from class org.mockserver.model.ObjectWithReflectiveEqualsHashCodeToString
fieldsExcludedFromEqualsAndHashCode
-
Constructor Details
-
HttpForwardWithFallback
public HttpForwardWithFallback()
-
-
Method Details
-
forwardWithFallback
Static builder to create a forward-with-fallback action. -
getType
- Specified by:
getTypein classAction<HttpForwardWithFallback>
-
getHttpForward
-
withForward
The forward definition specifying the upstream host, port and scheme.- Parameters:
httpForward- the forward target
-
getFallbackResponse
-
withFallback
The mock response to return when the upstream forward fails or returns a status code that matches the fallback criteria.- Parameters:
fallbackResponse- the fallback response
-
getFallbackOnStatusCodes
-
withFallbackOnStatusCodes
The HTTP status codes that should trigger the fallback response. Defaults to 500-599 when not set.- Parameters:
statusCodes- one or more HTTP status codes
-
withFallbackOnStatusCodes
The HTTP status codes that should trigger the fallback response. Defaults to 500-599 when not set.- Parameters:
statusCodes- list of HTTP status codes
-
getFallbackOnTimeout
-
withFallbackOnTimeout
Whether to return the fallback response when the upstream request times out or a connection error occurs. Defaults to true when not set.- Parameters:
fallbackOnTimeout- true to fall back on timeout/connection errors
-
equals
- Overrides:
equalsin classAction<HttpForwardWithFallback>
-
hashCode
public int hashCode()- Overrides:
hashCodein classAction<HttpForwardWithFallback>
-