Author: remy.maucherat(a)jboss.com
Date: 2009-08-17 08:48:31 -0400 (Mon, 17 Aug 2009)
New Revision: 1142
Modified:
trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
trunk/java/org/apache/catalina/core/LocalStrings.properties
trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
trunk/webapps/docs/changelog.xml
Log:
- Port JMX filter registration.
Modified: trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java
===================================================================
--- trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-08-04 16:40:02
UTC (rev 1141)
+++ trunk/java/org/apache/catalina/core/ApplicationFilterConfig.java 2009-08-17 12:48:31
UTC (rev 1142)
@@ -59,6 +59,7 @@
import java.util.Map;
import java.util.Set;
+import javax.management.ObjectName;
import javax.naming.NamingException;
import javax.servlet.DispatcherType;
import javax.servlet.Filter;
@@ -76,6 +77,7 @@
import org.apache.catalina.util.StringManager;
import org.apache.tomcat.InstanceManager;
import org.apache.tomcat.util.log.SystemLogHandler;
+import org.apache.tomcat.util.modeler.Registry;
/**
@@ -90,6 +92,9 @@
public final class ApplicationFilterConfig implements FilterConfig, Serializable {
+ protected static org.jboss.logging.Logger log=
+ org.jboss.logging.Logger.getLogger( ApplicationFilterConfig.class );
+
protected static StringManager sm =
StringManager.getManager(Constants.Package);
@@ -155,6 +160,12 @@
private transient InstanceManager instanceManager;
+ /**
+ * JMX registration name
+ */
+ private ObjectName oname;
+
+
// --------------------------------------------------- FilterConfig Methods
@@ -167,6 +178,14 @@
/**
+ * 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
* initialization parameter, or <code>null</code> if the parameter
* does not exist.
@@ -364,6 +383,11 @@
}
+ public Map<String, String> getInitParameters() {
+ return Collections.unmodifiableMap(filterDef.getParameterMap());
+ }
+
+
// -------------------------------------------------------- Package Methods
@@ -412,9 +436,12 @@
} else {
filter.init(this);
}
+
+ // Expose filter via JMX
+ registerJMX();
+
return (this.filter);
-
}
@@ -441,6 +468,8 @@
*/
void release() {
+ unregsiterJMX();
+
if (this.filter != null)
{
if (Globals.IS_SECURITY_ENABLED) {
@@ -483,4 +512,55 @@
return instanceManager;
}
+ 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.jmxRegsiterFail",
+ getFilterClass(), getFilterName()), ex);
+ }
+ }
+
+ private void unregsiterJMX() {
+ // unregister this component
+ if (oname != null) {
+ try {
+ Registry.getRegistry(null, null).unregisterComponent(oname);
+ if(log.isDebugEnabled())
+ log.debug(sm.getString(
+ "applicationFilterConfig.jmxUnregsiter",
+ getFilterClass(), getFilterName()));
+ } catch(Exception ex) {
+ log.error(sm.getString(
+ "applicationFilterConfig.jmxUnregsiterFail",
+ getFilterClass(), getFilterName()), ex);
+ }
+ }
+
+ }
+
}
Modified: trunk/java/org/apache/catalina/core/LocalStrings.properties
===================================================================
--- trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-08-04 16:40:02 UTC
(rev 1141)
+++ trunk/java/org/apache/catalina/core/LocalStrings.properties 2009-08-17 12:48:31 UTC
(rev 1142)
@@ -31,6 +31,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: trunk/java/org/apache/catalina/core/mbeans-descriptors.xml
===================================================================
--- trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 2009-08-04 16:40:02 UTC
(rev 1141)
+++ trunk/java/org/apache/catalina/core/mbeans-descriptors.xml 2009-08-17 12:48:31 UTC
(rev 1142)
@@ -1,6 +1,29 @@
<?xml version="1.0"?>
<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="initParameters"
+ 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: trunk/webapps/docs/changelog.xml
===================================================================
--- trunk/webapps/docs/changelog.xml 2009-08-04 16:40:02 UTC (rev 1141)
+++ trunk/webapps/docs/changelog.xml 2009-08-17 12:48:31 UTC (rev 1142)
@@ -127,6 +127,9 @@
<bug>41059</bug>: Reduce one possible source of errors if using
ENABLE_CLEAR_REFERENCES=true.
Patch by Curt Arnold. (markt)
</fix>
+ <fix>
+ Register filters with JMX. (markt)
+ </fix>
</changelog>
</subsection>
<subsection name="Coyote">
@@ -140,6 +143,9 @@
<fix>
Fix handling of timeout values <= 0 with the poller refactoring. (remm)
</fix>
+ <fix>
+ <jboss-jira>JBAS-6442</jboss-jira>: The character encoder should
tolerate unmappable characters. (jfclere)
+ </fix>
</changelog>
</subsection>
<subsection name="Jasper">