remm 2003/08/05 06:22:03 Modified: catalina/src/share/org/apache/catalina/core ApplicationContext.java ApplicationDispatcher.java ApplicationHttpRequest.java Log: - Fix for three related bugs. - Bug 22013: The wrapped request must actually override getRequestDispatcher. Thanks to Stephane Riviere for the test case. - Bug 4690: Fix for cross context sessions scoping (previously, the visible session would be the one from the context which first recieved the request). - Fix ServletContext.getContext(...) when using the root context. (but the spec should really be modified so that it says that only exact matches of the target context are allowed). Revision Changes Path 1.14 +7 -5 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.13 retrieving revision 1.14 diff -u -r1.13 -r1.14 --- ApplicationContext.java 12 Jun 2003 22:06:30 -0000 1.13 +++ ApplicationContext.java 5 Aug 2003 13:22:03 -0000 1.14 @@ -286,7 +286,9 @@ String contextPath = context.getPath(); if (!contextPath.endsWith("/")) contextPath = contextPath + "/"; - if ((contextPath.length() > 0) && (uri.startsWith(contextPath))) { + if ((contextPath.length() > 1) && + ((uri.equals(context.getPath())) + || (uri.startsWith(contextPath)))) { return (this); } 1.22 +13 -7 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java Index: ApplicationDispatcher.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationDispatcher.java,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- ApplicationDispatcher.java 23 Jul 2003 07:51:33 -0000 1.21 +++ ApplicationDispatcher.java 5 Aug 2003 13:22:03 -0000 1.22 @@ -996,10 +996,16 @@ ServletRequest wrapper = null; if ((current instanceof ApplicationHttpRequest) || (current instanceof HttpRequest) || - (current instanceof HttpServletRequest)) - wrapper = new ApplicationHttpRequest((HttpServletRequest) current); - else + (current instanceof HttpServletRequest)) { + // Compute a crossContext flag + HttpServletRequest hcurrent = (HttpServletRequest) current; + boolean crossContext = + !(context.getPath().equals(hcurrent.getContextPath())); + wrapper = new ApplicationHttpRequest + (hcurrent, context, crossContext); + } else { wrapper = new ApplicationRequest(current); + } if (previous == null) outerRequest = wrapper; else 1.11 +128 -5 jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java Index: ApplicationHttpRequest.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/core/ApplicationHttpRequest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- ApplicationHttpRequest.java 25 Jun 2003 19:39:09 -0000 1.10 +++ ApplicationHttpRequest.java 5 Aug 2003 13:22:03 -0000 1.11 @@ -72,10 +72,16 @@ import java.util.Iterator; import java.util.Set; import java.util.Map; + +import javax.servlet.RequestDispatcher; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; +import javax.servlet.http.HttpSession; + +import org.apache.catalina.Context; import org.apache.catalina.Globals; import org.apache.catalina.HttpRequest; +import org.apache.catalina.Session; import org.apache.catalina.util.Enumerator; import org.apache.catalina.util.RequestUtil; import org.apache.catalina.util.StringManager; @@ -130,9 +136,12 @@ * * @param request The servlet request being wrapped */ - public ApplicationHttpRequest(HttpServletRequest request) { + public ApplicationHttpRequest(HttpServletRequest request, Context context, + boolean crossContext) { super(request); + this.context = context; + this.crossContext = crossContext; setRequest(request); } @@ -142,12 +151,25 @@ /** + * The context for this request. + */ + protected Context context = null; + + + /** * The context path for this request. */ protected String contextPath = null; /** + * If this request is cross context, since this changes session accesss + * behavior. + */ + protected boolean crossContext = false; + + + /** * The current dispatcher type. */ protected Object dispatcherType = null; @@ -210,6 +232,12 @@ /** + * The currently active session for this request. + */ + protected HttpSession session = null; + + + /** * Special attributes. */ protected Object[] specialAttributes = new Object[specials.length]; @@ -292,6 +320,43 @@ } + /** + * Return a RequestDispatcher that wraps the resource at the specified + * path, which may be interpreted as relative to the current request path. + * + * @param path Path of the resource to be wrapped + */ + public RequestDispatcher getRequestDispatcher(String path) { + + if (context == null) + return (null); + + // If the path is already context-relative, just pass it through + if (path == null) + return (null); + else if (path.startsWith("/")) + return (context.getServletContext().getRequestDispatcher(path)); + + // Convert a request-relative path to a context-relative one + String servletPath = + (String) getAttribute(Globals.INCLUDE_SERVLET_PATH_ATTR); + if (servletPath == null) + servletPath = getServletPath(); + + int pos = servletPath.lastIndexOf('/'); + String relative = null; + if (pos >= 0) { + relative = RequestUtil.normalize + (servletPath.substring(0, pos + 1) + path); + } else { + relative = RequestUtil.normalize(servletPath + path); + } + + return (context.getServletContext().getRequestDispatcher(relative)); + + } + + // --------------------------------------------- HttpServletRequest Methods @@ -423,6 +488,64 @@ public String getServletPath() { return (this.servletPath); + + } + + + /** + * Return the session associated with this Request, creating one + * if necessary. + */ + public HttpSession getSession() { + return (getSession(true)); + } + + + /** + * Return the session associated with this Request, creating one + * if necessary and requested. + * + * @param create Create a new session if one does not exist + */ + public HttpSession getSession(boolean create) { + + if (crossContext) { + + // There cannot be a session if no context has been assigned yet + if (context == null) + return (null); + + // Return the current session if it exists and is valid + if (session != null) + return (session); + + HttpSession other = super.getSession(false); + if (create && (other == null)) { + // First create a session in the first context: the problem is + // that the top level request is the only one which can + // create the cookie safely + other = super.getSession(true); + } + if (other != null) { + Session localSession = null; + try { + localSession = + context.getManager().findSession(other.getId()); + } catch (IOException e) { + // Ignore + } + if (localSession == null) { + localSession = context.getManager().createEmptySession(); + localSession.setId(other.getId()); + } + session = localSession.getSession(); + return session; + } + return null; + + } else { + return super.getSession(create); + } }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]