[Httpunit-commit] CVS: httpunit/src/com/meterware/servletunit ServletUnitContext.java,1.4,1.5 Servle
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-03-17 01:35:50
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv23842/src/com/meterware/servletunit
Modified Files:
ServletUnitContext.java ServletUnitHttpRequest.java
Log Message:
Added support for HttpServletRequest.getRequestDispatcher()
Index: ServletUnitContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitContext.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- ServletUnitContext.java 16 Mar 2003 14:14:39 -0000 1.4
+++ ServletUnitContext.java 17 Mar 2003 01:35:44 -0000 1.5
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -30,9 +30,10 @@
this( null );
}
- ServletUnitContext(String contextPath) {
+ ServletUnitContext( String contextPath ) {
_contextPath = (contextPath != null ? contextPath : "");
}
+
Set getSessionIDs() {
return _sessions.keySet();
Index: ServletUnitHttpRequest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpRequest.java,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -r1.24 -r1.25
--- ServletUnitHttpRequest.java 13 Feb 2003 20:25:56 -0000 1.24
+++ ServletUnitHttpRequest.java 17 Mar 2003 01:35:44 -0000 1.25
@@ -35,6 +35,7 @@
import javax.servlet.http.HttpSession;
import javax.servlet.ServletInputStream;
import javax.servlet.RequestDispatcher;
+import javax.servlet.ServletException;
/**
@@ -560,7 +561,18 @@
* is that this method can take a relative path.
**/
public RequestDispatcher getRequestDispatcher( String path ) {
- throw new RuntimeException( "getRequestDispatcher not implemented" );
+ try {
+ if (!path.startsWith( "/" )) path = combinedPath( getServletPath(), path );
+ return _servletRequest.getServlet().getServletConfig().getServletContext().getRequestDispatcher( path );
+ } catch (ServletException e) {
+ return null;
+ }
+ }
+
+
+ private String combinedPath( String basePath, String relativePath ) {
+ if (basePath.indexOf( '/' ) < 0) return relativePath;
+ return basePath.substring( 0, basePath.lastIndexOf( '/' ) ) + '/' + relativePath;
}
@@ -725,7 +737,7 @@
final static private String LOOPBACK_ADDRESS = "127.0.0.1";
private WebRequest _request;
- private ServletMetaData _servletRequest;
+ private ServletMetaData _servletRequest;
private WebClient.HeaderDictionary _headers;
private ServletUnitContext _context;
private ServletUnitHttpSession _session;
|