com.jamonapi.http.HttpMonRequest Maven / Gradle / Ivy
package com.jamonapi.http;
import com.jamonapi.MonKeyImp;
import com.jamonapi.Monitor;
import com.jamonapi.MonitorFactory;
import com.jamonapi.utils.Misc;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Iterator;
/**
* Generic HttpMon object that monitors http request, and http response objects.
* Includes any dynamic data needed by HttpMonItem such as url, request and response. This allows HttpMonItems to not be
* created with each request. This object is constructed via HttpMonFactory and represents
* all monitors for one page request.
*/
final class HttpMonRequest implements HttpMon {
private static final String EXCEPTION_ATTR="javax.servlet.error.exception";// seems to be standarad exception property for tocmat, and jetty
private final Object request;//HttpServletRequest or child of it
private final Object response;//HttpServletResponse or a child of it
private final HttpMonFactory httpMonFactory;
private Monitor[] timeMons;// an array that is created for each time monitor
private int timeMonIndex=0;// index used in start/stop methods to keep track of the current time monitor
private String keyReadyURI;// uri that has params removed such as jsessionid. This can be used as a jamon key.
private String detailLabel;
private String stackTrace;
private Throwable requestException;
HttpMonRequest(Object request, Object response, HttpMonFactory httpMonFactory) {
this.request=request;
this.response=response;
this.httpMonFactory=httpMonFactory;
this.timeMons=(httpMonFactory.getNumTimeMons()>0) ? new Monitor[httpMonFactory.getNumTimeMons()] : null;
detailLabel=getRequestURI();
}
/**
* Method called to start monitoring http requests, and responses. Loop through all
* HttpMonItems starting each of them. Note state is passed into the stateless HttpMonItem
* instances via 'this' instance.
*/
public HttpMon start() {
timeMonIndex=0;// Index that is incremented for time monitors only
Iterator iter=iter();
while (iter.hasNext()) {
HttpMonItem monItem=(HttpMonItem) iter.next();
monItem.start(this);
}
return this;
}
/** Method called to stop any active http monitoring requests, and responses */
public void stop() {
timeMonIndex=0;
setException();
Iterator iter=iter();
while (iter.hasNext()) {
HttpMonItem monItem=(HttpMonItem) iter.next();
monItem.stop(this);
}
if (stackTrace!=null)
changeDetails();// detailLabel now has stack trace in it.
}
// change details was called when stackTrace had data in it. The result is to
// allow the gui to show the stack tracke for all monitors buffer listeners.
private void changeDetails() {
int len=(timeMons==null) ? 0 : timeMons.length;
for (int i=0;i