Author: remy.maucherat(a)jboss.com
Date: 2009-11-19 14:10:23 -0500 (Thu, 19 Nov 2009)
New Revision: 1278
Added:
trunk/java/org/apache/catalina/core/ServiceMapperListener.java
Modified:
trunk/java/org/apache/catalina/Service.java
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/connector/Request.java
trunk/java/org/apache/catalina/core/StandardService.java
Log:
- Add a new simpler mapper listener, associated with Service.
Modified: trunk/java/org/apache/catalina/Service.java
===================================================================
--- trunk/java/org/apache/catalina/Service.java 2009-11-19 19:01:33 UTC (rev 1277)
+++ trunk/java/org/apache/catalina/Service.java 2009-11-19 19:10:23 UTC (rev 1278)
@@ -19,6 +19,7 @@
package org.apache.catalina;
import org.apache.catalina.connector.Connector;
+import org.apache.tomcat.util.http.mapper.Mapper;
/**
* A <strong>Service</strong> is a group of one or more
@@ -61,6 +62,12 @@
public String getInfo();
/**
+ * Return the <code>Mapper</code> that handles mapping for all
+ * <code>Connectors</code> associated with this Service.
+ */
+ public Mapper getMapper();
+
+ /**
* Return the name of this Service.
*/
public String getName();
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-19 19:01:33 UTC
(rev 1277)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-19 19:10:23 UTC
(rev 1278)
@@ -527,7 +527,7 @@
} else {
serverName = req.serverName();
}
- connector.getMapper().map(serverName, decodedURI,
+ connector.getService().getMapper().map(serverName, decodedURI,
request.getMappingData());
request.setContext((Context) request.getMappingData().context);
request.setWrapper((Wrapper) request.getMappingData().wrapper);
Modified: trunk/java/org/apache/catalina/connector/Request.java
===================================================================
--- trunk/java/org/apache/catalina/connector/Request.java 2009-11-19 19:01:33 UTC (rev
1277)
+++ trunk/java/org/apache/catalina/connector/Request.java 2009-11-19 19:10:23 UTC (rev
1278)
@@ -685,10 +685,7 @@
* Return the Host within which this Request is being processed.
*/
public Host getHost() {
- if (getContext() == null)
- return null;
- return (Host) getContext().getParent();
- //return ((Host) mappingData.host);
+ return ((Host) mappingData.host);
}
Added: trunk/java/org/apache/catalina/core/ServiceMapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/ServiceMapperListener.java
(rev 0)
+++ trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-19 19:10:23 UTC
(rev 1278)
@@ -0,0 +1,174 @@
+/*
+ * 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.core;
+
+import org.apache.catalina.Container;
+import org.apache.catalina.ContainerEvent;
+import org.apache.catalina.ContainerListener;
+import org.apache.catalina.Context;
+import org.apache.catalina.Engine;
+import org.apache.catalina.Host;
+import org.apache.catalina.Lifecycle;
+import org.apache.catalina.LifecycleEvent;
+import org.apache.catalina.LifecycleListener;
+import org.apache.catalina.Service;
+import org.apache.catalina.Wrapper;
+import org.apache.tomcat.util.http.mapper.Mapper;
+
+
+/**
+ * Mapper listener.
+ *
+ * @author Remy Maucherat
+ * @author Costin Manolache
+ */
+public class ServiceMapperListener
+ implements LifecycleListener, ContainerListener
+ {
+
+
+ // ----------------------------------------------------- Instance Variables
+
+
+ /**
+ * Associated mapper.
+ */
+ protected Mapper mapper = null;
+
+
+ // ----------------------------------------------------------- Constructors
+
+
+ /**
+ * Create mapper listener.
+ */
+ public ServiceMapperListener(Mapper mapper) {
+ this.mapper = mapper;
+ }
+
+
+ // --------------------------------------------------------- Public Methods
+
+
+ public void containerEvent(ContainerEvent event) {
+
+ Container container = event.getContainer();
+ String type = event.getType();
+
+ if (type.equals(Container.ADD_CHILD_EVENT)) {
+ if (container instanceof Host) {
+ // Deploying a webapp
+ Context context = (Context) event.getData();
+ ((Lifecycle) context).addLifecycleListener(this);
+ if (context.isStarted()) {
+ mapper.addContext(container.getName(), context.getName(), context,
+ context.findWelcomeFiles(), context.getResources());
+ }
+ } else if (container instanceof Engine) {
+ // Deploying a host
+ container.addContainerListener(this);
+ Host host = (Host) event.getData();
+ mapper.addHost(host.getName(), host.findAliases(), host);
+ }
+ } else if (type.equals(Container.REMOVE_CHILD_EVENT)) {
+ if (container instanceof Host) {
+ // Undeploying a webapp
+ Context context = (Context) event.getData();
+ ((Lifecycle) context).removeLifecycleListener(this);
+ mapper.removeContext(container.getName(), context.getName());
+ } else if (container instanceof Engine) {
+ // Undeploying a host
+ container.removeContainerListener(this);
+ Host host = (Host) event.getData();
+ mapper.removeHost(host.getName());
+ }
+ } else if (type == Host.ADD_ALIAS_EVENT) {
+ mapper.addHostAlias(((Host) event.getSource()).getName(),
+ event.getData().toString());
+ } else if (type == Host.REMOVE_ALIAS_EVENT) {
+ mapper.removeHostAlias(event.getData().toString());
+ }
+
+ }
+
+
+ public void lifecycleEvent(LifecycleEvent event) {
+
+ Object source = event.getLifecycle();
+
+ if (Lifecycle.START_EVENT.equals(event.getType())) {
+ if (source instanceof Service) {
+ Service service = (Service) source;
+ Engine engine = (Engine) service.getContainer();
+ engine.addContainerListener(this);
+ ((Lifecycle) engine).addLifecycleListener(this);
+ if (engine.getDefaultHost() != null) {
+ mapper.setDefaultHostName(engine.getDefaultHost());
+ }
+ for (Container host : engine.findChildren()) {
+ host.addContainerListener(this);
+ mapper.addHost(host.getName(), ((Host) host).findAliases(), host);
+ for (Container context : host.findChildren()) {
+ ((Lifecycle) context).addLifecycleListener(this);
+ }
+ }
+ } else {
+ return;
+ }
+ } else if (Lifecycle.STOP_EVENT.equals(event.getType())) {
+ if (source instanceof Context) {
+ // Stop a webapp
+ Context context = (Context) source;
+ mapper.removeContext(context.getParent().getName(), context.getName());
+ } else if (source instanceof Service) {
+ Service service = (Service) source;
+ Engine engine = (Engine) service.getContainer();
+ engine.removeContainerListener(this);
+ ((Lifecycle) engine).removeLifecycleListener(this);
+ for (Container host : engine.findChildren()) {
+ host.removeContainerListener(this);
+ mapper.removeHost(host.getName());
+ for (Container context : host.findChildren()) {
+ ((Lifecycle) context).removeLifecycleListener(this);
+ mapper.removeContext(host.getName(), context.getName());
+ }
+ }
+ } else {
+ return;
+ }
+ } else if (Context.COMPLETE_CONFIG_EVENT.equals(event.getType())) {
+ Context context = (Context) source;
+ mapper.addContext(context.getParent().getName(), context.getName(), context,
+ context.findWelcomeFiles(), context.getResources());
+ // Add all wrappers
+ for (Container child : context.findChildren()) {
+ Wrapper wrapper = (Wrapper) child;
+ if (wrapper.getEnabled()) {
+ for (String mapping : wrapper.findMappings()) {
+ boolean jspWildCard = ("jsp".equals(wrapper.getName())
+ && mapping.endsWith("/*"));
+ mapper.addWrapper(context.getParent().getName(),
context.getName(),
+ mapping, wrapper, jspWildCard);
+ }
+ }
+ }
+ } else if (Lifecycle.PERIODIC_EVENT.equals(event.getType())) {
+ }
+
+ }
+
+}
Modified: trunk/java/org/apache/catalina/core/StandardService.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardService.java 2009-11-19 19:01:33 UTC (rev
1277)
+++ trunk/java/org/apache/catalina/core/StandardService.java 2009-11-19 19:10:23 UTC (rev
1278)
@@ -38,6 +38,7 @@
import org.apache.catalina.connector.Connector;
import org.apache.catalina.util.LifecycleSupport;
import org.apache.catalina.util.StringManager;
+import org.apache.tomcat.util.http.mapper.Mapper;
import org.apache.tomcat.util.modeler.Registry;
import org.jboss.logging.Logger;
@@ -125,8 +126,20 @@
*/
protected Container container = null;
+
+ /**
+ * Mapper.
+ */
+ protected Mapper mapper = new Mapper();
+
/**
+ * The associated mapper.
+ */
+ protected ServiceMapperListener mapperListener = new ServiceMapperListener(mapper);
+
+
+ /**
* Has this component been initialized?
*/
protected boolean initialized = false;
@@ -186,6 +199,12 @@
}
+
+ public Mapper getMapper() {
+ return mapper;
+ }
+
+
public ObjectName getContainerName() {
if( container instanceof ContainerBase ) {
return ((ContainerBase)container).getJmxName();
@@ -675,7 +694,8 @@
server.addService(this);
}
-
+ addLifecycleListener(mapperListener);
+
// Initialize our defined Connectors
synchronized (connectors) {
for (int i = 0; i < connectors.length; i++) {
@@ -687,6 +707,7 @@
public void destroy() throws LifecycleException {
if( started ) stop();
// FIXME unregister should be here probably -- stop doing that ?
+ removeLifecycleListener(mapperListener);
}
public void init() {