You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by re...@apache.org on 2003/05/19 23:54:08 UTC
cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core ApplicationContext.java LocalStrings.properties StandardContext.java
remm 2003/05/19 14:54:08
Modified: catalina/src/share/org/apache/catalina/core
ApplicationContext.java LocalStrings.properties
StandardContext.java
Log:
- Swicth to the "new" mapper for request dispatching. The host mapping is
copied over for cross context support (I don't see any need to optimize this).
If I broke stuff, sorry. Let me know.
Revision Changes Path
1.11 +78 -28 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContext.java
Index: ApplicationContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationContext.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- ApplicationContext.java 26 Mar 2003 18:21:50 -0000 1.10
+++ ApplicationContext.java 19 May 2003 21:54:07 -0000 1.11
@@ -101,6 +101,12 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+
+import org.apache.tomcat.util.buf.CharChunk;
+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.naming.resources.Resource;
import org.apache.naming.resources.DirContextURLStreamHandler;
import org.apache.naming.resources.DirContextURLConnection;
@@ -202,6 +208,18 @@
private String basePath = null;
+ /**
+ * Thread local mapping data.
+ */
+ private ThreadLocal localMappingData = new ThreadLocal();
+
+
+ /**
+ * Thread local URI message bytes.
+ */
+ private ThreadLocal localUriMB = new ThreadLocal();
+
+
// --------------------------------------------------------- Public Methods
@@ -277,7 +295,20 @@
return (null);
try {
Host host = (Host) context.getParent();
- Context child = host.map(uri);
+ Context child = null;
+ String mapuri = uri;
+ while (true) {
+ child = (Context) host.findChild(mapuri);
+ if (context != null)
+ break;
+ int slash = mapuri.lastIndexOf('/');
+ if (slash < 0)
+ break;
+ mapuri = mapuri.substring(0, slash);
+ }
+ if (child == null) {
+ child = (Context) host.findChild("");
+ }
if (child != null)
return (child.getServletContext());
else
@@ -416,38 +447,57 @@
return (null);
if (!path.startsWith("/"))
throw new IllegalArgumentException
- (sm.getString("applicationContext.requestDispatcher.iae", path));
+ (sm.getString
+ ("applicationContext.requestDispatcher.iae", path));
path = normalize(path);
if (path == null)
return (null);
- // Construct a "fake" request to be mapped by our Context
- String contextPath = context.getPath();
- if (contextPath == null)
- contextPath = "";
- String relativeURI = path;
+ // Retrieve the thread local URI
+ MessageBytes uriMB = (MessageBytes) localUriMB.get();
+ if (uriMB == null) {
+ uriMB = new MessageBytes();
+ CharChunk uriCC = uriMB.getCharChunk();
+ uriCC.setLimit(-1);
+ localUriMB.set(uriMB);
+ } else {
+ uriMB.recycle();
+ }
String queryString = null;
- int question = path.indexOf('?');
- if (question >= 0) {
- relativeURI = path.substring(0, question);
- queryString = path.substring(question + 1);
+ int pos = path.indexOf('?');
+ if (pos >= 0) {
+ queryString = path.substring(pos + 1);
+ } else {
+ pos = path.length();
}
- // The remaining code is duplicated in PrivilegedGetRequestDispatcher,
- // we need to make sure they stay in sync
- HttpRequest request = new DummyRequest
- (context.getPath(), contextPath + relativeURI, queryString);
- Wrapper wrapper = (Wrapper) context.map(request, true);
- if (wrapper == null)
+
+ // Retrieve the thread local mapping data
+ MappingData mappingData = (MappingData) localMappingData.get();
+ if (mappingData == null) {
+ mappingData = new MappingData();
+ localMappingData.set(mappingData);
+ } else {
+ mappingData.recycle();
+ }
+
+ // Map the URI
+ try {
+ CharChunk uriCC = uriMB.getCharChunk();
+ uriCC.append(path, 0, pos);
+ context.getMapper().map(uriMB, mappingData);
+ if (mappingData.wrapper == null) {
+ return (null);
+ }
+ } catch (Exception e) {
+ // Should never happen
+ log(sm.getString("applicationContext.mapping.error"), e);
return (null);
+ }
// Construct a RequestDispatcher to process this request
- HttpServletRequest hrequest =
- (HttpServletRequest) request.getRequest();
- return (RequestDispatcher) new ApplicationDispatcher(wrapper,
- hrequest.getServletPath(),
- hrequest.getPathInfo(),
- hrequest.getQueryString(),
- null);
+ return (RequestDispatcher) new ApplicationDispatcher
+ ((Wrapper) mappingData.wrapper, mappingData.wrapperPath.toString(),
+ mappingData.pathInfo.toString(), queryString, null);
}
1.6 +1 -0 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/LocalStrings.properties
Index: LocalStrings.properties
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/LocalStrings.properties,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- LocalStrings.properties 24 Jan 2003 23:47:45 -0000 1.5
+++ LocalStrings.properties 19 May 2003 21:54:08 -0000 1.6
@@ -1,4 +1,5 @@
applicationContext.attributeEvent=Exception thrown by attributes event listener
+applicationContext.mapping.error=Error during mapping
applicationContext.requestDispatcher.iae=Path {0} does not start with a "/" character
applicationContext.setAttribute.namenull=Name cannot be null
applicationDispatcher.allocateException=Allocate exception for servlet {0}
1.53 +65 -3 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java
Index: StandardContext.java
===================================================================
RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/StandardContext.java,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -r1.52 -r1.53
--- StandardContext.java 15 May 2003 20:49:05 -0000 1.52
+++ StandardContext.java 19 May 2003 21:54:08 -0000 1.53
@@ -161,6 +161,8 @@
// ----------------------------------------------------- Instance Variables
+
+
/**
* The alternate deployment descriptor name.
*/
@@ -330,6 +332,13 @@
/**
+ * The mapper associated with this context.
+ */
+ private org.apache.tomcat.util.http.mapper.Mapper mapper =
+ new org.apache.tomcat.util.http.mapper.Mapper();
+
+
+ /**
* The naming context listener for this web application.
*/
private transient NamingContextListener namingContextListener = null;
@@ -1032,6 +1041,14 @@
/**
+ * Get the mapper associated with the context.
+ */
+ public org.apache.tomcat.util.http.mapper.Mapper getMapper() {
+ return (mapper);
+ }
+
+
+ /**
* Return the naming resources associated with this web application.
*/
public NamingResources getNamingResources() {
@@ -1520,7 +1537,8 @@
String jspFile = wrapper.getJspFile();
if ((jspFile != null) && !jspFile.startsWith("/")) {
if (isServlet22()) {
- log.debug(sm.getString("standardContext.wrapper.warning", jspFile));
+ log.debug(sm.getString("standardContext.wrapper.warning",
+ jspFile));
wrapper.setJspFile("/" + jspFile);
} else {
throw new IllegalArgumentException
@@ -3013,6 +3031,26 @@
/**
+ * Add a child Container, only if the proposed child is an implementation
+ * of Wrapper.
+ *
+ * @param child Child container to be added
+ *
+ * @exception IllegalArgumentException if the proposed container is
+ * not an implementation of Wrapper
+ */
+ public void removeChild(Container child) {
+
+ if (!(child instanceof Wrapper))
+ throw new IllegalArgumentException
+ (sm.getString("standardContext.notWrapper"));
+
+ super.removeChild(child);
+
+ }
+
+
+ /**
* Remove the specified security constraint from this web application.
*
* @param constraint Constraint to be removed
@@ -4039,12 +4077,16 @@
((Lifecycle) resources).start();
// Start our Mappers, if any
+ // FIXME: Remove this
Mapper mappers[] = findMappers();
for (int i = 0; i < mappers.length; i++) {
if (mappers[i] instanceof Lifecycle)
((Lifecycle) mappers[i]).start();
}
+ // Initialize associated mapper
+ mapper.setContext(welcomeFiles, resources);
+
// Start our child containers, if any
Container children[] = findChildren();
for (int i = 0; i < children.length; i++) {
@@ -4070,6 +4112,16 @@
// Notify our interested LifecycleListeners
lifecycle.fireLifecycleEvent(START_EVENT, null);
+ children = findChildren();
+ for (int i = 0; i < children.length; i++) {
+ // Updating associated mapper
+ Wrapper wrapper = (Wrapper) children[i];
+ String[] mappings = wrapper.findMappings();
+ for (int j = 0; j < mappings.length; j++) {
+ mapper.addWrapper(mappings[j], wrapper);
+ }
+ }
+
if ((manager != null) && (manager instanceof Lifecycle)) {
((Lifecycle) manager).start();
}
@@ -4243,6 +4295,16 @@
((Lifecycle) manager).stop();
}
+ // Updating associated mapper
+ Container children[] = findChildren();
+ for (int i = 0; i < children.length; i++) {
+ Wrapper wrapper = (Wrapper) children[i];
+ String[] mappings = wrapper.findMappings();
+ for (int j = 0; j < mappings.length; j++) {
+ mapper.removeWrapper(mappings[j]);
+ }
+ }
+
// Normal container shutdown processing
if (log.isDebugEnabled())
log.debug("Processing standard container shutdown");
@@ -4258,7 +4320,7 @@
}
// Stop our child containers, if any
- Container children[] = findChildren();
+ children = findChildren();
for (int i = 0; i < children.length; i++) {
if (children[i] instanceof Lifecycle)
((Lifecycle) children[i]).stop();
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core
ApplicationContext.java LocalStrings.properties StandardContext.java
Posted by Remy Maucherat <re...@apache.org>.
Bill Barker wrote:
>>remm 2003/05/19 14:54:08
>>
>> Modified: catalina/src/share/org/apache/catalina/core
>> ApplicationContext.java LocalStrings.properties
>> StandardContext.java
>> Log:
>> - Swicth to the "new" mapper for request dispatching. The host mapping
>
> is
>
>> copied over for cross context support (I don't see any need to
>
> optimize this).
>
>> If I broke stuff, sorry. Let me know.
>>
>> Revision Changes Path
>> 1.11 +78 -28
>
> jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/Applicat
> ionContext.java
>
>> Index: ApplicationContext.java
>> > + /**
>> + * Thread local mapping data.
>> + */
>> + private ThreadLocal localMappingData = new ThreadLocal();
>> +
>> +
>> + /**
>> + * Thread local URI message bytes.
>> + */
>> + private ThreadLocal localUriMB = new ThreadLocal();
>> +
>> +
>
>
> Wouldn't make more sense to have these as Request notes? Especially with
> the HTTP/1.1 Connector, the threads are short-lived but the Request gets
> reused.
I'm not sure I get the short lived argument. Anyway, the idea is that
the request is wrapped as soon you go into a dispatcher (well, I guess
you can retrieve the one where there's the note by using getRequest and
getResponse), so that's why I didn't use a note. It's not too hard to
change that.
Remy
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org
Re: cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core ApplicationContext.java LocalStrings.properties StandardContext.java
Posted by Bill Barker <wb...@wilshire.com>.
----- Original Message -----
From: <re...@apache.org>
To: <ja...@apache.org>
Sent: Monday, May 19, 2003 2:54 PM
Subject: cvs commit:
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core
ApplicationContext.java LocalStrings.properties StandardContext.java
> remm 2003/05/19 14:54:08
>
> Modified: catalina/src/share/org/apache/catalina/core
> ApplicationContext.java LocalStrings.properties
> StandardContext.java
> Log:
> - Swicth to the "new" mapper for request dispatching. The host mapping
is
> copied over for cross context support (I don't see any need to
optimize this).
> If I broke stuff, sorry. Let me know.
>
> Revision Changes Path
> 1.11 +78 -28
jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/Applicat
ionContext.java
>
> Index: ApplicationContext.java
> > + /**
> + * Thread local mapping data.
> + */
> + private ThreadLocal localMappingData = new ThreadLocal();
> +
> +
> + /**
> + * Thread local URI message bytes.
> + */
> + private ThreadLocal localUriMB = new ThreadLocal();
> +
> +
Wouldn't make more sense to have these as Request notes? Especially with
the HTTP/1.1 Connector, the threads are short-lived but the Request gets
reused.
---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org