KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > jonas > web > jetty50 > JSR77Configuration


1 /**
2  * JOnAS: Java(TM) Open Application Server
3  * Copyright (C) 2005 Bull S.A.
4  * Contact: jonas-team@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id$
23  * --------------------------------------------------------------------------
24  */

25 package org.objectweb.jonas.web.jetty50;
26
27 import org.mortbay.jetty.servlet.Dispatcher;
28 import org.mortbay.jetty.servlet.FilterHolder;
29 import org.mortbay.jetty.servlet.ServletHolder;
30 import org.mortbay.jetty.servlet.WebApplicationContext;
31 import org.mortbay.jetty.servlet.WebApplicationHandler;
32 import org.mortbay.jetty.servlet.WebApplicationContext.Configuration;
33 import org.mortbay.jetty.servlet.jsr77.Jsr77Filter;
34
35 import org.apache.commons.logging.Log;
36 import org.apache.commons.logging.LogFactory;
37
38 /**
39  * Replace the JSR77 Configuration implementation from Jetty 5.0
40  * This class add Filters to the Servlets in order to provide some statistics.
41  *
42  * @author Guillaume Sauthier
43  */

44 public class JSR77Configuration implements Configuration {
45
46     /**
47      * Filter name prefix
48      */

49     public static final String JavaDoc FILTER_PREFIX = "JSR77Filter-";
50
51     /**
52      * logger
53      */

54     private static Log log = LogFactory.getLog(JSR77Configuration.class);
55
56     /**
57      * The monitored WebApplication
58      */

59     private WebApplicationContext webAppContext = null;
60
61     /**
62      * Defualt Constructor
63      */

64     public JSR77Configuration() {
65         super();
66     }
67
68     /**
69      * @param wac the monitored WebApplication
70      */

71     public void setWebApplicationContext(WebApplicationContext wac) {
72         this.webAppContext = wac;
73     }
74
75     /**
76      * @return the monitored WebApplication
77      */

78     public WebApplicationContext getWebApplicationContext() {
79         return this.webAppContext;
80     }
81
82     /**
83      * was not implemented in Jetty's Configuration
84      * @throws Exception not documented !
85      */

86     public void configureClassPath() throws Exception JavaDoc {
87         // TODO Auto-generated method stub
88

89     }
90
91     /**
92      * was not implemented in Jetty's Configuration
93      * @throws Exception not documented !
94      */

95     public void configureDefaults() throws Exception JavaDoc {
96         // TODO Auto-generated method stub
97

98     }
99
100     /**
101      * Add the Statistic Filters for JSR77
102      * @throws Exception not documented !
103      */

104     public void configureWebApp() throws Exception JavaDoc {
105         if (this.webAppContext.isStarted()) {
106             if (log.isDebugEnabled()) {
107                 log.debug("Cannot configure webapp after it is started");
108             }
109             return;
110         }
111
112         // get the context, ask it for all of its servlets, configure a
113
// Jsr77Filter for
114
// each of them as the LAST filter
115
if (this.webAppContext != null) {
116             ServletHolder[] servlets = this.webAppContext.getServletHandler().getServlets();
117             WebApplicationHandler waHandler = this.webAppContext.getWebApplicationHandler();
118
119             for (int i = 0; servlets != null && i < servlets.length; i++) {
120                 String JavaDoc filterName = FILTER_PREFIX + servlets[i].getName();
121                 FilterHolder holder = waHandler.defineFilter(filterName, Jsr77Filter.class.getName());
122                 waHandler.addFilterServletMapping(servlets[i].getName(), filterName, Dispatcher.__ALL);
123                 holder.put("servlet-name", servlets[i].getName());
124                 if (log.isDebugEnabled()) {
125                     log.debug("Configured JSR77 filter " + filterName);
126                 }
127             }
128         }
129
130     }
131
132 }
133
Popular Tags