001: package com.jamonapi.http;
002:
003: import java.io.IOException;
004:
005: import javax.servlet.Filter;
006: import javax.servlet.FilterChain;
007: import javax.servlet.FilterConfig;
008: import javax.servlet.ServletException;
009: import javax.servlet.ServletRequest;
010: import javax.servlet.ServletResponse;
011: import javax.servlet.http.HttpServlet;
012:
013: /** Note this servlet filter is more functional than com.jamonapi.JAMonFilter, but either can be used.
014: * This is a wrapper class for the true monitoring class of HttpMonFactory.
015: *
016: * <web-app>
017: <display-name>jamon</display-name>
018: <filter>
019: <filter-name>JAMonServletFilter</filter-name>
020: <filter-class>com.jamonapi.http.JAMonServletFilter</filter-class>
021: </filter>
022:
023: <filter-mapping>
024: <filter-name>JAMonServletFilter</filter-name>
025: <url-pattern>*</url-pattern>
026: </filter-mapping>
027: */
028: public class JAMonServletFilter extends HttpServlet implements
029: HttpMonManage, Filter {
030:
031: private static final long serialVersionUID = 27L;
032:
033: private static final String PREFIX = "com.jamonapi.http.JAMonServletFilter";
034: private HttpMonFactory httpMonFactory = new HttpMonFactory(PREFIX);
035:
036: private final String jamonSummaryLabels = "request.getRequestURI().ms as allPages, request.getRequestURI().value.ms as page, request.contextpath.ms";
037:
038: public JAMonServletFilter() {
039: setSummaryLabels(jamonSummaryLabels);
040: }
041:
042: /** Servlet filter method that does the monitoring */
043:
044: public void doFilter(ServletRequest request,
045: ServletResponse response, FilterChain filterChain)
046: throws IOException, ServletException {
047: HttpMon httpMon = null;
048: try {
049: httpMon = httpMonFactory.start(request, response);
050: filterChain.doFilter(request, response);
051: } catch (Throwable e) {
052: httpMon.throwException(e);
053: } finally {
054: httpMon.stop();
055: }
056: }
057:
058: public void setSummaryLabels(String jamonSummaryLabels) {
059: httpMonFactory.setSummaryLabels(jamonSummaryLabels);
060: }
061:
062: public String getSummaryLabels() {
063: return httpMonFactory.getSummaryLabels();
064: }
065:
066: public void addSummaryLabel(String jamonSummaryLabel) {
067: httpMonFactory.addSummaryLabel(jamonSummaryLabel);
068:
069: }
070:
071: public boolean getIgnoreHttpParams() {
072: return httpMonFactory.getIgnoreHttpParams();
073: }
074:
075: public void setIgnoreHttpParams(boolean ignoreHttpParams) {
076: httpMonFactory.setIgnoreHttpParams(ignoreHttpParams);
077: }
078:
079: public void setEnabled(boolean enable) {
080: httpMonFactory.setEnabled(enable);
081:
082: }
083:
084: public int getSize() {
085: return httpMonFactory.getSize();
086: }
087:
088: public boolean getEnabled() {
089: return httpMonFactory.getEnabled();
090: }
091:
092: public void setSize(int size) {
093: httpMonFactory.setSize(size);
094:
095: }
096:
097: public void init(FilterConfig arg0) throws ServletException {
098:
099: }
100:
101: }
|