Author: remy.maucherat(a)jboss.com
Date: 2009-11-25 10:20:31 -0500 (Wed, 25 Nov 2009)
New Revision: 1292
Added:
trunk/test/java/org/jboss/web/mapper/
trunk/test/java/org/jboss/web/mapper/MapperTestCase.java
Modified:
trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
trunk/java/org/apache/catalina/core/ServiceMapperListener.java
trunk/java/org/apache/catalina/core/StandardContext.java
trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
Log:
- Fix the scenario where the host starts the context.
- Cleanup.
Modified: trunk/java/org/apache/catalina/connector/CoyoteAdapter.java
===================================================================
--- trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-25 14:34:26 UTC
(rev 1291)
+++ trunk/java/org/apache/catalina/connector/CoyoteAdapter.java 2009-11-25 15:20:31 UTC
(rev 1292)
@@ -47,7 +47,6 @@
package org.apache.catalina.connector;
import java.io.IOException;
-import java.util.Iterator;
import javax.servlet.AsyncEvent;
import javax.servlet.AsyncListener;
Modified: trunk/java/org/apache/catalina/core/ServiceMapperListener.java
===================================================================
--- trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-25 14:34:26 UTC
(rev 1291)
+++ trunk/java/org/apache/catalina/core/ServiceMapperListener.java 2009-11-25 15:20:31 UTC
(rev 1292)
@@ -75,8 +75,7 @@
Context context = (Context) event.getData();
((Lifecycle) context).addLifecycleListener(this);
if (context.isStarted()) {
- mapper.addContext(container.getName(), context.getName(), context,
- context.findWelcomeFiles(), context.getResources());
+ addContext(context);
}
} else if (container instanceof Engine) {
// Deploying a host
@@ -148,22 +147,26 @@
}
} 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);
- }
+ addContext(context);
+ }
+
+ }
+
+ protected void addContext(Context context) {
+ 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);
}
}
}
-
}
}
Modified: trunk/java/org/apache/catalina/core/StandardContext.java
===================================================================
--- trunk/java/org/apache/catalina/core/StandardContext.java 2009-11-25 14:34:26 UTC (rev
1291)
+++ trunk/java/org/apache/catalina/core/StandardContext.java 2009-11-25 15:20:31 UTC (rev
1292)
@@ -4410,9 +4410,6 @@
ok = false;
}
- // Initialize associated mapper
- mapper.setContext(getPath(), welcomeFiles, resources);
-
// Binding thread
oldCCL = bindThread();
@@ -4432,8 +4429,6 @@
try {
-
-
// Create context attributes that will be required
if (ok) {
postContextAttributes();
@@ -4502,6 +4497,9 @@
unbindThread(oldCCL);
}
+ // Initialize associated mapper
+ mapper.setContext(getPath(), welcomeFiles, resources);
+
// Set available status depending upon startup success
if (ok) {
if (log.isDebugEnabled())
Modified: trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java
===================================================================
--- trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2009-11-25 14:34:26 UTC (rev
1291)
+++ trunk/java/org/apache/tomcat/util/http/mapper/Mapper.java 2009-11-25 15:20:31 UTC (rev
1292)
@@ -525,15 +525,15 @@
continue;
// found the context
Context ctx=hosts[i].contextList.contexts[j];
- list.add( ctx.defaultWrapper.path);
+ list.add( ctx.defaultWrapper.name);
for( int k=0; k<ctx.exactWrappers.length; k++ ) {
- list.add( ctx.exactWrappers[k].path);
+ list.add( ctx.exactWrappers[k].name);
}
for( int k=0; k<ctx.wildcardWrappers.length; k++ ) {
- list.add( ctx.wildcardWrappers[k].path + "*");
+ list.add( ctx.wildcardWrappers[k].name + "*");
}
for( int k=0; k<ctx.extensionWrappers.length; k++ ) {
- list.add( "*." + ctx.extensionWrappers[k].path);
+ list.add( "*." + ctx.extensionWrappers[k].name);
}
}
}
@@ -817,7 +817,6 @@
}
-
// Rule 7 -- Default servlet
if (mappingData.wrapper == null && !checkJspWelcomeFiles) {
if (context.defaultWrapper != null) {
@@ -1314,7 +1313,6 @@
protected static final class Context
extends MapElement {
- public String path = null;
public String[] welcomeResources = new String[0];
public javax.naming.Context resources = null;
public Wrapper defaultWrapper = null;
@@ -1332,121 +1330,8 @@
protected static class Wrapper
extends MapElement {
-
- public String path = null;
public boolean jspWildCard = false;
}
- // -------------------------------------------------------- Testing Methods
-
- // FIXME: Externalize this
- /*
- public static void main(String args[]) {
-
- try {
-
- Mapper mapper = new Mapper();
- System.out.println("Start");
-
- mapper.addHost("sjbjdvwsbvhrb", new String[0], "blah1");
- mapper.addHost("sjbjdvwsbvhr/", new String[0], "blah1");
- mapper.addHost("wekhfewuifweuibf", new String[0], "blah2");
- mapper.addHost("ylwrehirkuewh", new String[0], "blah3");
- mapper.addHost("iohgeoihro", new String[0], "blah4");
- mapper.addHost("fwehoihoihwfeo", new String[0], "blah5");
- mapper.addHost("owefojiwefoi", new String[0], "blah6");
- mapper.addHost("iowejoiejfoiew", new String[0], "blah7");
- mapper.addHost("iowejoiejfoiew", new String[0], "blah17");
- mapper.addHost("ohewoihfewoih", new String[0], "blah8");
- mapper.addHost("fewohfoweoih", new String[0], "blah9");
- mapper.addHost("ttthtiuhwoih", new String[0], "blah10");
- mapper.addHost("lkwefjwojweffewoih", new String[0],
"blah11");
- mapper.addHost("zzzuyopjvewpovewjhfewoih", new String[0],
"blah12");
- mapper.addHost("xxxxgqwiwoih", new String[0], "blah13");
- mapper.addHost("qwigqwiwoih", new String[0], "blah14");
-
- System.out.println("Map:");
- for (int i = 0; i < mapper.hosts.length; i++) {
- System.out.println(mapper.hosts[i].name);
- }
-
- mapper.setDefaultHostName("ylwrehirkuewh");
-
- String[] welcomes = new String[2];
- welcomes[0] = "boo/baba";
- welcomes[1] = "bobou";
-
- mapper.addContext("iowejoiejfoiew", "", "context0",
new String[0], null);
- mapper.addContext("iowejoiejfoiew", "/foo",
"context1", new String[0], null);
- mapper.addContext("iowejoiejfoiew", "/foo/bar",
"context2", welcomes, null);
- mapper.addContext("iowejoiejfoiew", "/foo/bar/bla",
"context3", new String[0], null);
-
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/fo/*", "wrapper0");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/", "wrapper1");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blh", "wrapper2");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"*.jsp", "wrapper3");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blah/bou/*", "wrapper4");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blah/bobou/*", "wrapper5");
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"*.htm", "wrapper6");
-
- MappingData mappingData = new MappingData();
- MessageBytes host = MessageBytes.newInstance();
- host.setString("iowejoiejfoiew");
- MessageBytes uri = MessageBytes.newInstance();
- uri.setString("/foo/bar/blah/bobou/foo");
- uri.toChars();
- uri.getCharChunk().setLimit(-1);
-
- mapper.map(host, uri, mappingData);
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- for (int i = 0; i < 1000000; i++) {
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- }
-
- long time = System.currentTimeMillis();
- for (int i = 0; i < 1000000; i++) {
- mappingData.recycle();
- mapper.map(host, uri, mappingData);
- }
- System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
-
- System.out.println("MD Host:" + mappingData.host);
- System.out.println("MD Context:" + mappingData.context);
- System.out.println("MD Wrapper:" + mappingData.wrapper);
-
- System.out.println("contextPath:" + mappingData.contextPath);
- System.out.println("wrapperPath:" + mappingData.wrapperPath);
- System.out.println("requestPath:" + mappingData.requestPath);
- System.out.println("pathInfo:" + mappingData.pathInfo);
- System.out.println("redirectPath:" + mappingData.redirectPath);
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
- */
-
-
}
Added: trunk/test/java/org/jboss/web/mapper/MapperTestCase.java
===================================================================
--- trunk/test/java/org/jboss/web/mapper/MapperTestCase.java (rev
0)
+++ trunk/test/java/org/jboss/web/mapper/MapperTestCase.java 2009-11-25 15:20:31 UTC (rev
1292)
@@ -0,0 +1,175 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2009, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ * @author Jean-Frederic Clere
+ */
+
+
+package org.jboss.web.mapper;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.io.BufferedReader;
+import java.io.BufferedWriter;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.net.Socket;
+
+public class MapperTestCase extends TestCase {
+
+ /**
+ * Construct a new instance of this test case.
+ *
+ * @param name Name of the test case
+ */
+ public MapperTestCase(String name) {
+ super(name);
+ }
+
+ /**
+ * Set up instance variables required by this test case.
+ */
+ public void setUp() {
+ }
+
+ /**
+ * Return the tests included in this test suite.
+ */
+ public static Test suite() {
+ return (new TestSuite(MapperTestCase.class));
+ }
+
+ /**
+ * Tear down instance variables required by this test case.
+ */
+ public void tearDown() {
+ }
+
+ /*
+ public static void main(String args[]) {
+
+ try {
+
+ Mapper mapper = new Mapper();
+ System.out.println("Start");
+
+ mapper.addHost("sjbjdvwsbvhrb", new String[0], "blah1");
+ mapper.addHost("sjbjdvwsbvhr/", new String[0], "blah1");
+ mapper.addHost("wekhfewuifweuibf", new String[0], "blah2");
+ mapper.addHost("ylwrehirkuewh", new String[0], "blah3");
+ mapper.addHost("iohgeoihro", new String[0], "blah4");
+ mapper.addHost("fwehoihoihwfeo", new String[0], "blah5");
+ mapper.addHost("owefojiwefoi", new String[0], "blah6");
+ mapper.addHost("iowejoiejfoiew", new String[0], "blah7");
+ mapper.addHost("iowejoiejfoiew", new String[0], "blah17");
+ mapper.addHost("ohewoihfewoih", new String[0], "blah8");
+ mapper.addHost("fewohfoweoih", new String[0], "blah9");
+ mapper.addHost("ttthtiuhwoih", new String[0], "blah10");
+ mapper.addHost("lkwefjwojweffewoih", new String[0],
"blah11");
+ mapper.addHost("zzzuyopjvewpovewjhfewoih", new String[0],
"blah12");
+ mapper.addHost("xxxxgqwiwoih", new String[0], "blah13");
+ mapper.addHost("qwigqwiwoih", new String[0], "blah14");
+
+ System.out.println("Map:");
+ for (int i = 0; i < mapper.hosts.length; i++) {
+ System.out.println(mapper.hosts[i].name);
+ }
+
+ mapper.setDefaultHostName("ylwrehirkuewh");
+
+ String[] welcomes = new String[2];
+ welcomes[0] = "boo/baba";
+ welcomes[1] = "bobou";
+
+ mapper.addContext("iowejoiejfoiew", "", "context0",
new String[0], null);
+ mapper.addContext("iowejoiejfoiew", "/foo",
"context1", new String[0], null);
+ mapper.addContext("iowejoiejfoiew", "/foo/bar",
"context2", welcomes, null);
+ mapper.addContext("iowejoiejfoiew", "/foo/bar/bla",
"context3", new String[0], null);
+
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/fo/*", "wrapper0");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/", "wrapper1");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blh", "wrapper2");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"*.jsp", "wrapper3");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blah/bou/*", "wrapper4");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"/blah/bobou/*", "wrapper5");
+ mapper.addWrapper("iowejoiejfoiew", "/foo/bar",
"*.htm", "wrapper6");
+
+ MappingData mappingData = new MappingData();
+ MessageBytes host = MessageBytes.newInstance();
+ host.setString("iowejoiejfoiew");
+ MessageBytes uri = MessageBytes.newInstance();
+ uri.setString("/foo/bar/blah/bobou/foo");
+ uri.toChars();
+ uri.getCharChunk().setLimit(-1);
+
+ mapper.map(host, uri, mappingData);
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ for (int i = 0; i < 1000000; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+
+ long time = System.currentTimeMillis();
+ for (int i = 0; i < 1000000; i++) {
+ mappingData.recycle();
+ mapper.map(host, uri, mappingData);
+ }
+ System.out.println("Elapsed:" + (System.currentTimeMillis() - time));
+
+ System.out.println("MD Host:" + mappingData.host);
+ System.out.println("MD Context:" + mappingData.context);
+ System.out.println("MD Wrapper:" + mappingData.wrapper);
+
+ System.out.println("contextPath:" + mappingData.contextPath);
+ System.out.println("wrapperPath:" + mappingData.wrapperPath);
+ System.out.println("requestPath:" + mappingData.requestPath);
+ System.out.println("pathInfo:" + mappingData.pathInfo);
+ System.out.println("redirectPath:" + mappingData.redirectPath);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ }
+ */
+
+}