com.appdynamics.eumagent.runtime
Interface HttpRequestTracker


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);
         }
     } 
 


Method Summary
 java.lang.String getError()
           
 java.lang.Exception getException()
           
 int getResponseCode()
          Gets the HTTP status code associated with this request.
 java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaderFields()
           
 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 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.
 

Method Detail

getException

java.lang.Exception getException()

withException

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.

Parameters:
e - An exception describing the error.

getError

java.lang.String getError()

withError

HttpRequestTracker withError(java.lang.String error)
Indicates that this request encountered an error.

Parameters:
error - A string describing the error.

getResponseCode

int getResponseCode()
Gets the HTTP status code associated with this request.

Returns:
the status code of the response.
Throws:
java.lang.NullPointerException - if withResponseCode(int) has never been called to set the value.

withResponseCode

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.

Parameters:
responseCode - The status code of the response.

getResponseHeaderFields

java.util.Map<java.lang.String,java.util.List<java.lang.String>> getResponseHeaderFields()

withResponseHeaderFields

HttpRequestTracker withResponseHeaderFields(java.util.Map<java.lang.String,java.util.List<java.lang.String>> responseHeaderFields)
Sets the response headers associated with this request.

Parameters:
responseHeaderFields - The headers of the response.

reportDone

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.