Class HttpLogger


  • public class HttpLogger
    extends java.lang.Object
    This handles logging of HttpRequests and HttpResults.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected java.util.Set<java.lang.String> filter
      A list of paths from an URI.
      protected boolean logBody  
      protected int maxBinaryLength  
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpLogger​(int maxBinaryLength)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean active()  
      void addFilter​(java.net.URI uri)  
      protected boolean filterMatch​(java.net.URI uri)  
      int getMaxBinaryLength()  
      void logRequest​(java.net.http.HttpRequest httpRequest, java.lang.Object body)
      Log a request from the data inside HttpRequest.
      void logResponseBody​(java.net.http.HttpResponse<?> httpResponse, java.lang.Object body)
      Log a response from the data inside HttpResponse.
      void logResponseHeaders​(java.net.http.HttpResponse<?> httpResponse)
      Log a response from the data inside HttpResponse.
      protected java.lang.String processHeaderField​(java.lang.String key, java.util.List<java.lang.String> value)
      Hide critical data from header logging
      void removeFilter​(java.net.URI uri)  
      void setLogBody​(boolean logBody)
      Enable or disable logging of bodies.
      void setMaxBinaryLength​(int maxBinaryLength)
      Max length to log for binary data
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • logBody

        protected boolean logBody
      • maxBinaryLength

        protected int maxBinaryLength
      • filter

        protected final java.util.Set<java.lang.String> filter
        A list of paths from an URI. If such a filter matches, do not log body data.
    • Constructor Detail

      • HttpLogger

        public HttpLogger​(int maxBinaryLength)
    • Method Detail

      • addFilter

        public void addFilter​(java.net.URI uri)
      • removeFilter

        public void removeFilter​(java.net.URI uri)
      • filterMatch

        protected boolean filterMatch​(java.net.URI uri)
      • setLogBody

        public void setLogBody​(boolean logBody)
        Enable or disable logging of bodies. The values in the filter override this.
        Parameters:
        logBody - The flag to set
      • getMaxBinaryLength

        public int getMaxBinaryLength()
      • setMaxBinaryLength

        public void setMaxBinaryLength​(int maxBinaryLength)
        Max length to log for binary data
        Parameters:
        maxBinaryLength - Length in bytes
      • active

        public boolean active()
        Returns:
        Return true when the logger is logging
      • processHeaderField

        protected java.lang.String processHeaderField​(java.lang.String key,
                                                      java.util.List<java.lang.String> value)
        Hide critical data from header logging
        Parameters:
        key - Header name
        value - Value of header
        Returns:
        A secure string representation of the value of the header field.
      • logRequest

        public void logRequest​(java.net.http.HttpRequest httpRequest,
                               java.lang.Object body)
        Log a request from the data inside HttpRequest.
        Parameters:
        httpRequest - The httpRequest to log.
        body - The body of the httpRequest.
      • logResponseHeaders

        public void logResponseHeaders​(java.net.http.HttpResponse<?> httpResponse)
        Log a response from the data inside HttpResponse.
        Parameters:
        httpResponse - The httpResponse to log.
      • logResponseBody

        public void logResponseBody​(java.net.http.HttpResponse<?> httpResponse,
                                    java.lang.Object body)
        Log a response from the data inside HttpResponse.
        Parameters:
        httpResponse - The httpResponse to log.
        body - The body of the httpResponse.