Author: markt
Date: Mon Sep  7 13:37:06 2009
New Revision: 812133

URL: http://svn.apache.org/viewvc?rev=812133&view=rev
Log:
Expose filters via JMX

Modified:
    tomcat/tc6.0.x/trunk/   (props changed)
    tomcat/tc6.0.x/trunk/STATUS.txt
    
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
    tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
    tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml

Propchange: tomcat/tc6.0.x/trunk/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Mon Sep  7 13:37:06 2009
@@ -1 +1 @@
-/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,753039,757335,757774,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,770809,770876,776921,776924,776935,776945,777464,77
 
7466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,797168,797425,797596,797607,805153
+/tomcat/trunk:601180,606992,612607,630314,640888,652744,653247,673796,673820,683982,684001,684081,684234,684269-684270,685177,687503,687645,689402,690781,691392,691805,692748,693378,694992,695053,695311,696780,696782,698012,698227,698236,698613,699427,699634,701355,709294,709811,709816,710063,710066,710125,710205,711126,711600,712461,712467,718360,719119,719124,719602,719626,719628,720046,720069,721040,721286,721708,721886,723404,723738,726052,727303,728032,728768,728947,729057,729567,729569,729571,729681,729809,729815,729934,730250,730590,731651,732859,732863,734734,740675,740684,742677,742697,742714,744160,744238,746321,746384,746425,747834,747863,748344,750258,750291,750921,751286-751287,751289,751295,753039,757335,757774,758365,758596,758616,758664,759074,761601,762868,762929,762936-762937,763166,763183,763193,763228,763262,763298,763302,763325,763599,763611,763654,763681,763706,764985,764997,765662,768335,769979,770716,770809,770876,776921,776924,776935,776945,777464,77
 
7466,777576,777625,778379,778523-778524,781528,781779,782145,782791,783316,783696,783724,783756,783762,783766,783863,783934,784453,784602,784614,785381,785688,785768,785859,786468,786487,786490,786496,786667,787627,787770,787985,789389,790405,791041,791184,791194,791243,791326,791328,791789,792740,793372,793757,793882,793981,794082,794673,794822,795043,795152,795210,795457,797168,797425,797596,797607,802727,805153,812125

Modified: tomcat/tc6.0.x/trunk/STATUS.txt
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/STATUS.txt?rev=812133&r1=812132&r2=812133&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/STATUS.txt (original)
+++ tomcat/tc6.0.x/trunk/STATUS.txt Mon Sep  7 13:37:06 2009
@@ -190,15 +190,6 @@
   +1: markt
   -1: 
 
-* Expose filter configuration via JMX (read-only)
-  Based on a patch by Xie Xiaodong as part of GSOC2009.
-  http://svn.apache.org/viewvc?rev=802727&view=rev
-  +1: markt, funkman, rjung
-  -1: 
-  rjung: typo regsiter -> register should be corrected everywhere (method name,
-         log messages etc., string manager property, sometimes with 
capitalzation "Regsiter")
-         Another little style nitpick: "if(" -> "if (".
-
 * Use platform MBean server rather than creating a new one. Makes it possible 
to
   connect JConsole and other JMX tools to locally running Tomcat instances
   without any config changes to Tomcat

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java?rev=812133&r1=812132&r2=812133&view=diff
==============================================================================
--- 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 
(original)
+++ 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 
Mon Sep  7 13:37:06 2009
@@ -24,10 +24,12 @@
 import java.io.Serializable;
 import java.lang.reflect.InvocationTargetException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.Map;
 import java.util.Properties;
 
+import javax.management.ObjectName;
 import javax.naming.NamingException;
 import javax.servlet.Filter;
 import javax.servlet.FilterConfig;
@@ -41,7 +43,9 @@
 import org.apache.catalina.security.SecurityUtil;
 import org.apache.catalina.util.Enumerator;
 import org.apache.catalina.util.StringManager;
