[Httpunit-commit] CVS: httpunit/src/com/meterware/servletunit JSPServletDescriptor.java,NONE,1.1 Inv
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-06-23 23:52:42
|
Update of /cvsroot/httpunit/httpunit/src/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv29969/src/com/meterware/servletunit Modified Files: InvocationContextImpl.java ServletRunner.java ServletUnitClient.java ServletUnitContext.java ServletUnitServletContext.java WebApplication.java Added Files: JSPServletDescriptor.java Log Message: Added support for JSPs ***** Error reading new file[Errno 2] No such file or directory: 'JSPServletDescriptor.java' Index: InvocationContextImpl.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/InvocationContextImpl.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- InvocationContextImpl.java 19 Jun 2002 13:47:19 -0000 1.5 +++ InvocationContextImpl.java 23 Jun 2002 23:52:39 -0000 1.6 @@ -131,7 +131,7 @@ * request, and cookie headers. **/ InvocationContextImpl( ServletRunner runner, WebRequest request, Cookie[] cookies, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { - _application = runner._application; + _application = runner.getApplication(); _requestURL = request.getURL(); _target = request.getTarget(); Index: ServletRunner.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletRunner.java,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ServletRunner.java 21 May 2002 20:43:31 -0000 1.16 +++ ServletRunner.java 23 Jun 2002 23:52:39 -0000 1.17 @@ -25,6 +25,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.util.Dictionary; +import java.util.Hashtable; import javax.servlet.Servlet; import javax.servlet.ServletException; @@ -47,8 +48,8 @@ * Default constructor, which defines no servlets. */ public ServletRunner() { - _context = new ServletUnitContext(); _application = new WebApplication(); + completeInitialization( null ); } /** @@ -58,8 +59,8 @@ * @param webXMLFileSpec the full path to the web.xml file */ public ServletRunner( String webXMLFileSpec ) throws IOException, SAXException { - _context = new ServletUnitContext(); _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ) ); + completeInitialization( null ); } @@ -71,9 +72,9 @@ * @param contextPath the context path */ public ServletRunner( String webXMLFileSpec, String contextPath ) throws IOException, SAXException { - _context = new ServletUnitContext( contextPath ); File webXMLFile = new File( webXMLFileSpec ); - _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ), webXMLFile.getParentFile().getParentFile(), _context.getContextPath() ); + _application = new WebApplication( HttpUnitUtils.newParser().parse( webXMLFileSpec ), webXMLFile.getParentFile().getParentFile(), contextPath ); + completeInitialization( contextPath ); } @@ -81,22 +82,37 @@ * Constructor which expects an input stream containing the web.xml for the application. **/ public ServletRunner( InputStream webXML ) throws IOException, SAXException { - this(webXML, null); + this( webXML, null ); } /** * Constructor which expects an input stream containing the web.xml for the application. **/ public ServletRunner( InputStream webXML, String contextPath ) throws IOException, SAXException { - _context = new ServletUnitContext(contextPath); - _application = new WebApplication( HttpUnitUtils.newParser().parse( new InputSource( webXML ) ), _context.getContextPath()); + _application = new WebApplication( HttpUnitUtils.newParser().parse( new InputSource( webXML ) ), contextPath ); + completeInitialization( contextPath ); } + /** * Registers a servlet class to be run. **/ public void registerServlet( String resourceName, String servletClassName ) { - _application.registerServlet( resourceName, servletClassName ); + _application.registerServlet( resourceName, servletClassName, null ); + } + + + private void completeInitialization( String contextPath ) { + _context = new ServletUnitContext( contextPath ); + _application.registerServlet( "*.jsp", _jspServletDescriptor.getClassName(), _jspServletDescriptor.getInitializationParameters( null, null ) ); + } + + + /** + * Registers a servlet class to be run, specifying initialization parameters. + **/ + public void registerServlet( String resourceName, String servletClassName, Hashtable initParameters ) { + _application.registerServlet( resourceName, servletClassName, initParameters ); } @@ -126,6 +142,25 @@ } + public static class JasperJSPServletDescriptor implements JSPServletDescriptor { + + public String getClassName() { + return "org.apache.jasper.servlet.JspServlet"; + } + + + public Hashtable getInitializationParameters( String classPath, String workingDirectory ) { + Hashtable params = new Hashtable(); + if (classPath != null) params.put( "classpath", classPath ); + if (workingDirectory != null) params.put( "scratchdir", workingDirectory ); + return params; + } + } + + + public final static JSPServletDescriptor JASPER_DESCRIPTOR = new JasperJSPServletDescriptor(); + + //-------------------------------------------- package methods --------------------------------------------------------- @@ -134,9 +169,16 @@ } + WebApplication getApplication() { + return _application; + } + + //---------------------------- private members ------------------------------------ - WebApplication _application; + private static JSPServletDescriptor _jspServletDescriptor = JASPER_DESCRIPTOR; + + private WebApplication _application; private ServletUnitClient _client; @@ -153,5 +195,6 @@ if (_client == null) _client = newClient(); return _client; } + } Index: ServletUnitClient.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitClient.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- ServletUnitClient.java 4 Feb 2002 22:33:55 -0000 1.5 +++ ServletUnitClient.java 23 Jun 2002 23:52:39 -0000 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 Index: ServletUnitContext.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitContext.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- ServletUnitContext.java 1 Mar 2002 06:08:24 -0000 1.2 +++ ServletUnitContext.java 23 Jun 2002 23:52:39 -0000 1.3 @@ -26,7 +26,7 @@ class ServletUnitContext { ServletUnitContext() { - _contextPath = ""; + this( null ); } ServletUnitContext(String contextPath) { Index: ServletUnitServletContext.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java,v retrieving revision 1.9 retrieving revision 1.10 diff -u -r1.9 -r1.10 --- ServletUnitServletContext.java 19 Jun 2002 13:47:19 -0000 1.9 +++ ServletUnitServletContext.java 23 Jun 2002 23:52:39 -0000 1.10 @@ -235,7 +235,7 @@ * any reason (such as when the content is being made available from a .war archive). **/ public String getRealPath( String path ) { - return null; // XXX not implemented + return _application.getResourceFile( path ).getAbsolutePath(); } Index: WebApplication.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/src/com/meterware/servletunit/WebApplication.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- WebApplication.java 19 Jun 2002 13:47:19 -0000 1.10 +++ WebApplication.java 23 Jun 2002 23:52:39 -0000 1.11 @@ -104,8 +104,8 @@ /** * Registers a servlet class to be run. **/ - void registerServlet( String resourceName, String servletClassName ) { - registerServlet( resourceName, new ServletConfiguration( servletClassName ) ); + void registerServlet( String resourceName, String servletClassName, Hashtable initParams ) { + registerServlet( resourceName, new ServletConfiguration( servletClassName, initParams ) ); } @@ -203,7 +203,7 @@ File getResourceFile( String path ) { if (_contextDir == null) { - return null; + return new File( path.substring(1) ); } else { return new File( _contextDir, path.substring(1) ); } @@ -355,8 +355,14 @@ class ServletConfiguration { - public ServletConfiguration( String className ) { + ServletConfiguration( String className ) { _className = className; + } + + + ServletConfiguration( String className, Hashtable initParams ) { + _className = className; + if (initParams != null) _initParams = initParams; } |