You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-dev@jakarta.apache.org by vm...@apache.org on 2001/12/15 23:48:54 UTC
cvs commit: jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit TestServletTestCase2.java
vmassol 01/12/15 14:48:54
Modified: docs/framework/xdocs changes.xml
src/framework/share/org/apache/cactus/server
AbstractHttpServletRequestWrapper.java
src/sample/share/org/apache/cactus/sample/unit
TestServletTestCase2.java
Log:
Corrected bug in AbstractHttpServletRequestWrapper.getPathTranslated(), which was not returning null when getRealPath("/") was returning null. It is allowed by the spec. to return null upon certain conditions (see section SRV.4.5 of the Servlet 2.3 spec.).
Revision Changes Path
1.70 +8 -0 jakarta-cactus/docs/framework/xdocs/changes.xml
Index: changes.xml
===================================================================
RCS file: /home/cvs/jakarta-cactus/docs/framework/xdocs/changes.xml,v
retrieving revision 1.69
retrieving revision 1.70
diff -u -r1.69 -r1.70
--- changes.xml 2001/12/15 20:52:36 1.69
+++ changes.xml 2001/12/15 22:48:54 1.70
@@ -127,6 +127,14 @@
</devs>
<release version="1.3 in CVS">
+ <action dev="VMA" type="fix">
+ Corrected bug in
+ <code>AbstractHttpServletRequestWrapper.getPathTranslated()</code> which
+ was not returning <code>null</code> when <code>getRealPath("/")</code>
+ was returning <code>null</code>. It is allowed by the spec. to return
+ <code>null</code> upon certain conditions (see section SRV.4.5 of the
+ Servlet 2.3 spec.).
+ </action>
<action dev="VMA" type="add" due-to="Jim Young" due-to-email="Jim.Young@cibc.com">
Add a tutorial for setting up Cactus in VAJava with Tomcat environment.
</action>
1.4 +18 -9 jakarta-cactus/src/framework/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java
Index: AbstractHttpServletRequestWrapper.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/src/framework/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractHttpServletRequestWrapper.java 2001/11/16 19:19:27 1.3
+++ AbstractHttpServletRequestWrapper.java 2001/12/15 22:48:54 1.4
@@ -68,7 +68,7 @@
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
- * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.3 2001/11/16 19:19:27 vmassol Exp $
+ * @version $Id: AbstractHttpServletRequestWrapper.java,v 1.4 2001/12/15 22:48:54 vmassol Exp $
*/
public abstract class AbstractHttpServletRequestWrapper implements HttpServletRequest
{
@@ -231,15 +231,24 @@
String pathInfo = this.url.getPathInfo();
if (pathInfo != null) {
- String newPathInfo = (pathInfo.startsWith("/") ?
- pathInfo.substring(1) : pathInfo);
- if (this.request.getRealPath("/").endsWith("/")) {
- pathTranslated = this.request.getRealPath("/") +
- newPathInfo.replace('/', File.separatorChar);
+
+ // If getRealPath returns null then getPathTranslated should also
+ // return null (see section SRV.4.5 of the Servlet 2.3 spec).
+ if (this.request.getRealPath("/") == null) {
+ pathTranslated = null;
} else {
- pathTranslated = this.request.getRealPath("/") +
- File.separatorChar + newPathInfo.replace('/',
- File.separatorChar);
+
+ // Compute the translated path using the root real path
+ String newPathInfo = (pathInfo.startsWith("/") ?
+ pathInfo.substring(1) : pathInfo);
+ if (this.request.getRealPath("/").endsWith("/")) {
+ pathTranslated = this.request.getRealPath("/") +
+ newPathInfo.replace('/', File.separatorChar);
+ } else {
+ pathTranslated = this.request.getRealPath("/") +
+ File.separatorChar + newPathInfo.replace('/',
+ File.separatorChar);
+ }
}
} else {
pathTranslated = this.request.getPathTranslated();
1.21 +15 -6 jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java
Index: TestServletTestCase2.java
===================================================================
RCS file: /home/cvs/jakarta-cactus/src/sample/share/org/apache/cactus/sample/unit/TestServletTestCase2.java,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- TestServletTestCase2.java 2001/10/20 13:22:11 1.20
+++ TestServletTestCase2.java 2001/12/15 22:48:54 1.21
@@ -77,7 +77,7 @@
*
* @author <a href="mailto:vmassol@apache.org">Vincent Massol</a>
*
- * @version $Id: TestServletTestCase2.java,v 1.20 2001/10/20 13:22:11 vmassol Exp $
+ * @version $Id: TestServletTestCase2.java,v 1.21 2001/12/15 22:48:54 vmassol Exp $
*/
public class TestServletTestCase2 extends ServletTestCase
{
@@ -571,7 +571,11 @@
/**
* Verify that <code>HttpServletRequestWrapper.getPathTranslated()</code>
- * takes into account the simulated URL (if any).
+ * takes into account the simulated URL (if any) or null in situations
+ * where the servlet container cannot determine a valid file path for
+ * these methods, such as when the web application is executed from an
+ * archive, on a remote file system not accessible locally, or in a
+ * database (see section SRV.4.5 of the Servlet 2.3 spec).
*/
public void testGetPathTranslated()
{
@@ -580,10 +584,15 @@
String pathTranslated = request.getPathTranslated();
- assertNotNull("Should not be null", pathTranslated);
- assert("Should end with [" + nativePathInfo + "] but got [" +
- pathTranslated + "] instead",
- pathTranslated.endsWith(nativePathInfo));
+ // Should be null if getRealPath("/") is null
+ if (request.getRealPath("/") == null) {
+ assertNull("Should have been null", pathTranslated);
+ } else {
+ assertNotNull("Should not be null", pathTranslated);
+ assert("Should end with [" + nativePathInfo + "] but got [" +
+ pathTranslated + "] instead",
+ pathTranslated.endsWith(nativePathInfo));
+ }
}
//-------------------------------------------------------------------------
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>