01: /**
02: *
03: */package clime.messadmin.model;
04:
05: import javax.servlet.ServletContext;
06: import javax.servlet.http.HttpServletRequest;
07:
08: import clime.messadmin.filter.MessAdminRequestWrapper;
09: import clime.messadmin.filter.MessAdminResponseWrapper;
10: import clime.messadmin.filter.MessAdminThreadLocal;
11:
12: /**
13: * @author Cédrik LIME
14: */
15: public class Request {
16:
17: /**
18: *
19: */
20: public Request(String url) {
21: super ();
22: }
23:
24: private void hit(final RequestInfo requestInfo, int duration) {
25: //++requestInfo.hits;
26: requestInfo.usedTime.registerValue(duration);
27: }
28:
29: private void addRequestLength(final RequestInfo requestInfo,
30: final MessAdminRequestWrapper request) {
31: if (-1 != request.getContentLength()) {
32: requestInfo.requestLength.registerValue(request
33: .getContentLength());
34: } else if (-1 != request.getRequestLength()) {
35: requestInfo.requestLength.registerValue(request
36: .getRequestLength());
37: } else {
38: requestInfo.requestLength.hit();
39: }
40: }
41:
42: private void addResponseLength(final RequestInfo requestInfo,
43: final MessAdminResponseWrapper response) {
44: if (-1 != response.getContentLength()) {
45: requestInfo.responseLength.registerValue(response
46: .getContentLength());
47: } else if (-1 != response.getResponseLength()) {
48: requestInfo.responseLength.registerValue(response
49: .getResponseLength());
50: } else {
51: requestInfo.responseLength.hit();
52: }
53: }
54:
55: /*****************************************/
56: /** Request/Response Listener methods **/
57: /*****************************************/
58:
59: /**
60: * @see IRequestListener#requestInitialized(HttpServletRequest, ServletContext)
61: */
62: public void requestInitialized(final RequestInfo requestInfo,
63: HttpServletRequest request, ServletContext servletContext) {
64: requestInfo.lastRequestDate = MessAdminThreadLocal
65: .getStartTime().getTime();
66: }
67:
68: /**
69: * @see IRequestListener#requestDestroyed(MessAdminRequestWrapper, MessAdminResponseWrapper, ServletContext)
70: */
71: public void requestDestroyed(final RequestInfo requestInfo,
72: MessAdminRequestWrapper request,
73: MessAdminResponseWrapper response,
74: ServletContext servletContext) {
75: requestInfo.lastResponseDate = MessAdminThreadLocal
76: .getStopTime().getTime();
77: requestInfo.lastResponseStatus = response.getStatus();
78: ++requestInfo.responseStatus[(response.getStatus() / 100)];
79: //requestInfo.responseStatus[(response.getStatus()/100)].hit(lastResponseDate);
80: addRequestLength(requestInfo, request);
81: addResponseLength(requestInfo, response);
82: int lastUsedTime = MessAdminThreadLocal.getUsedTime();
83: hit(requestInfo, lastUsedTime);
84: }
85:
86: /**
87: * @see IRequestListener#requestException(Exception, MessAdminRequestWrapper, MessAdminResponseWrapper, ServletContext)
88: */
89: public void requestException(final RequestInfo requestInfo,
90: Exception e, MessAdminRequestWrapper request,
91: MessAdminResponseWrapper response,
92: ServletContext servletContext) {
93: requestDestroyed(requestInfo, request, response, servletContext);
94: ++requestInfo.nErrors;
95: requestInfo.lastError = new ErrorData(request, e);
96: }
97: }
|