Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: httpunit/src/com/meterware/servletunit/WebApplication.java
- ===================================================================
- --- httpunit/src/com/meterware/servletunit/WebApplication.java (revision 1061)
- +++ httpunit/src/com/meterware/servletunit/WebApplication.java (working copy)
- -57,6 +57,11 @@
- /** A mapping of resource names to servlet configurations. **/
- private WebResourceMap _servletMapping = new WebResourceMap();
- + /** A mapping of filter names to FilterConfigurations */
- + private Hashtable _filters = new Hashtable();
- + /** A mapping of servlet names to ServletConfigurations */
- + private Hashtable _servlets = new Hashtable();
- +
- /** A mapping of resource names to filter configurations. **/
- private FilterUrlMap _filterUrlMapping = new FilterUrlMap();
- -265,7 +270,11 @@
- return _servletMapping.get( url );
- }
- + ServletConfiguration getServletByName(String name) {
- + return (ServletConfiguration) _servlets.get(name);
- + }
- +
- /**
- * Returns true if this application uses Basic Authentication.
- */
- -417,6 +426,7 @@
- for (int i = 0; i < nl.getLength(); i++) registerFilterClass( nameToClass, (Element) nl.item( i ) );
- nl = document.getElementsByTagName( "filter-mapping" );
- for (int i = 0; i < nl.getLength(); i++) registerFilter( nameToClass, (Element) nl.item( i ) );
- + _filters = nameToClass;
- }
- -478,6 +488,7 @@
- for (int i = 0; i < nl.getLength(); i++) registerServletClass( nameToClass, (Element) nl.item( i ) );
- nl = document.getElementsByTagName( "servlet-mapping" );
- for (int i = 0; i < nl.getLength(); i++) registerServlet( nameToClass, (Element) nl.item( i ) );
- + _servlets = nameToClass;
- }
- -552,6 +563,7 @@
- private Servlet _servlet;
- private String _servletName;
- + private String _jspFile;
- private int _loadOrder = DONT_AUTOLOAD;
- ServletConfiguration( String className ) {
- -565,8 +577,11 @@
- ServletConfiguration( Element servletElement ) throws SAXException {
- - super( servletElement, "servlet-class" );
- + super( servletElement, "servlet-class",
- + XMLUtils.getChildNodeValue( servletElement, "servlet-class", "org.apache.jasper.servlet.JspServlet" ) );
- _servletName = XMLUtils.getChildNodeValue( servletElement, "servlet-name" );
- + _jspFile = XMLUtils.getChildNodeValue( servletElement, "jsp-file", "");
- + if("".equals(_jspFile)) _jspFile = null;
- final NodeList loadOrder = servletElement.getElementsByTagName( "load-on-startup" );
- for (int i = 0; i < loadOrder.getLength(); i++) {
- String order = XMLUtils.getTextValue( loadOrder.item(i) );
- -601,6 +616,11 @@
- }
- + public String getJspFile() {
- + return _jspFile;
- + }
- +
- +
- boolean isLoadOnStartup() {
- return _loadOrder != DONT_AUTOLOAD;
- }
- Index: httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java
- ===================================================================
- --- httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java (revision 1061)
- +++ httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java (working copy)
- -49,7 +49,12 @@
- WebResourceConfiguration( Element resourceElement, String resourceNodeName ) throws SAXException {
- - this( XMLUtils.getChildNodeValue( resourceElement, resourceNodeName ) );
- + this( resourceElement, resourceNodeName, XMLUtils.getChildNodeValue( resourceElement, resourceNodeName ) );
- + }
- +
- +
- + WebResourceConfiguration( Element resourceElement, String resourceNodeName, String className ) throws SAXException {
- + this( className );
- final NodeList initParams = resourceElement.getElementsByTagName( "init-param" );
- for (int i = initParams.getLength() - 1; i >= 0; i--) {
- _initParams.put( XMLUtils.getChildNodeValue( (Element) initParams.item( i ), "param-name" ),
- Index: httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java
- ===================================================================
- --- httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java (revision 1061)
- +++ httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java (working copy)
- -23,6 +23,7 @@
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileNotFoundException;
- +import java.io.IOException;
- import java.io.PrintStream;
- import java.net.MalformedURLException;
- import java.net.URL;
- -34,6 +35,7 @@
- import javax.servlet.ServletContext;
- import javax.servlet.ServletException;
- +import javax.servlet.*;
- -176,8 +178,54 @@
- *
- * This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.
- **/
- - public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String A) {
- - return null; // XXX not implemented
- + public javax.servlet.RequestDispatcher getNamedDispatcher( String servletName ) {
- + final WebApplication.ServletConfiguration servletConfig = _application.getServletByName(servletName);
- + if(servletConfig==null) return null;
- + Servlet tempServlet;
- + Exception tempException;
- + try {
- + tempServlet = servletConfig.getServlet();
- + tempException = null;
- + } catch (Exception e) {
- + tempServlet = null;
- + tempException = e;
- + }
- + final Servlet servlet = tempServlet;
- + final Exception instantiationException = tempException;
- +
- + return new javax.servlet.RequestDispatcher() {
- + public void forward( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
- + if(instantiationException!=null) {
- + if(instantiationException instanceof ServletException) {
- + throw (ServletException) instantiationException;
- + } else {
- + ServletException e = new ServletException(instantiationException.getMessage());
- + e.initCause(instantiationException);
- + throw e;
- + }
- + }
- + if(servletConfig.getJspFile()!=null) {
- + request.setAttribute("org.apache.catalina.jsp_file", servletConfig.getJspFile());
- + }
- + response.reset();
- + servlet.service( request, response );
- + }
- + public void include( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
- + if(instantiationException!=null) {
- + if(instantiationException instanceof ServletException) {
- + throw (ServletException) instantiationException;
- + } else {
- + ServletException e = new ServletException(instantiationException.getMessage());
- + e.initCause(instantiationException);
- + throw e;
- + }
- + }
- + if(servletConfig.getJspFile()!=null) {
- + request.setAttribute("org.apache.catalina.jsp_file", servletConfig.getJspFile());
- + }
- + servlet.service( request, response );
- + }
- + };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement