Author: remy.maucherat(a)jboss.com
Date: 2009-11-19 16:49:54 -0500 (Thu, 19 Nov 2009)
New Revision: 1279
Removed:
trunk/java/org/apache/catalina/connector/MapperListener.java
Modified:
trunk/java/org/apache/catalina/connector/Connector.java
trunk/java/org/apache/catalina/core/ServiceMapperListener.java
trunk/java/org/apache/catalina/core/StandardEngine.java
Log:
- Remove the old mapper listener.
Modified: trunk/java/org/apache/catalina/connector/Connector.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Connector.java 2009-11-19 19:10:23 UTC (rev
1278)
+++ trunk/java/org/apache/catalina/connector/Connector.java 2009-11-19 21:49:54 UTC (rev
1279)
@@ -32,13 +32,11 @@
import org.apache.catalina.LifecycleException;
import org.apache.catalina.LifecycleListener;
import org.apache.catalina.Service;
-import org.apache.catalina.core.StandardEngine;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
import org.apache.coyote.Adapter;
import org.apache.coyote.ProtocolHandler;
import org.apache.tomcat.util.IntrospectionUtils;
-import org.apache.tomcat.util.http.mapper.Mapper;
import org.apache.tomcat.util.modeler.Registry;
import org.jboss.logging.Logger;
@@ -252,18 +250,6 @@
/**
- * Mapper.
- */
- protected Mapper mapper = new Mapper();
-
-
- /**
- * Mapper listener.
- */
- protected MapperListener mapperListener = new MapperListener(mapper, this);
-
-
- /**
* URI encoding.
*/
protected String URIEncoding = null;
@@ -478,16 +464,6 @@
}
- /**
- * Return the mapper.
- */
- public Mapper getMapper() {
-
- return (mapper);
-
- }
-
-
/**
* Return the maximum size of a POST which will be automatically
* parsed by the container.
@@ -1017,11 +993,10 @@
this.initialized = true;
- if( oname == null && (container instanceof StandardEngine)) {
+ if (oname == null) {
try {
// we are loaded directly, via API - and no name was given to us
- StandardEngine cb=(StandardEngine)container;
- oname = createObjectName(cb.getName(), "Connector");
+ oname = createObjectName(container.getName(), "Connector");
Registry.getRegistry(null, null)
.registerComponent(this, oname, null);
controller=oname;
@@ -1125,22 +1100,6 @@
("coyoteConnector.protocolHandlerStartFailed", e));
}
- if( this.domain != null ) {
- mapperListener.setDomain( domain );
- //mapperListener.setEngine( service.getContainer().getName() );
- mapperListener.init();
- try {
- ObjectName mapperOname =
createObjectName(this.domain,"Mapper");
- if (log.isDebugEnabled())
- log.debug(sm.getString(
- "coyoteConnector.MapperRegistration",
mapperOname));
- Registry.getRegistry(null, null).registerComponent
- (mapper, mapperOname, "Mapper");
- } catch (Exception ex) {
- log.error(sm.getString
- ("coyoteConnector.protocolRegistrationFailed"), ex);
- }
- }
}
@@ -1161,10 +1120,7 @@
started = false;
try {
- mapperListener.destroy();
Registry.getRegistry(null, null).unregisterComponent
- (createObjectName(this.domain,"Mapper"));
- Registry.getRegistry(null, null).unregisterComponent
(createObjectName(this.domain,"ProtocolHandler"));
} catch (MalformedObjectNameException e) {
log.error( sm.getString
Deleted: trunk/java/org/apache/catalina/connector/MapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/connector/MapperListener.java 2009-11-19 19:10:23 UTC
(rev 1278)
+++ trunk/java/org/apache/catalina/connector/MapperListener.java 2009-11-19 21:49:54 UTC
(rev 1279)
@@ -1,535 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *
http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.catalina.connector;
-
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.management.MBeanServer;
-import javax.management.MBeanServerNotification;
-import javax.management.Notification;
-import javax.management.NotificationListener;
-import javax.management.ObjectInstance;
-import javax.management.ObjectName;
-
-import org.apache.catalina.ContainerEvent;
-import org.apache.catalina.ContainerListener;
-import org.apache.catalina.Host;
-import org.apache.catalina.core.StandardContext;
-import org.apache.tomcat.util.buf.MessageBytes;
-import org.apache.tomcat.util.http.mapper.Mapper;
-import org.apache.tomcat.util.http.mapper.MappingData;
-import org.apache.tomcat.util.modeler.Registry;
-import org.apache.tomcat.util.res.StringManager;
-import org.jboss.logging.Logger;
-
-
-/**
- * Mapper listener.
- *
- * @author Remy Maucherat
- * @author Costin Manolache
- * FIXME: redo as server listener ? see ClusterListener
- */
-public class MapperListener
- implements NotificationListener, ContainerListener
- {
- private static Logger log = Logger.getLogger(MapperListener.class);
-
-
- // ----------------------------------------------------- Instance Variables
- /**
- * Associated mapper.
- */
- protected Mapper mapper = null;
-
- /**
- * Associated connector
- */
- protected Connector connector = null;
-
- /**
- * MBean server.
- */
- protected MBeanServer mBeanServer = null;
-
-
- /**
- * The string manager for this package.
- */
- private StringManager sm =
- StringManager.getManager(Constants.Package);
-
- // It should be null - and fail if not set
- private String domain="*";
-
- // ----------------------------------------------------------- Constructors
-
-
- /**
- * Create mapper listener.
- */
- public MapperListener(Mapper mapper, Connector connector) {
- this.mapper = mapper;
- this.connector = connector;
- }
-
-
- // --------------------------------------------------------- Public Methods
-
- public String getDomain() {
- return domain;
- }
-
- public void setDomain(String domain) {
- this.domain = domain;
- }
-
- /**
- * Initialize associated mapper.
- */
- public void init() {
-
- try {
-
- mBeanServer = Registry.getRegistry(null, null).getMBeanServer();
-
- registerEngine();
-
- // Query hosts
- String onStr = domain + ":type=Host,*";
- ObjectName objectName = new ObjectName(onStr);
- Set set = mBeanServer.queryMBeans(objectName, null);
- Iterator iterator = set.iterator();
- while (iterator.hasNext()) {
- ObjectInstance oi = (ObjectInstance) iterator.next();
- registerHost(oi.getObjectName());
- }
-
-
- // Query contexts
- onStr = "*:j2eeType=WebModule,*";
- objectName = new ObjectName(onStr);
- set = mBeanServer.queryMBeans(objectName, null);
- iterator = set.iterator();
- while (iterator.hasNext()) {
- ObjectInstance oi = (ObjectInstance) iterator.next();
- registerContext(oi.getObjectName());
- }
-
- // Query wrappers
- onStr = "*:j2eeType=Servlet,*";
- objectName = new ObjectName(onStr);
- set = mBeanServer.queryMBeans(objectName, null);
- iterator = set.iterator();
- while (iterator.hasNext()) {
- ObjectInstance oi = (ObjectInstance) iterator.next();
- registerWrapper(oi.getObjectName());
- }
-
- onStr = "JMImplementation:type=MBeanServerDelegate";
- objectName = new ObjectName(onStr);
- mBeanServer.addNotificationListener(objectName, this, null, null);
-
- } catch (Exception e) {
- log.warn("Error registering contexts",e);
- }
-
- }
-
- /**
- * unregister this from JMImplementation:type=MBeanServerDelegate
- */
- public void destroy() {
- try {
-
- ObjectName objectName = new
ObjectName("JMImplementation:type=MBeanServerDelegate");
- if (mBeanServer != null) {
- mBeanServer.removeNotificationListener(objectName, this);
- }
- } catch (Exception e) {
- log.warn("Error unregistering MBeanServerDelegate", e);
- }
- }
-
- // ------------------------------------------- NotificationListener Methods
-
-
- public void handleNotification(Notification notification,
- java.lang.Object handback) {
-
- if (notification instanceof MBeanServerNotification) {
- ObjectName objectName =
- ((MBeanServerNotification) notification).getMBeanName();
- String j2eeType = objectName.getKeyProperty("j2eeType");
- String engineName = null;
- if (j2eeType != null) {
- if ((j2eeType.equals("WebModule")) ||
- (j2eeType.equals("Servlet"))) {
- if (mBeanServer.isRegistered(objectName)) {
- try {
- engineName = (String)
- mBeanServer.getAttribute(objectName,
"engineName");
- } catch (Exception e) {
- // Ignore
- }
- }
- }
- }
-
- // At deployment time, engineName is always = null.
- if ( (!"*".equals(domain)) &&
- ( !domain.equals(objectName.getDomain()) ) &&
- ( (!domain.equals(engineName) ) &&
- (engineName != null) ) ) {
- return;
- }
- if(log.isDebugEnabled())
- log.debug( "Handle " + objectName + " type : " +
notification.getType());
- if (notification.getType().equals
- (MBeanServerNotification.REGISTRATION_NOTIFICATION)) {
- String type=objectName.getKeyProperty("type");
- if( "Host".equals( type ) &&
domain.equals(objectName.getDomain())) {
- try {
- registerHost(objectName);
- } catch (Exception e) {
- log.warn("Error registering Host " + objectName, e);
- }
- }
-
- if (j2eeType != null) {
- if (j2eeType.equals("WebModule")) {
- try {
- registerContext(objectName);
- } catch (Throwable t) {
- log.warn("Error registering Context " +
objectName,t);
- }
- } else if (j2eeType.equals("Servlet")) {
- try {
- registerWrapper(objectName);
- } catch (Throwable t) {
- log.warn("Error registering Wrapper " +
objectName,t);
- }
- }
- }
- } else if (notification.getType().equals
- (MBeanServerNotification.UNREGISTRATION_NOTIFICATION)) {
- String type=objectName.getKeyProperty("type");
- if( "Host".equals( type )&&
domain.equals(objectName.getDomain())) {
- try {
- unregisterHost(objectName);
- } catch (Exception e) {
- log.warn("Error unregistering Host " + objectName,e);
- }
- }
-
- if (j2eeType != null) {
- if (j2eeType.equals("WebModule")) {
- try {
- unregisterContext(objectName);
- } catch (Throwable t) {
- log.warn("Error unregistering webapp " +
objectName,t);
- }
- }
- }
- }
- }
-
- }
-
-
- // --------------------------------------------- Container Listener methods
-
- public void containerEvent(ContainerEvent event) {
-
- if (event.getType() == Host.ADD_ALIAS_EVENT) {
- mapper.addHostAlias(((Host) event.getSource()).getName(),
- event.getData().toString());
- } else if (event.getType() == Host.REMOVE_ALIAS_EVENT) {
- mapper.removeHostAlias(event.getData().toString());
- }
- }
-
- // ------------------------------------------------------ Protected Methods
-
- private void registerEngine()
- throws Exception
- {
- ObjectName engineName = new ObjectName
- (domain + ":type=Engine");
- if ( ! mBeanServer.isRegistered(engineName)) return;
- String defaultHost =
- (String) mBeanServer.getAttribute(engineName, "defaultHost");
- ObjectName hostName = new ObjectName
- (domain + ":type=Host," + "host=" + defaultHost);
- if (!mBeanServer.isRegistered(hostName)) {
-
- // Get the hosts' list
- String onStr = domain + ":type=Host,*";
- ObjectName objectName = new ObjectName(onStr);
- Set set = mBeanServer.queryMBeans(objectName, null);
- Iterator iterator = set.iterator();
- String[] aliases;
- boolean isRegisteredWithAlias = false;
-
- while (iterator.hasNext()) {
-
- if (isRegisteredWithAlias) break;
-
- ObjectInstance oi = (ObjectInstance) iterator.next();
- hostName = oi.getObjectName();
- aliases = (String[])
- mBeanServer.invoke(hostName, "findAliases", null, null);
-
- for (int i=0; i < aliases.length; i++){
- if (aliases[i].equalsIgnoreCase(defaultHost)){
- isRegisteredWithAlias = true;
- break;
- }
- }
- }
-
- if (!isRegisteredWithAlias)
- log.warn(sm.getString("mapperListener.unknownDefaultHost",
defaultHost));
- }
- // This should probably be called later
- if( defaultHost != null ) {
- mapper.setDefaultHostName(defaultHost);
- }
- }
-
- /**
- * Register host.
- */
- private void registerHost(ObjectName objectName)
- throws Exception {
- String name=objectName.getKeyProperty("host");
- if( name != null ) {
- Host host = (Host) connector.getService().getContainer().findChild(name);
- String[] aliases = host.findAliases();
- mapper.addHost(name, aliases, objectName);
- host.addContainerListener(this);
- if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.registerHost", name, domain));
- }
- }
-
-
- private void unregisterHost(ObjectName objectName)
- throws Exception {
- String name=objectName.getKeyProperty("host");
- if( name != null ) {
- Host host =
- (Host) connector.getService().getContainer().findChild(name);
-
- mapper.removeHost(name);
- if (host != null) {
- host.removeContainerListener(this);
- }
- if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.unregisterHost", name, domain));
- }
- }
-
-
- /**
- * Register context.
- */
- private void registerContext(ObjectName objectName)
- throws Exception {
-
- String name = objectName.getKeyProperty("name");
-
- // If the domain is the same with ours or the engine
- // name attribute is the same... - then it's ours
- String targetDomain=objectName.getDomain();
- if( ! domain.equals( targetDomain )) {
- try {
- targetDomain = (String) mBeanServer.getAttribute
- (objectName, "engineName");
- } catch (Exception e) {
- // Ignore
- }
- if( ! domain.equals( targetDomain )) {
- // not ours
- return;
- }
- }
-
- String hostName = null;
- String contextName = null;
- if (name.startsWith("//")) {
- name = name.substring(2);
- }
- int slash = name.indexOf("/");
- if (slash != -1) {
- hostName = name.substring(0, slash);
- contextName = name.substring(slash);
- } else {
- return;
- }
- // Special case for the root context
- if (contextName.equals("/")) {
- contextName = "";
- }
-
- if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.registerContext", contextName));
-
- Object context =
- mBeanServer.invoke(objectName, "findMappingObject", null, null);
- //mBeanServer.getAttribute(objectName, "mappingObject");
- javax.naming.Context resources = (javax.naming.Context)
- mBeanServer.invoke(objectName, "findStaticResources", null, null);
- //mBeanServer.getAttribute(objectName, "staticResources");
- String[] welcomeFiles = (String[])
- mBeanServer.getAttribute(objectName, "welcomeFiles");
-
- mapper.addContext(hostName, contextName, context,
- welcomeFiles, resources);
-
- }
-
-
- /**
- * Unregister context.
- */
- private void unregisterContext(ObjectName objectName)
- throws Exception {
-
- String name = objectName.getKeyProperty("name");
-
- // If the domain is the same with ours or the engine
- // name attribute is the same... - then it's ours
- String targetDomain=objectName.getDomain();
- if( ! domain.equals( targetDomain )) {
- try {
- targetDomain = (String) mBeanServer.getAttribute
- (objectName, "engineName");
- } catch (Exception e) {
- // Ignore
- }
- if( ! domain.equals( targetDomain )) {
- // not ours
- return;
- }
- }
-
- String hostName = null;
- String contextName = null;
- if (name.startsWith("//")) {
- name = name.substring(2);
- }
- int slash = name.indexOf("/");
- if (slash != -1) {
- hostName = name.substring(0, slash);
- contextName = name.substring(slash);
- } else {
- return;
- }
- // Special case for the root context
- if (contextName.equals("/")) {
- contextName = "";
- }
- // Don't un-map a context that is paused
- MessageBytes hostMB = MessageBytes.newInstance();
- hostMB.setString(hostName);
- MessageBytes contextMB = MessageBytes.newInstance();
- contextMB.setString(contextName);
- MappingData mappingData = new MappingData();
- mapper.map(hostMB, contextMB, mappingData);
- if (mappingData.context instanceof StandardContext &&
- ((StandardContext)mappingData.context).getPaused()) {
- return;
- }
- if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.unregisterContext", contextName));
-
- mapper.removeContext(hostName, contextName);
-
- }
-
-
- /**
- * Register wrapper.
- */
- private void registerWrapper(ObjectName objectName)
- throws Exception {
-
- // If the domain is the same with ours or the engine
- // name attribute is the same... - then it's ours
- String targetDomain=objectName.getDomain();
- if( ! domain.equals( targetDomain )) {
- try {
- targetDomain=(String) mBeanServer.getAttribute(objectName,
"engineName");
- } catch (Exception e) {
- // Ignore
- }
- if( ! domain.equals( targetDomain )) {
- // not ours
- return;
- }
-
- }
-
- String wrapperName = objectName.getKeyProperty("name");
- String name = objectName.getKeyProperty("WebModule");
-
- String hostName = null;
- String contextName = null;
- if (name.startsWith("//")) {
- name = name.substring(2);
- }
- int slash = name.indexOf("/");
- if (slash != -1) {
- hostName = name.substring(0, slash);
- contextName = name.substring(slash);
- } else {
- return;
- }
- // Special case for the root context
- if (contextName.equals("/")) {
- contextName = "";
- }
- if(log.isDebugEnabled())
- log.debug(sm.getString
- ("mapperListener.registerWrapper",
- wrapperName, contextName));
-
- // FIXME: need to handle enabled flag
- String[] mappings = (String[])
- mBeanServer.invoke(objectName, "findMappings", null, null);
- Object wrapper =
- mBeanServer.invoke(objectName, "findMappingObject", null, null);
-
- for (int i = 0; i < mappings.length; i++) {
- boolean jspWildCard = (wrapperName.equals("jsp")
- && mappings[i].endsWith("/*"));
- mapper.addWrapper(hostName, contextName, mappings[i], wrapper,
- jspWildCard);
- }
-
- }
-
-
-
-
-}
Modified: trunk/java/org/apache/catalina/core/ServiceMapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-19 19:10:23 UTC
(rev 1278)
+++ trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-19 21:49:54 UTC
(rev 1279)
@@ -126,8 +126,6 @@
((Lifecycle) context).addLifecycleListener(this);
}
}
- } else {
- return;
}
} else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
if (source instanceof Context) {
@@ -147,8 +145,6 @@
mapper.removeContext(host.getName(), context.getName());
}
}
- } else {
- return;
}
} else if (Context.COMPLETE_CONFIG_EVENT.equals(event.getType())) {
Context context = (Context) source;
@@ -166,7 +162,6 @@
}
}
}
- } else if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
}
}
Modified: trunk/java/org/apache/catalina/core/StandardEngine.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardEngine.java 2009-11-19 19:10:23 UTC (rev
1278)
+++ trunk/java/org/apache/catalina/core/StandardEngine.java 2009-11-19 21:49:54 UTC (rev
1279)
@@ -37,7 +37,6 @@
import org.apache.tomcat.util.modeler.Registry;
import org.apache.tomcat.util.modeler.modules.MbeansSource;
import org.jboss.logging.Logger;
-import org.jboss.logging.Logger;
/**
* Standard implementation of the <b>Engine</b> interface. Each