001: package com.jamonapi.http;
002:
003: /** This valve works in tomcat 6 and jboss tomcat 5.5. An alternative approach is to use the jamontomcat-2.7.jar and this approach is required for
004: * tomcat 4/5. The Valve architecture and signatures were changed between release 5 and 5.5. For tomcat 5.5
005: * this class should work in tomcats version of 5.5 but doesn't due to classloader issues. Instead put com.jamontomcatvalve.http.JAMonTomcat55Valve
006: * in your server/classes/com/jamontomcat/http directory and put jamon's jar in common/lib. This approach should also work in tomcat 6
007: * though I didn't try it. This is a wrapper class for the true monitoring class of HttpMonFactory.
008: *
009: * Note
010: * <Engine name="Catalina" defaultHost="localhost" debug="0"><br>
011: * <Valve className="com.jamonapi.http.JAMonTomcatValve"/><br>
012: <Valve className="com.jamontomcat.JAMonTomcat5Valve" size="10000" summaryLabels="default"/><br>
013: * <Valve className="com.jamonapi.http.JAMonTomcatValve" summaryLabels="request.getRequestURI().ms, response.getContentCount().bytes, response.getStatus().value.httpStatus"><br>
014: * <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"/> <br>
015: * @author steve souza
016: *
017: */
018:
019: import javax.servlet.*;
020:
021: import org.apache.catalina.Valve;
022: import java.io.IOException;
023:
024: import org.apache.catalina.connector.Request;
025: import org.apache.catalina.connector.Response;
026:
027: public class JAMonTomcatValve extends
028: org.apache.catalina.valves.ValveBase implements HttpMonManage {
029:
030: private static final String PREFIX = "com.jamonapi.http.JAMonTomcatValve";
031: private static final String DEFAULT_SUMMARY = "default, response.getContentCount().bytes, response.getStatus().value.httpStatus, request.contextpath.ms";
032: private HttpMonFactory httpMonFactory = new HttpMonFactory(PREFIX);
033:
034: private final String jamonSummaryLabels = "default";
035:
036: public JAMonTomcatValve() {
037: setSummaryLabels(jamonSummaryLabels);
038: }
039:
040: /**
041: * Extract the desired request property, and pass it (along with the
042: * specified request and response objects) to the protected
043: * <code>process()</code> method to perform the actual filtering.
044: * This method must be implemented by a concrete subclass.
045: *
046: * @param request The servlet request to be processed
047: * @param response The servlet response to be created
048: *
049: * @exception IOException if an input/output error occurs
050: * @exception ServletException if a servlet error occurs
051: * http://www.jdocs.com/tomcat/5.5.17/org/apache/catalina/valves/RequestFilterValve.html
052: *
053: * log response, request to see what they do.
054: * debug mode?
055: * test xml - read property
056: */
057:
058: public void invoke(Request request, Response response)
059: throws IOException, ServletException {
060: HttpMon httpMon = null;
061: try {
062: httpMon = httpMonFactory.start(request, response);
063:
064: Valve nextValve = getNext();
065: if (nextValve != null)
066: nextValve.invoke(request, response);
067:
068: } catch (Throwable e) {
069: httpMon.throwException(e);
070: } finally {
071: httpMon.stop();
072: }
073:
074: }
075:
076: public void setSummaryLabels(String jamonSummaryLabels) {
077: httpMonFactory.setSummaryLabels(jamonSummaryLabels,
078: DEFAULT_SUMMARY);
079: }
080:
081: public String getSummaryLabels() {
082: return httpMonFactory.getSummaryLabels();
083: }
084:
085: public void addSummaryLabel(String jamonSummaryLabel) {
086: httpMonFactory.addSummaryLabel(jamonSummaryLabel);
087:
088: }
089:
090: public boolean getIgnoreHttpParams() {
091: return httpMonFactory.getIgnoreHttpParams();
092: }
093:
094: public void setIgnoreHttpParams(boolean ignoreHttpParams) {
095: httpMonFactory.setIgnoreHttpParams(ignoreHttpParams);
096: }
097:
098: public void setEnabled(boolean enable) {
099: httpMonFactory.setEnabled(enable);
100:
101: }
102:
103: public int getSize() {
104: return httpMonFactory.getSize();
105: }
106:
107: public boolean getEnabled() {
108: return httpMonFactory.getEnabled();
109: }
110:
111: public void setSize(int size) {
112: httpMonFactory.setSize(size);
113:
114: }
115:
116: public String getInfo() {
117: return PREFIX;
118: }
119:
120: }
|