[Httpunit-commit] CVS: httpunit/src/com/meterware/servletunit RequestDispatcherImpl.java,NONE,1.1 Se
Brought to you by:
russgold
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv15629/src/com/meterware/servletunit
Modified Files:
ServletUnitHttpResponse.java ServletUnitServletConfig.java
ServletUnitServletContext.java WebApplication.java
Added Files:
RequestDispatcherImpl.java
Log Message:
Added initial support for RequestDispatcher
***** Error reading new file[Errno 2] No such file or directory: 'RequestDispatcherImpl.java'
Index: ServletUnitHttpResponse.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitHttpResponse.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- ServletUnitHttpResponse.java 2001/11/14 14:40:31 1.8
+++ ServletUnitHttpResponse.java 2002/01/22 15:25:16 1.9
@@ -405,6 +405,17 @@
//---------------------------------------------- package methods --------------------------------------------------
+ /**
+ * Clears all headers and content.
+ */
+ void restartResponse() {
+ _headers = new Hashtable();
+ _headersComplete = false;
+ _outputStream = null;
+ _servletStream = null;
+ _status = SC_OK;
+ _writer = null;
+ }
/**
* Returns the content type defined for this response.
Index: ServletUnitServletConfig.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletConfig.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ServletUnitServletConfig.java 2001/11/26 14:20:12 1.2
+++ ServletUnitServletConfig.java 2002/01/22 15:25:16 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, 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
@@ -33,14 +33,10 @@
class ServletUnitServletConfig implements ServletConfig {
- ServletUnitServletConfig( Servlet servlet ) {
- this( servlet, NO_PARAMS );
- }
-
-
- ServletUnitServletConfig( Servlet servlet, Hashtable initParams ) {
+ ServletUnitServletConfig( Servlet servlet, WebApplication application, Hashtable initParams ) {
_name = servlet.getClass().getName();
_initParameters = initParams;
+ _context = new ServletUnitServletContext( application );
}
@@ -82,11 +78,9 @@
//----------------------------------------------- private members ------------------------------------------------------
- private final static Hashtable NO_PARAMS = new Hashtable();
-
private String _name;
- private Hashtable _initParameters;
+ private final Hashtable _initParameters;
- private ServletContext _context = new ServletUnitServletContext();
+ private final ServletContext _context;
}
Index: ServletUnitServletContext.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- ServletUnitServletContext.java 2001/11/26 14:20:12 1.5
+++ ServletUnitServletContext.java 2002/01/22 15:25:16 1.6
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2002, 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
@@ -23,6 +23,7 @@
import java.io.IOException;
import java.net.URL;
+import java.net.MalformedURLException;
import java.util.Enumeration;
import java.util.Hashtable;
@@ -38,6 +39,11 @@
**/
class ServletUnitServletContext implements ServletContext {
+ public ServletUnitServletContext( WebApplication application ) {
+ _application = application;
+ }
+
+
/**
* Returns a ServletContext object that corresponds to a specified URL on the server.
* <p>
@@ -48,7 +54,7 @@
* In a security conscious environment, the servlet container may return null for a given URL.
**/
public javax.servlet.ServletContext getContext(java.lang.String A) {
- throw new RuntimeException( "getContext not implemented" );
+ return null;
}
@@ -132,7 +138,13 @@
* RequestDispatcher.
**/
public javax.servlet.RequestDispatcher getRequestDispatcher( String path ) {
- return null; // XXX not implemented
+ try {
+ return new RequestDispatcherImpl( _application.getServlet( new URL( "http", "localhost", path ) ) );
+ } catch (ServletException e) {
+ return null;
+ } catch (MalformedURLException e) {
+ return null;
+ }
}
@@ -317,5 +329,7 @@
//------------------------------------------- private members ----------------------------------------------------
private final static Vector EMPTY_VECTOR = new Vector();
- private Hashtable _attributes = new Hashtable();
+
+ private Hashtable _attributes = new Hashtable();
+ private WebApplication _application;
}
Index: WebApplication.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- WebApplication.java 2002/01/01 19:29:08 1.2
+++ WebApplication.java 2002/01/22 15:25:16 1.3
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
- * Copyright (c) 2001, Russell Gold
+ * Copyright (c) 2001-2002, 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
@@ -98,7 +98,7 @@
if (!Servlet.class.isAssignableFrom( servletClass )) throw new HttpInternalErrorException( url );
Servlet servlet = (Servlet) servletClass.newInstance(); // XXX cache instances - by class?
- servlet.init( new ServletUnitServletConfig( servlet, configuration.getInitParams() ) );
+ servlet.init( new ServletUnitServletConfig( servlet, this, configuration.getInitParams() ) );
return servlet;
} catch (ClassNotFoundException e) {
throw new HttpNotFoundException( url, e );
|