01: package com.jamonapi.http;
02:
03: /** Handler that can be used to track request access in jetty. See www.jamonapi.com for more info on how to
04: * add this handler to the jetty.xml file. This is a wrapper class for the true monitoring class of HttpMonFactory.
05: *
06: */
07: import java.io.IOException;
08:
09: import javax.servlet.ServletException;
10: import javax.servlet.http.HttpServletRequest;
11: import javax.servlet.http.HttpServletResponse;
12:
13: import org.mortbay.jetty.HttpConnection;
14: import org.mortbay.jetty.Request;
15: import org.mortbay.jetty.Response;
16: import org.mortbay.jetty.handler.HandlerWrapper;
17:
18: public class JAMonJettyHandler extends HandlerWrapper implements
19: HttpMonManage {
20:
21: private static final String PREFIX = "com.jamonapi.http.JAMonJettyHandler";
22: private static final String DEFAULT_SUMMARY = "default, response.getContentCount().bytes, response.getStatus().value.ms";
23: private HttpMonFactory httpMonFactory = new JettyHttpMonFactory(
24: PREFIX);
25: private String jamonSummaryLabels = "default";
26:
27: public JAMonJettyHandler() {
28: setSummaryLabels(jamonSummaryLabels);
29: }
30:
31: /** Monitor the request and call any other requests in the decorator chain */
32: public void handle(String target, HttpServletRequest request,
33: HttpServletResponse response, int dispatch)
34: throws IOException, ServletException {
35: final Request baseRequest = (request instanceof Request) ? ((Request) request)
36: : HttpConnection.getCurrentConnection().getRequest();
37: final Response baseResponse = (response instanceof Response) ? ((Response) response)
38: : HttpConnection.getCurrentConnection().getResponse();
39:
40: HttpMon httpMon = null;
41: try {
42: httpMon = httpMonFactory.start(baseRequest, baseResponse);
43:
44: super .handle(target, request, response, dispatch);
45: } catch (Throwable e) {
46: httpMon.throwException(e);
47: } finally {
48: httpMon.stop();
49: }
50:
51: }
52:
53: public void setSummaryLabels(String jamonSummaryLabels) {
54: httpMonFactory.setSummaryLabels(jamonSummaryLabels,
55: DEFAULT_SUMMARY);
56: }
57:
58: public String getSummaryLabels() {
59: return httpMonFactory.getSummaryLabels();
60: }
61:
62: public void addSummaryLabel(String jamonSummaryLabel) {
63: httpMonFactory.addSummaryLabel(jamonSummaryLabel);
64:
65: }
66:
67: public boolean getIgnoreHttpParams() {
68: return httpMonFactory.getIgnoreHttpParams();
69: }
70:
71: public void setIgnoreHttpParams(boolean ignoreHttpParams) {
72: httpMonFactory.setIgnoreHttpParams(ignoreHttpParams);
73: }
74:
75: public void setEnabled(boolean enable) {
76: httpMonFactory.setEnabled(enable);
77:
78: }
79:
80: public int getSize() {
81: return httpMonFactory.getSize();
82: }
83:
84: public boolean getEnabled() {
85: return httpMonFactory.getEnabled();
86: }
87:
88: public void setSize(int size) {
89: httpMonFactory.setSize(size);
90:
91: }
92:
93: }
|