Class OPALatencyMeasuringHTTPClient

  • All Implemented Interfaces:
    HTTPClient

    public class OPALatencyMeasuringHTTPClient
    extends OPAHTTPClient
    This HTTPClient implementation wraps OPAHTTPClient and has the same functionality, but also creates log messages indicating the latency for each request processed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
      This method implements compatibility with the com.styra.opa.sdk.utils.HTTPClient interface.
      void setLatencyMeasurementFormat​(java.lang.String newFormat)
      Modify the format in which the latency measurements are logged, the default is "path=''{1}'' latency={0,number,#}ms".
      void setLatencyMeasurementLogLevel​(java.util.logging.Level newLevel)
      Modify the log level at which latency measurements are recorded, the default is FINE.
      • Methods inherited from class java.lang.Object

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

      • OPALatencyMeasuringHTTPClient

        public OPALatencyMeasuringHTTPClient()
      • OPALatencyMeasuringHTTPClient

        public OPALatencyMeasuringHTTPClient​(java.util.Map<java.lang.String,​java.lang.String> headers)
        This constructor allows providing additional headers that should be passed to OPAHTTPClient.
        Parameters:
        logger -
        headers -
        headers -
    • Method Detail

      • setLatencyMeasurementFormat

        public void setLatencyMeasurementFormat​(java.lang.String newFormat)
        Modify the format in which the latency measurements are logged, the default is "path=''{1}'' latency={0,number,#}ms". The format string should be compatible with java.text.MessageFormat. The {0} argument will contain the measured request latency in ms, and the {1} argument will contain the URL path for the HTTP request.
        Parameters:
        newFormat -
      • setLatencyMeasurementLogLevel

        public void setLatencyMeasurementLogLevel​(java.util.logging.Level newLevel)
        Modify the log level at which latency measurements are recorded, the default is FINE.
        Parameters:
        newLevel -
      • send

        public java.net.http.HttpResponse<java.io.InputStream> send​(java.net.http.HttpRequest request)
                                                             throws java.io.IOException,
                                                                    java.lang.InterruptedException,
                                                                    java.net.URISyntaxException
        Description copied from class: OPAHTTPClient
        This method implements compatibility with the com.styra.opa.sdk.utils.HTTPClient interface.
        Specified by:
        send in interface HTTPClient
        Overrides:
        send in class OPAHTTPClient
        Parameters:
        request - HTTP request
        Returns:
        HTTP response
        Throws:
        java.io.IOException
        java.lang.InterruptedException
        java.net.URISyntaxException