001: package com.jamontomcat;
002:
003: /** Note this is simply a copy of com.jamonapi.http.JAMonTomcatValve. Tomcat 5.5 would not work with the valve in the same jar as the jamon classes
004: * and also display stats in jamon.war. Simply compile this class sepeartely and put it in tomcats /server/classes/com/jamontomcat/http and put jamon-2.7.jar or higher in tomcats
005: * common/lib directory. Note this class should also work in tomcat 6 although it is easier simply to put jamon-2.7.jar (or higher in the server/lib)
006: * for tomcat 6.
007: *
008: * <Valve className="com.jamonapi.http.JAMonTomcatValve"/>
009: * same as default above
010: * <Valve className="com.jamonapi.http.JAMonTomcatValve" summaryLabels="request.getRequestURI().ms, response.getContentCount().bytes, response.getStatus().value.httpStatus">
011: * <Valve className="com.jamonapi.http.JAMonTomcatValve summaryLabels="request.getRequestURI().ms, request.getRequestURI().value.ms, response.getContentCount().pageBytes,response.getStatus().httpStatusCode, response.getStatus().value.httpStatusCode, response.getContentType().value.type"/>
012: * @author steve souza
013: *
014: */
015:
016: import javax.servlet.*;
017:
018: import java.io.IOException;
019: import org.apache.catalina.*;
020: import org.apache.catalina.valves.*;
021: import com.jamonapi.http.*;
022:
023: public class JAMonTomcat4Valve extends ValveBase {
024:
025: private static final String PREFIX = "com.jamontomcat.http.JAMonTomcat4Valve";
026: private static final String DEFAULT_SUMMARY = "default, response.getContentCount().bytes, response.getStatus().value.httpStatus, request.contextpath.ms";
027: HttpMonFactory httpMonFactory = new HttpMonFactory(PREFIX);
028:
029: private final String jamonSummaryLabels = "default";
030:
031: public JAMonTomcat4Valve() {
032: setSummaryLabels(jamonSummaryLabels);
033: }
034:
035: /**
036: * Extract the desired request property, and pass it (along with the
037: * specified request and response objects) to the protected
038: * <code>process()</code> method to perform the actual filtering.
039: * This method must be implemented by a concrete subclass.
040: *
041: * @param request The servlet request to be processed
042: * @param response The servlet response to be created
043: *
044: * @exception IOException if an input/output error occurs
045: * @exception ServletException if a servlet error occurs
046: * http://www.jdocs.com/tomcat/5.5.17/org/apache/catalina/valves/RequestFilterValve.html
047: *
048: * log response, request to see what they do.
049: * debug mode?
050: * test xml - read property
051: */
052:
053: public void invoke(Request request, Response response,
054: ValveContext valveContext) throws IOException,
055: ServletException {
056: HttpMon httpMon = null;
057: try {
058: httpMon = httpMonFactory.start(request, response);
059:
060: // tomcat 4/5
061: if (valveContext != null)
062: valveContext.invokeNext(request, response);
063:
064: } catch (Throwable e) {
065: httpMon.throwException(e);
066: } finally {
067: httpMon.stop();
068: }
069:
070: }
071:
072: public void setSummaryLabels(String jamonSummaryLabels) {
073: httpMonFactory.setSummaryLabels(jamonSummaryLabels,
074: DEFAULT_SUMMARY);
075: }
076:
077: public String getSummaryLabels() {
078: return httpMonFactory.getSummaryLabels();
079: }
080:
081: public void addSummaryLabel(String jamonSummaryLabel) {
082: httpMonFactory.addSummaryLabel(jamonSummaryLabel);
083:
084: }
085:
086: public boolean getIgnoreHttpParams() {
087: return httpMonFactory.getIgnoreHttpParams();
088: }
089:
090: public void setIgnoreHttpParams(boolean ignoreHttpParams) {
091: httpMonFactory.setIgnoreHttpParams(ignoreHttpParams);
092: }
093:
094: public void setEnabled(boolean enable) {
095: httpMonFactory.setEnabled(enable);
096:
097: }
098:
099: public int getSize() {
100: return httpMonFactory.getSize();
101: }
102:
103: public boolean getEnabled() {
104: return httpMonFactory.getEnabled();
105: }
106:
107: public void setSize(int size) {
108: httpMonFactory.setSize(size);
109:
110: }
111:
112: public String getInfo() {
113: return PREFIX;
114: }
115:
116: }
|