public interface HttpRequestTracker
If the SDK does not automatically discover your HTTP requests, use this class to explicitly report them.
Note that most users will not need to use this class; check the documentation for the list of HTTP API that are automatically discovered.
Suppose that you have a method like this for making HTTP requests:
public byte[] sendRequest(URL url) throws HttpException { try { // implementation omitted return responseBody; } catch (UnderlyingException e) { throw new HttpException(e); } } Here’s how you would augment this method to report requests to the SDK:
public byte[] sendRequest(URL url) throws HttpException { HttpRequestTracker tracker = Instrumentation.beginHttpRequest(url); try { // implementation omitted tracker.withResponseCode(theResponseCode) .withResponseHeaderFields(theResponseHeaderFields) .reportDone(); return responseBody; } catch (UnderlyingException e) { tracker.withException(e) .reportDone(); throw new HttpException(e); } } | Modifier and Type | Method and Description |
|---|---|
java.lang.String |
getError()
Gets the error message associated with this request.
|
java.lang.Exception |
getException()
Gets the exception associated with this request.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getRequestHeaderFields()
Returns the request header fields associated with this request.
|
int |
getResponseCode()
Gets the HTTP status code associated with this request.
|
java.util.Map<java.lang.String,java.util.List<java.lang.String>> |
getResponseHeaderFields()
Returns the response header fields associated with this request.
|
void |
reportDone()
Stops tracking an HTTP request.
|
HttpRequestTracker |
withError(java.lang.String error)
Indicates that this request encountered an error.
|
HttpRequestTracker |
withException(java.lang.Exception e)
Indicates that this request encountered an error.
|
HttpRequestTracker |
withRequestHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestHeaderFields)
Sets the request headers associated with this request.
|
HttpRequestTracker |
withResponseCode(int responseCode)
Sets the HTTP response code associated with this request.
|
HttpRequestTracker |
withResponseHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields)
Sets the response headers associated with this request.
|
HttpRequestTracker |
withStatusLine(java.lang.String statusLine)
Sets the HTTP status line associated with this request.
|
java.lang.Exception getException()
Gets the exception associated with this request.
HttpRequestTracker withException(java.lang.Exception e)
Indicates that this request encountered an error.
This method is preferred over withError(String). If both an error and an exception are specified, the error is ignored.
e - An exception describing the error.java.lang.String getError()
Gets the error message associated with this request.
HttpRequestTracker withError(java.lang.String error)
Indicates that this request encountered an error.
error - A string describing the error.int getResponseCode()
Gets the HTTP status code associated with this request.
java.lang.NullPointerException - if withResponseCode(int) has never been called to set the value.HttpRequestTracker withResponseCode(int responseCode)
Sets the HTTP response code associated with this request.
If a response was received, this method must be called, or the request will not be reported.
responseCode - The status code of the response.HttpRequestTracker withStatusLine(java.lang.String statusLine)
Sets the HTTP status line associated with this request.
This is optional
statusLine - java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaderFields()
Returns the response header fields associated with this request.
HttpRequestTracker withResponseHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields)
Sets the response headers associated with this request.
responseHeaderFields - The headers of the response.java.util.Map<java.lang.String,java.util.List<java.lang.String>> getRequestHeaderFields()
Returns the request header fields associated with this request.
HttpRequestTracker withRequestHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> requestHeaderFields)
Sets the request headers associated with this request.
requestHeaderFields - The headers of the request.void reportDone()
Stops tracking an HTTP request.
Immediately after receiving a response or an error, set the appropriate fields and call this method to report the outcome of the HTTP request. You should not continue to use this object after calling this method – if you need to track another request, obtain a new instance.