Package com.styra.opa.utils
Class OPALatencyMeasuringHTTPClient
- java.lang.Object
-
- com.styra.opa.utils.OPAHTTPClient
-
- com.styra.opa.utils.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.
-
-
Constructor Summary
Constructors Constructor Description OPALatencyMeasuringHTTPClient()
OPALatencyMeasuringHTTPClient(java.util.Map<java.lang.String,java.lang.String> headers)
This constructor allows providing additional headers that should be passed to OPAHTTPClient.
-
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.
-
-
-
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 interfaceHTTPClient
- Overrides:
send
in classOPAHTTPClient
- Parameters:
request
- HTTP request- Returns:
- HTTP response
- Throws:
java.io.IOException
java.lang.InterruptedException
java.net.URISyntaxException
-
-