Class HttpForwardWithFallback


public class HttpForwardWithFallback extends Action<HttpForwardWithFallback>
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.
  • Constructor Details

    • HttpForwardWithFallback

      public HttpForwardWithFallback()
  • Method Details

    • forwardWithFallback

      public static HttpForwardWithFallback forwardWithFallback()
      Static builder to create a forward-with-fallback action.
    • getType

      public Action.Type getType()
      Specified by:
      getType in class Action<HttpForwardWithFallback>
    • getHttpForward

      public HttpForward getHttpForward()
    • withForward

      public HttpForwardWithFallback withForward(HttpForward httpForward)
      The forward definition specifying the upstream host, port and scheme.
      Parameters:
      httpForward - the forward target
    • getFallbackResponse

      public HttpResponse getFallbackResponse()
    • withFallback

      public HttpForwardWithFallback withFallback(HttpResponse fallbackResponse)
      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

      public List<Integer> getFallbackOnStatusCodes()
    • withFallbackOnStatusCodes

      public HttpForwardWithFallback withFallbackOnStatusCodes(Integer... statusCodes)
      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

      public HttpForwardWithFallback withFallbackOnStatusCodes(List<Integer> statusCodes)
      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

      public Boolean getFallbackOnTimeout()
    • withFallbackOnTimeout

      public HttpForwardWithFallback withFallbackOnTimeout(Boolean fallbackOnTimeout)
      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

      public boolean equals(Object o)
      Overrides:
      equals in class Action<HttpForwardWithFallback>
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Action<HttpForwardWithFallback>