You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2014/06/30 14:37:39 UTC
svn commit: r1606714 - in /tomcat/trunk: java/org/apache/catalina/mapper/
test/org/apache/catalina/mapper/ webapps/docs/
Author: kkolinko
Date: Mon Jun 30 12:37:38 2014
New Revision: 1606714
URL: http://svn.apache.org/r1606714
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=56658
Avoid delay between registrations of mappings for context and for its servlets.
Added:
tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java (with props)
Modified:
tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java
tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java
tomcat/trunk/webapps/docs/changelog.xml
Modified: tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java?rev=1606714&r1=1606713&r2=1606714&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/Mapper.java Mon Jun 30 12:37:38 2014
@@ -214,10 +214,31 @@ public final class Mapper {
* @param context Context object
* @param welcomeResources Welcome files defined for this context
* @param resources Static resources of the context
+ * @deprecated Use {@link #addContextVersion(String, Host, String, String, Context, String[], WebResourceRoot, Collection)}
*/
+ @Deprecated
public void addContextVersion(String hostName, Host host, String path,
String version, Context context, String[] welcomeResources,
WebResourceRoot resources) {
+ addContextVersion(hostName, host, path, version, context,
+ welcomeResources, resources, null);
+ }
+
+ /**
+ * Add a new Context to an existing Host.
+ *
+ * @param hostName Virtual host name this context belongs to
+ * @param host Host object
+ * @param path Context path
+ * @param version Context version
+ * @param context Context object
+ * @param welcomeResources Welcome files defined for this context
+ * @param resources Static resources of the context
+ * @param wrappers Information on wrapper mappings
+ */
+ public void addContextVersion(String hostName, Host host, String path,
+ String version, Context context, String[] welcomeResources,
+ WebResourceRoot resources, Collection<WrapperMappingInfo> wrappers) {
MappedHost mappedHost = exactFind(hosts, hostName);
if (mappedHost == null) {
@@ -236,6 +257,9 @@ public final class Mapper {
synchronized (mappedHost) {
ContextVersion newContextVersion = new ContextVersion(version,
path, slashCount, context, resources, welcomeResources);
+ if (wrappers != null) {
+ addWrappers(newContextVersion, wrappers);
+ }
ContextList contextList = mappedHost.contextList;
MappedContext mappedContext = exactFind(contextList.contexts, path);
@@ -304,28 +328,70 @@ public final class Mapper {
}
- public void addWrapper(String hostName, String contextPath, String version,
- String path, Wrapper wrapper, boolean jspWildCard,
- boolean resourceOnly) {
+ private ContextVersion findContextVersion(String hostName,
+ String contextPath, String version, boolean silent) {
MappedHost host = exactFind(hosts, hostName);
if (host == null) {
- return;
+ if (!silent) {
+ log.error("No host found: " + hostName);
+ }
+ return null;
}
MappedContext context = exactFind(host.contextList.contexts,
contextPath);
if (context == null) {
- log.error("No context found: " + contextPath );
- return;
+ if (!silent) {
+ log.error("No context found: " + contextPath);
+ }
+ return null;
}
ContextVersion contextVersion = exactFind(context.versions, version);
if (contextVersion == null) {
- log.error("No context version found: " + contextPath + " " +
- version);
+ if (!silent) {
+ log.error("No context version found: " + contextPath + " "
+ + version);
+ }
+ return null;
+ }
+ return contextVersion;
+ }
+
+
+ public void addWrapper(String hostName, String contextPath, String version,
+ String path, Wrapper wrapper, boolean jspWildCard,
+ boolean resourceOnly) {
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, false);
+ if (contextVersion == null) {
return;
}
addWrapper(contextVersion, path, wrapper, jspWildCard, resourceOnly);
}
+ public void addWrappers(String hostName, String contextPath,
+ String version, Collection<WrapperMappingInfo> wrappers) {
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, false);
+ if (contextVersion == null) {
+ return;
+ }
+ addWrappers(contextVersion, wrappers);
+ }
+
+ /**
+ * Adds wrappers to the given context.
+ *
+ * @param contextVersion The context to which to add the wrappers
+ * @param wrappers Information on wrapper mappings
+ */
+ private void addWrappers(ContextVersion contextVersion,
+ Collection<WrapperMappingInfo> wrappers) {
+ for (WrapperMappingInfo wrapper : wrappers) {
+ addWrapper(contextVersion, wrapper.getMapping(),
+ wrapper.getWrapper(), wrapper.isJspWildCard(),
+ wrapper.isResourceOnly());
+ }
+ }
/**
* Adds a wrapper to the given context.
@@ -334,9 +400,9 @@ public final class Mapper {
* @param path Wrapper mapping
* @param wrapper The Wrapper object
* @param jspWildCard true if the wrapper corresponds to the JspServlet
+ * and the mapping path contains a wildcard; false otherwise
* @param resourceOnly true if this wrapper always expects a physical
* resource to be present (such as a JSP)
- * and the mapping path contains a wildcard; false otherwise
*/
protected void addWrapper(ContextVersion context, String path,
Wrapper wrapper, boolean jspWildCard, boolean resourceOnly) {
@@ -403,16 +469,8 @@ public final class Mapper {
*/
public void removeWrapper(String hostName, String contextPath,
String version, String path) {
- MappedHost host = exactFind(hosts, hostName);
- if (host == null) {
- return;
- }
- MappedContext context = exactFind(host.contextList.contexts,
- contextPath);
- if (context == null) {
- return;
- }
- ContextVersion contextVersion = exactFind(context.versions, version);
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, true);
if (contextVersion == null) {
return;
}
@@ -494,20 +552,9 @@ public final class Mapper {
*/
public void addWelcomeFile(String hostName, String contextPath,
String version, String welcomeFile) {
- MappedHost host = exactFind(hosts, hostName);
- if (host == null) {
- return;
- }
- MappedContext context = exactFind(host.contextList.contexts,
- contextPath);
- if (context == null) {
- log.error("No context found: " + contextPath);
- return;
- }
- ContextVersion contextVersion = exactFind(context.versions, version);
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, false);
if (contextVersion == null) {
- log.error("No context version found: " + contextPath + " "
- + version);
return;
}
int len = contextVersion.welcomeResources.length + 1;
@@ -527,20 +574,9 @@ public final class Mapper {
*/
public void removeWelcomeFile(String hostName, String contextPath,
String version, String welcomeFile) {
- MappedHost host = exactFind(hosts, hostName);
- if (host == null) {
- return;
- }
- MappedContext context = exactFind(host.contextList.contexts,
- contextPath);
- if (context == null) {
- log.error("No context found: " + contextPath);
- return;
- }
- ContextVersion contextVersion = exactFind(context.versions, version);
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, false);
if (contextVersion == null) {
- log.error("No context version found: " + contextPath + " "
- + version);
return;
}
int match = -1;
@@ -571,20 +607,9 @@ public final class Mapper {
*/
public void clearWelcomeFiles(String hostName, String contextPath,
String version) {
- MappedHost host = exactFind(hosts, hostName);
- if (host == null) {
- return;
- }
- MappedContext context = exactFind(host.contextList.contexts,
- contextPath);
- if (context == null) {
- log.error("No context found: " + contextPath);
- return;
- }
- ContextVersion contextVersion = exactFind(context.versions, version);
+ ContextVersion contextVersion = findContextVersion(hostName,
+ contextPath, version, false);
if (contextVersion == null) {
- log.error("No context version found: " + contextPath + " "
- + version);
return;
}
contextVersion.welcomeResources = new String[0];
Modified: tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java?rev=1606714&r1=1606713&r2=1606714&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java (original)
+++ tomcat/trunk/java/org/apache/catalina/mapper/MapperListener.java Mon Jun 30 12:37:38 2014
@@ -16,6 +16,9 @@
*/
package org.apache.catalina.mapper;
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.catalina.Container;
import org.apache.catalina.ContainerEvent;
import org.apache.catalina.ContainerListener;
@@ -319,13 +322,14 @@ public class MapperListener extends Life
*/
private void unregisterWrapper(Wrapper wrapper) {
- String contextPath = ((Context) wrapper.getParent()).getPath();
+ Context context = ((Context) wrapper.getParent());
+ String contextPath = context.getPath();
String wrapperName = wrapper.getName();
if ("/".equals(contextPath)) {
contextPath = "";
}
- String version = ((Context) wrapper.getParent()).getWebappVersion();
+ String version = context.getWebappVersion();
String hostName = wrapper.getParent().getParent().getName();
String[] mappings = wrapper.findMappings();
@@ -354,14 +358,21 @@ public class MapperListener extends Life
WebResourceRoot resources = context.getResources();
String[] welcomeFiles = context.findWelcomeFiles();
-
- mapper.addContextVersion(host.getName(), host, contextPath,
- context.getWebappVersion(), context, welcomeFiles, resources);
+ List<WrapperMappingInfo> wrappers = new ArrayList<>();
for (Container container : context.findChildren()) {
- registerWrapper((Wrapper) container);
+ prepareWrapperMappingInfo(context, (Wrapper) container, wrappers);
+
+ if(log.isDebugEnabled()) {
+ log.debug(sm.getString("mapperListener.registerWrapper",
+ container.getName(), contextPath, service));
+ }
}
+ mapper.addContextVersion(host.getName(), host, contextPath,
+ context.getWebappVersion(), context, welcomeFiles, resources,
+ wrappers);
+
if(log.isDebugEnabled()) {
log.debug(sm.getString("mapperListener.registerContext",
contextPath, service));
@@ -400,7 +411,6 @@ public class MapperListener extends Life
*/
private void registerWrapper(Wrapper wrapper) {
- String wrapperName = wrapper.getName();
Context context = (Context) wrapper.getParent();
String contextPath = context.getPath();
if ("/".equals(contextPath)) {
@@ -409,19 +419,34 @@ public class MapperListener extends Life
String version = context.getWebappVersion();
String hostName = context.getParent().getName();
- String[] mappings = wrapper.findMappings();
+ List<WrapperMappingInfo> wrappers = new ArrayList<>();
+ prepareWrapperMappingInfo(context, wrapper, wrappers);
+ mapper.addWrappers(hostName, contextPath, version, wrappers);
+ if(log.isDebugEnabled()) {
+ log.debug(sm.getString("mapperListener.registerWrapper",
+ wrapper.getName(), contextPath, service));
+ }
+ }
+
+ /**
+ * Populate <code>wrappers</code> list with information for registration of
+ * mappings for this wrapper in this context.
+ *
+ * @param context
+ * @param wrapper
+ * @param list
+ */
+ private void prepareWrapperMappingInfo(Context context, Wrapper wrapper,
+ List<WrapperMappingInfo> wrappers) {
+ String wrapperName = wrapper.getName();
+ boolean resourceOnly = context.isResourceOnlyServlet(wrapperName);
+ String[] mappings = wrapper.findMappings();
for (String mapping : mappings) {
boolean jspWildCard = (wrapperName.equals("jsp")
&& mapping.endsWith("/*"));
- mapper.addWrapper(hostName, contextPath, version, mapping, wrapper,
- jspWildCard,
- context.isResourceOnlyServlet(wrapperName));
- }
-
- if(log.isDebugEnabled()) {
- log.debug(sm.getString("mapperListener.registerWrapper",
- wrapperName, contextPath, service));
+ wrappers.add(new WrapperMappingInfo(mapping, wrapper, jspWildCard,
+ resourceOnly));
}
}
Added: tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java?rev=1606714&view=auto
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java (added)
+++ tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java Mon Jun 30 12:37:38 2014
@@ -0,0 +1,55 @@
+/*
+ * 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.mapper;
+
+import org.apache.catalina.Wrapper;
+
+/**
+ * Encapsulates information used to register a Wrapper mapping.
+ */
+public class WrapperMappingInfo {
+
+ private final String mapping;
+ private final Wrapper wrapper;
+ private final boolean jspWildCard;
+ private final boolean resourceOnly;
+
+ public WrapperMappingInfo(String mapping, Wrapper wrapper,
+ boolean jspWildCard, boolean resourceOnly) {
+ this.mapping = mapping;
+ this.wrapper = wrapper;
+ this.jspWildCard = jspWildCard;
+ this.resourceOnly = resourceOnly;
+ }
+
+ public String getMapping() {
+ return mapping;
+ }
+
+ public Wrapper getWrapper() {
+ return wrapper;
+ }
+
+ public boolean isJspWildCard() {
+ return jspWildCard;
+ }
+
+ public boolean isResourceOnly() {
+ return resourceOnly;
+ }
+
+}
Propchange: tomcat/trunk/java/org/apache/catalina/mapper/WrapperMappingInfo.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java?rev=1606714&r1=1606713&r2=1606714&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java (original)
+++ tomcat/trunk/test/org/apache/catalina/mapper/TestMapper.java Mon Jun 30 12:37:38 2014
@@ -16,6 +16,7 @@
*/
package org.apache.catalina.mapper;
+import java.util.Arrays;
import java.util.HashMap;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -95,30 +96,39 @@ public class TestMapper extends LoggingB
Host host = createHost("blah7");
mapper.addContextVersion("iowejoiejfoiew", host, "",
- "0", createContext("context0"), new String[0], null);
+ "0", createContext("context0"), new String[0], null, null);
mapper.addContextVersion("iowejoiejfoiew", host, "/foo",
- "0", createContext("context1"), new String[0], null);
+ "0", createContext("context1"), new String[0], null, null);
mapper.addContextVersion("iowejoiejfoiew", host, "/foo/bar",
- "0", createContext("context2"), welcomes, null);
- mapper.addContextVersion("iowejoiejfoiew", host, "/foo/bar/bla",
- "0", createContext("context3"), new String[0], null);
-
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "/fo/*",
- createWrapper("wrapper0"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "/",
- createWrapper("wrapper1"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "/blh",
- createWrapper("wrapper2"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "*.jsp",
- createWrapper("wrapper3"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "/blah/bou/*",
- createWrapper("wrapper4"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "/blah/bobou/*",
- createWrapper("wrapper5"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar", "0", "*.htm",
- createWrapper("wrapper6"), false, false);
- mapper.addWrapper("iowejoiejfoiew", "/foo/bar/bla", "0", "/bobou/*",
- createWrapper("wrapper7"), false, false);
+ "0", createContext("context2"), welcomes, null, null);
+
+ mapper.addWrappers("iowejoiejfoiew", "/foo/bar", "0", Arrays
+ .asList(new WrapperMappingInfo[] {
+ new WrapperMappingInfo("/fo/*",
+ createWrapper("wrapper0"), false, false),
+ new WrapperMappingInfo("/", createWrapper("wrapper1"),
+ false, false),
+ new WrapperMappingInfo("/blh",
+ createWrapper("wrapper2"), false, false),
+ new WrapperMappingInfo("*.jsp",
+ createWrapper("wrapper3"), false, false),
+ new WrapperMappingInfo("/blah/bou/*",
+ createWrapper("wrapper4"), false, false),
+ new WrapperMappingInfo("/blah/bobou/*",
+ createWrapper("wrapper5"), false, false),
+ new WrapperMappingInfo("*.htm",
+ createWrapper("wrapper6"), false, false) }));
+
+ mapper.addContextVersion(
+ "iowejoiejfoiew",
+ host,
+ "/foo/bar/bla",
+ "0",
+ createContext("context3"),
+ new String[0],
+ null,
+ Arrays.asList(new WrapperMappingInfo[] { new WrapperMappingInfo(
+ "/bobou/*", createWrapper("wrapper7"), false, false) }));
}
@Test
@@ -259,15 +269,15 @@ public class TestMapper extends LoggingB
mapper.setDefaultHostName("localhost");
mapper.addContextVersion("localhost", host, "", "0", contextRoot,
- new String[0], null);
+ new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo", "0", context1,
- new String[0], null);
+ new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar", "0", context2,
- new String[0], null);
+ new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar/bla", "0",
- context3, new String[0], null);
+ context3, new String[0], null, null);
mapper.addContextVersion("localhost", host, "/foo/bar/bla/baz", "0",
- context4, new String[0], null);
+ context4, new String[0], null, null);
final AtomicBoolean running = new AtomicBoolean(true);
Thread t = new Thread() {
@@ -278,7 +288,7 @@ public class TestMapper extends LoggingB
"/foo/bar/bla/baz", "0");
mapper.addContextVersion("localhost", host,
"/foo/bar/bla/baz", "0", context4, new String[0],
- null);
+ null, null);
}
running.set(false);
}
Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1606714&r1=1606713&r2=1606714&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Jun 30 12:37:38 2014
@@ -77,10 +77,14 @@
work in <code>Mapper</code>. (kkolinko)
</fix>
<scode>
- Remove <code>context</code> and <code>wrapper</code> fields and
- deprecate their setters in <code>Request</code> class. (kkolinko)
+ Remove <code>context</code> and <code>wrapper</code> fields in
+ <code>Request</code> class and deprecate their setters. (kkolinko)
</scode>
<fix>
+ <bug>56658</bug>: Avoid delay between registrations of mappings for
+ context and for its servlets. (kkolinko)
+ </fix>
+ <fix>
<bug>56665</bug>: Correct the generation of the effective web.xml when
elements contain an empty string as value. (violetagg)
</fix>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org