Class HttpResponseModifier


public class HttpResponseModifier extends ObjectWithJsonToString
  • Constructor Details

    • HttpResponseModifier

      public HttpResponseModifier()
  • Method Details

    • responseModifier

      public static HttpResponseModifier responseModifier()
    • getHeaders

      public HeadersModifier getHeaders()
    • withHeaders

      public HttpResponseModifier withHeaders(HeadersModifier headers)
    • withHeaders

      public HttpResponseModifier withHeaders(List<Header> add, List<Header> replace, List<String> remove)
    • getCookies

      public CookiesModifier getCookies()
    • withCookies

      public HttpResponseModifier withCookies(CookiesModifier cookies)
    • withCookies

      public HttpResponseModifier withCookies(List<Cookie> add, List<Cookie> replace, List<String> remove)
    • getCondition

      public HttpResponseModifierCondition getCondition()
    • withCondition

      public HttpResponseModifier withCondition(HttpResponseModifierCondition condition)
      Restrict this modifier so it only applies when the supplied condition holds against the in-flight response (and, where available, the original request). When null the modifier always applies — the historical behaviour.
    • getModifiers

      public List<HttpResponseModifier> getModifiers()
    • withModifiers

      public HttpResponseModifier withModifiers(List<HttpResponseModifier> modifiers)
      Configure an ordered chain of modifiers. Each is applied in order to the same response, so a later modifier observes the output of the earlier ones. When a chain is present the headers/cookies of this (wrapping) modifier are ignored — the chain is the unit of work; the wrapping modifier's condition still gates the whole chain.
    • getJsonPatch

      public com.fasterxml.jackson.databind.JsonNode getJsonPatch()
    • withJsonPatch

      public HttpResponseModifier withJsonPatch(com.fasterxml.jackson.databind.JsonNode jsonPatch)
      Apply an RFC 6902 JSON Patch document (an array of add/remove/replace/ move/copy/test operations) to the forwarded response body when that body is valid JSON. When null the body is left untouched. If the body is not valid JSON, or the patch cannot be applied (e.g. a test operation fails), the body is left unchanged.
    • withJsonPatch

      public HttpResponseModifier withJsonPatch(String jsonPatch)
      Convenience overload accepting the RFC 6902 JSON Patch document as a JSON string.
      Throws:
      IllegalArgumentException - if the string is not valid JSON
    • getJsonMergePatch

      public com.fasterxml.jackson.databind.JsonNode getJsonMergePatch()
    • withJsonMergePatch

      public HttpResponseModifier withJsonMergePatch(com.fasterxml.jackson.databind.JsonNode jsonMergePatch)
      Apply an RFC 7386 JSON Merge Patch document to the forwarded response body when that body is valid JSON. Members present in the patch overwrite (or, when null, delete) the corresponding members of the body; everything else is left as-is. When null the body is left untouched. If the body is not valid JSON, or the merge cannot be applied, the body is left unchanged.
    • withJsonMergePatch

      public HttpResponseModifier withJsonMergePatch(String jsonMergePatch)
      Convenience overload accepting the RFC 7386 JSON Merge Patch document as a JSON string.
      Throws:
      IllegalArgumentException - if the string is not valid JSON
    • applyTo

      public void applyTo(HttpResponse response, HttpRequest request)
      Apply this modifier to response, honouring any condition and chain.

      Evaluation order:

      1. if a condition is configured and does not match, do nothing;
      2. if a chain is configured, apply each child in order (each sees the prior child's output);
      3. otherwise apply this modifier's own header/cookie edits and then its body patch.
      Parameters:
      response - the in-flight response to mutate in place
      request - the original request (may be null when not available)
    • equals

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

      public int hashCode()
      Overrides:
      hashCode in class ObjectWithReflectiveEqualsHashCodeToString