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/jamontomcatvalve/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: //START tomcat 4/5
017: /*
018:
019: Note I have not tested or run TomcatValves in tomcat 4 or 5, however they will work if coded
020: in a manner similar to the following.
021: // tomcat 4/5
022: import org.apache.catalina.*;
023: import org.apache.catalina.valves.*;
024:
025: // use catalina.jar from tomcat4
026:
027: public class JAMonTomcat55Valve extends org.apache.catalina.valves.ValveBase {
028:
029: // tomcat 4/5
030: public void invoke(Request request, Response response, ValveContext valveContext) throws IOException, ServletException {
031: start monitoring
032:
033: // tomcat 4/5
034: if (valveContext!=null)
035: valveContext.invokeNext(request, response);
036:
037: stop monitoring
038: }
039:
040: */
041:
042: import javax.servlet.*;
043:
044: import org.apache.catalina.Valve;
045: import java.io.IOException;
046:
047: //START tomcat 5.5/6
048: import org.apache.catalina.connector.Request;
049: import org.apache.catalina.connector.Response;
050: import com.jamonapi.http.*;
051:
052: public class JAMonTomcat55Valve extends
053: org.apache.catalina.valves.ValveBase {
054: private static final String PREFIX = "com.jamontomcat.http.JAMonTomcat55Valve";
055: private static final String DEFAULT_SUMMARY = "default, response.getContentCount().bytes, response.getStatus().value.httpStatus, request.contextpath.ms";
056: HttpMonFactory httpMonFactory = new HttpMonFactory(PREFIX);
057:
058: private final String jamonSummaryLabels = "default";
059:
060: public JAMonTomcat55Valve() {
061: setSummaryLabels(jamonSummaryLabels);
062: }
063:
064: /**
065: * Extract the desired request property, and pass it (along with the
066: * specified request and response objects) to the protected
067: * <code>process()</code> method to perform the actual filtering.
068: * This method must be implemented by a concrete subclass.
069: *
070: * @param request The servlet request to be processed
071: * @param response The servlet response to be created
072: *
073: * @exception IOException if an input/output error occurs
074: * @exception ServletException if a servlet error occurs
075: * http://www.jdocs.com/tomcat/5.5.17/org/apache/catalina/valves/RequestFilterValve.html
076: *
077: * log response, request to see what they do.
078: * debug mode?
079: * test xml - read property
080: */
081:
082: public void invoke(Request request, Response response)
083: throws IOException, ServletException {
084: HttpMon httpMon = null;
085: try {
086: httpMon = httpMonFactory.start(request, response);
087:
088: Valve nextValve = getNext();
089: if (nextValve != null)
090: nextValve.invoke(request, response);
091:
092: } catch (Throwable e) {
093: httpMon.throwException(e);
094: } finally {
095: httpMon.stop();
096: }
097:
098: }
099:
100: public void setSummaryLabels(String jamonSummaryLabels) {
101: httpMonFactory.setSummaryLabels(jamonSummaryLabels,
102: DEFAULT_SUMMARY);
103: }
104:
105: public String getSummaryLabels() {
106: return httpMonFactory.getSummaryLabels();
107: }
108:
109: public void addSummaryLabel(String jamonSummaryLabel) {
110: httpMonFactory.addSummaryLabel(jamonSummaryLabel);
111:
112: }
113:
114: public boolean getIgnoreHttpParams() {
115: return httpMonFactory.getIgnoreHttpParams();
116: }
117:
118: public void setIgnoreHttpParams(boolean ignoreHttpParams) {
119: httpMonFactory.setIgnoreHttpParams(ignoreHttpParams);
120: }
121:
122: public void setEnabled(boolean enable) {
123: httpMonFactory.setEnabled(enable);
124:
125: }
126:
127: public int getSize() {
128: return httpMonFactory.getSize();
129: }
130:
131: public boolean getEnabled() {
132: return httpMonFactory.getEnabled();
133: }
134:
135: public void setSize(int size) {
136: httpMonFactory.setSize(size);
137:
138: }
139:
140: public String getInfo() {
141: return PREFIX;
142: }
143:
144: }
|