Class Exchange


  • public class Exchange
    extends Object
    Models a request log entry.
    Author:
    https://github.com/lbovet [Laurent Bovet]
    • Constructor Summary

      Constructors 
      Constructor Description
      Exchange​(String urlPrefix, org.json.JSONObject json)  
      Exchange​(org.springframework.http.RequestEntity<org.json.JSONObject> request, org.springframework.http.ResponseEntity<org.json.JSONObject> response)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static void assertSameExchange​(Exchange expected, Exchange actual)
      Convenience method for unit tests.
      static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>>
      com.google.common.base.Predicate<T>
      body​(com.jayway.jsonpath.Predicate bodyPredicate)
      Predicate that applies to a request or response body.
      boolean equals​(Object o)  
      String getId()
      Convenience method to retrieve the x-request-id header.
      org.springframework.http.RequestEntity<org.json.JSONObject> getRequest()  
      org.springframework.http.ResponseEntity<org.json.JSONObject> getResponse()  
      String getTimestamp()
      Convenience method to retrieve the x-client-timestamp header.
      int hashCode()  
      static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>,​U extends CharSequence>
      com.google.common.base.Predicate<T>
      header​(String key, com.google.common.base.Predicate<U> stringPredicate)
      Predicate that applies to a given request or response header.
      static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>>
      com.google.common.base.Predicate<T>
      headers​(com.google.common.base.Predicate<org.springframework.http.HttpHeaders> headersPredicate)
      Predicate that applies to request or response headers.
      static com.google.common.base.Predicate<org.springframework.http.RequestEntity<org.json.JSONObject>> method​(com.google.common.base.Predicate<org.springframework.http.HttpMethod> methodPredicate)
      Predicate that applies to the request HTTP method.
      static com.google.common.base.Predicate<Exchange> request​(com.google.common.base.Predicate<? super org.springframework.http.RequestEntity<org.json.JSONObject>> requestPredicate)
      Predicate that applies to the request part.
      static com.google.common.base.Predicate<Exchange> response​(com.google.common.base.Predicate<? super org.springframework.http.ResponseEntity<org.json.JSONObject>> responsePredicate)
      Predicate that applies to the response part.
      void setRequest​(org.springframework.http.RequestEntity<org.json.JSONObject> request)  
      void setResponse​(org.springframework.http.ResponseEntity<org.json.JSONObject> response)  
      static com.google.common.base.Predicate<org.springframework.http.ResponseEntity<org.json.JSONObject>> status​(com.google.common.base.Predicate<org.springframework.http.HttpStatus> statusPredicate)
      Predicate that applies to the response HTTP status code.
      String toString()  
      static com.google.common.base.Predicate<org.springframework.http.RequestEntity<org.json.JSONObject>> url​(com.google.common.base.Predicate<? super CharSequence> stringPredicate)
      Predicate that applies to the request URL.
      static com.google.common.base.Predicate<Exchange> withId​(String... requestIds)
      Predicate matching exchanges having one of the specified x-request-id header.
    • Constructor Detail

      • Exchange

        public Exchange​(org.springframework.http.RequestEntity<org.json.JSONObject> request,
                        org.springframework.http.ResponseEntity<org.json.JSONObject> response)
      • Exchange

        public Exchange​(String urlPrefix,
                        org.json.JSONObject json)
        Parameters:
        urlPrefix - A prefix added to the request URI.
        json - Source exchange in JSON form.
    • Method Detail

      • getRequest

        public org.springframework.http.RequestEntity<org.json.JSONObject> getRequest()
      • setRequest

        public void setRequest​(org.springframework.http.RequestEntity<org.json.JSONObject> request)
      • getResponse

        public org.springframework.http.ResponseEntity<org.json.JSONObject> getResponse()
      • setResponse

        public void setResponse​(org.springframework.http.ResponseEntity<org.json.JSONObject> response)
      • getTimestamp

        public String getTimestamp()
        Convenience method to retrieve the x-client-timestamp header.
        Returns:
        the ISO timestamp string
      • getId

        public String getId()
        Convenience method to retrieve the x-request-id header.
        Returns:
        the ID
      • request

        public static com.google.common.base.Predicate<Exchange> request​(com.google.common.base.Predicate<? super org.springframework.http.RequestEntity<org.json.JSONObject>> requestPredicate)
        Predicate that applies to the request part.
        Parameters:
        requestPredicate - requestPredicate
        Returns:
        Predicate
      • response

        public static com.google.common.base.Predicate<Exchange> response​(com.google.common.base.Predicate<? super org.springframework.http.ResponseEntity<org.json.JSONObject>> responsePredicate)
        Predicate that applies to the response part.
        Parameters:
        responsePredicate - responsePredicate
        Returns:
        Predicate
      • withId

        public static com.google.common.base.Predicate<Exchange> withId​(String... requestIds)
        Predicate matching exchanges having one of the specified x-request-id header.
        Parameters:
        requestIds - requestIds
        Returns:
        Predicate
      • url

        public static com.google.common.base.Predicate<org.springframework.http.RequestEntity<org.json.JSONObject>> url​(com.google.common.base.Predicate<? super CharSequence> stringPredicate)
        Predicate that applies to the request URL.
        Parameters:
        stringPredicate - stringPredicate
        Returns:
        Predicate
      • method

        public static com.google.common.base.Predicate<org.springframework.http.RequestEntity<org.json.JSONObject>> method​(com.google.common.base.Predicate<org.springframework.http.HttpMethod> methodPredicate)
        Predicate that applies to the request HTTP method.
        Parameters:
        methodPredicate - methodPredicate
        Returns:
        Predicate
      • status

        public static com.google.common.base.Predicate<org.springframework.http.ResponseEntity<org.json.JSONObject>> status​(com.google.common.base.Predicate<org.springframework.http.HttpStatus> statusPredicate)
        Predicate that applies to the response HTTP status code.
        Parameters:
        statusPredicate - statusPredicate
        Returns:
        Predicate
      • body

        public static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>> com.google.common.base.Predicate<T> body​(com.jayway.jsonpath.Predicate bodyPredicate)
        Predicate that applies to a request or response body.
        Parameters:
        bodyPredicate - bodyPredicate
        Returns:
        Predicate
      • headers

        public static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>> com.google.common.base.Predicate<T> headers​(com.google.common.base.Predicate<org.springframework.http.HttpHeaders> headersPredicate)
        Predicate that applies to request or response headers.
        Parameters:
        headersPredicate - headersPredicate
        Returns:
        Predicate
      • header

        public static <T extends org.springframework.http.HttpEntity<org.json.JSONObject>,​U extends CharSequence> com.google.common.base.Predicate<T> header​(String key,
                                                                                                                                                                   com.google.common.base.Predicate<U> stringPredicate)
        Predicate that applies to a given request or response header.
        Parameters:
        key - key
        stringPredicate - stringPredicate
        Returns:
        Predicate
      • assertSameExchange

        public static void assertSameExchange​(Exchange expected,
                                              Exchange actual)
        Convenience method for unit tests.
        Parameters:
        expected - expected
        actual - actual
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object