+import org.apache.juli.logging.LogFactory;
 import org.apache.tomcat.util.log.SystemLogHandler;
+import org.apache.tomcat.util.modeler.Registry;
 
 
 /**
@@ -53,12 +57,15 @@
  * @version $Revision$ $Date$
  */
 
-final class ApplicationFilterConfig implements FilterConfig, Serializable {
+public final class ApplicationFilterConfig implements FilterConfig, 
Serializable {
 
 
     protected static StringManager sm =
         StringManager.getManager(Constants.Package);
     
+    private static org.apache.juli.logging.Log log =
+        LogFactory.getLog(ApplicationFilterConfig.class);
+
     // ----------------------------------------------------------- Constructors
 
 
@@ -81,7 +88,7 @@
      * @throws NamingException 
      * @throws InvocationTargetException 
      */
-    public ApplicationFilterConfig(Context context, FilterDef filterDef)
+    ApplicationFilterConfig(Context context, FilterDef filterDef)
         throws ClassCastException, ClassNotFoundException,
                IllegalAccessException, InstantiationException,
                ServletException, InvocationTargetException, NamingException {
@@ -136,6 +143,10 @@
      */
     protected static Properties restrictedFilters = null;
 
+    /**
+     * JMX registration name
+     */
+    private ObjectName oname;
     
     // --------------------------------------------------- FilterConfig Methods
 
@@ -144,11 +155,15 @@
      * Return the name of the filter we are configuring.
      */
     public String getFilterName() {
-
         return (filterDef.getFilterName());
-
     }
 
+    /**
+     * Return the class of the filter we are configuring.
+     */
+    public String getFilterClass() {
+        return filterDef.getFilterClass();
+    }
 
     /**
      * Return a <code>String</code> containing the value of the named
@@ -208,6 +223,11 @@
 
     }
 
+    // --------------------------------------------------------- Public Methods
+
+    public Map<String, String> getFilterInitParameterMap() {
+        return Collections.unmodifiableMap(filterDef.getParameterMap());
+    }
 
     // -------------------------------------------------------- Package Methods
 
@@ -274,9 +294,12 @@
         } else {
             filter.init(this);
         }
+        
+        // Expose filter via JMX
+        registerJMX();
+        
         return (this.filter);
 
-
     }
 
 
@@ -319,6 +342,8 @@
      */
     void release() {
 
+        unregisterJMX();
+        
         if (this.filter != null)
         {
             if (Globals.IS_SECURITY_ENABLED) {
@@ -371,7 +396,7 @@
 
             // Release any previously allocated filter instance
             if (this.filter != null){
-                if( Globals.IS_SECURITY_ENABLED) {
+                if (Globals.IS_SECURITY_ENABLED) {
                     try{
                         SecurityUtil.doAsPrivilege("destroy", filter);  
                     } catch(java.lang.Exception ex){    
@@ -404,4 +429,54 @@
     // -------------------------------------------------------- Private Methods
 
 
+    private void registerJMX() {
+        String parentName = context.getName();
+        parentName = ("".equals(parentName)) ? "/" : parentName;
+
+        String hostName = context.getParent().getName();
+        hostName = (hostName == null) ? "DEFAULT" : hostName;
+
+        // domain == engine name
+        String domain = context.getParent().getParent().getName();
+
+        String webMod = "//" + hostName + parentName;
+        String onameStr = null;
+        if (context instanceof StandardContext) {
+            StandardContext standardContext = (StandardContext) context;
+            onameStr = domain + ":j2eeType=Filter,name=" +
+                 filterDef.getFilterName() + ",WebModule=" + webMod +
+                 ",J2EEApplication=" +
+                 standardContext.getJ2EEApplication() + ",J2EEServer=" +
+                 standardContext.getJ2EEServer();
+        } else {
+            onameStr = domain + ":j2eeType=Filter,name=" +
+                 filterDef.getFilterName() + ",WebModule=" + webMod;
+}
+        try {
+            oname = new ObjectName(onameStr);
+            Registry.getRegistry(null, null).registerComponent(this, oname,
+                    null);
+        } catch (Exception ex) {
+            log.info(sm.getString("applicationFilterConfig.jmxRegisterFail",
+                    getFilterClass(), getFilterName()), ex);
+        }
+    }
+    
+    private void unregisterJMX() {
+        // unregister this component
+        if (oname != null) {
+            try {
+                Registry.getRegistry(null, null).unregisterComponent(oname);
+                if (log.isDebugEnabled())
+                    log.debug(sm.getString(
+                            "applicationFilterConfig.jmxUnregister",
+                            getFilterClass(), getFilterName()));
+            } catch(Exception ex) {
+                log.error(sm.getString(
+                        "applicationFilterConfig.jmxUnregisterFail",
+                        getFilterClass(), getFilterName()), ex);
+            }
+        }
+
+    }
 }

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties?rev=812133&r1=812132&r2=812133&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/LocalStrings.properties 
Mon Sep  7 13:37:06 2009
@@ -27,6 +27,9 @@
 applicationDispatcher.serviceException=Servlet.service() for servlet {0} threw 
exception
 applicationDispatcher.specViolation.request=Original SevletRequest or wrapped 
original ServletRequest not passed to RequestDispatcher in violation of SRV.8.2 
and SRV.14.2.5.1
 applicationDispatcher.specViolation.response=Original SevletResponse or 
wrapped original ServletResponse not passed to RequestDispatcher in violation 
of SRV.8.2 and SRV.14.2.5.1
+applicationFilterConfig.jmxRegisterFail=JMX registration failed for filter of 
type [{0}] and name [{1}]
+applicationFilterConfig.jmxUnregister=JMX de-registration complete for filter 
of type [{0}] and name [{1}]
+applicationFilterConfig.jmxUnregisterFail=JMX de-registration failed for 
filter of type [{0}] and name [{1}]
 applicationRequest.badParent=Cannot locate parent Request implementation
 applicationRequest.badRequest=Request is not a 
javax.servlet.ServletRequestWrapper
 applicationResponse.badParent=Cannot locate parent Response implementation

Modified: 
tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml?rev=812133&r1=812132&r2=812133&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 
(original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 
Mon Sep  7 13:37:06 2009
@@ -17,6 +17,29 @@
 -->
 <mbeans-descriptors>
 
+  <mbean name="ApplicationFilterConfig"
+         description="Wrapper that represents an individual servlet-filter 
definition"
+         domain="Catalina"
+         group="Filter"
+         type="org.apache.catalina.core.ApplicationFilterConfig">
+                
+     <attribute name="filterName"
+                description="The name used to reference the filter in web.xml"
+                type="java.lang.String"
+                writeable="false"/>    
+
+     <attribute name="filterClass"
+                description="Fully qualified class name of the filter object"
+                type="java.lang.String"
+                writeable="false"/>                               
+
+     <attribute name="filterInitParameterMap"
+                description="Return the initiaization parameters associated 
with this filter"
+                type="java.util.Map"
+                writeable="false" />
+                    
+  </mbean> 
+
   <mbean name="NamingContextListener"
          description="Helper class used to initialize and populate the JNDI 
context associated with each context and server"
          domain="Catalina"

Modified: tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml
URL: 
http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml?rev=812133&r1=812132&r2=812133&view=diff
==============================================================================
--- tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc6.0.x/trunk/webapps/docs/changelog.xml Mon Sep  7 13:37:06 2009
@@ -160,6 +160,10 @@
         ability to specify a default role, optional handling for nested roles
         and an option to ignore PartialResultExceptions (markt). 
       </update>
+      <add>
+        Expose Sevlet Filters via JMX. Based on a patch by Xie Xiaodong as part
+        of GSOC2009. (markt)
+      </add>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to