View difference between Paste ID: f15093292 and
SHOW: | | - or go back to the newest paste.
1-
1+
Index: httpunit/src/com/meterware/servletunit/WebApplication.java
2
===================================================================
3
--- httpunit/src/com/meterware/servletunit/WebApplication.java	(revision 1061)
4
+++ httpunit/src/com/meterware/servletunit/WebApplication.java	(working copy)
5
 -57,6 +57,11 @@
6
     /** A mapping of resource names to servlet configurations. **/
7
     private WebResourceMap _servletMapping = new WebResourceMap();
8
 
9
+    /** A mapping of filter names to FilterConfigurations */
10
+    private Hashtable _filters = new Hashtable();
11
+    /** A mapping of servlet names to ServletConfigurations */
12
+    private Hashtable _servlets = new Hashtable();
13
+
14
     /** A mapping of resource names to filter configurations. **/
15
     private FilterUrlMap _filterUrlMapping = new FilterUrlMap();
16
 
17
 -265,7 +270,11 @@
18
         return _servletMapping.get( url );
19
     }
20
 
21
+    ServletConfiguration getServletByName(String name) {
22
+        return (ServletConfiguration) _servlets.get(name);
23
+    }
24
 
25
+
26
     /**
27
      * Returns true if this application uses Basic Authentication.
28
      */
29
 -417,6 +426,7 @@
30
         for (int i = 0; i < nl.getLength(); i++) registerFilterClass( nameToClass, (Element) nl.item( i ) );
31
         nl = document.getElementsByTagName( "filter-mapping" );
32
         for (int i = 0; i < nl.getLength(); i++) registerFilter( nameToClass, (Element) nl.item( i ) );
33
+	_filters = nameToClass;
34
     }
35
 
36
 
37
 -478,6 +488,7 @@
38
         for (int i = 0; i < nl.getLength(); i++) registerServletClass( nameToClass, (Element) nl.item( i ) );
39
         nl = document.getElementsByTagName( "servlet-mapping" );
40
         for (int i = 0; i < nl.getLength(); i++) registerServlet( nameToClass, (Element) nl.item( i ) );
41
+	_servlets = nameToClass;
42
     }
43
 
44
 
45
 -552,6 +563,7 @@
46
 
47
         private Servlet _servlet;
48
         private String _servletName;
49
+	private String _jspFile;
50
         private int _loadOrder = DONT_AUTOLOAD;
51
 
52
         ServletConfiguration( String className ) {
53
 -565,8 +577,11 @@
54
 
55
 
56
         ServletConfiguration( Element servletElement ) throws SAXException {
57
-            super( servletElement, "servlet-class" );
58
+            super( servletElement, "servlet-class", 
59
+		XMLUtils.getChildNodeValue( servletElement, "servlet-class", "org.apache.jasper.servlet.JspServlet" ) );
60
             _servletName = XMLUtils.getChildNodeValue( servletElement, "servlet-name" );
61
+	    _jspFile = XMLUtils.getChildNodeValue( servletElement, "jsp-file", "");
62
+	    if("".equals(_jspFile)) _jspFile = null;
63
             final NodeList loadOrder = servletElement.getElementsByTagName( "load-on-startup" );
64
             for (int i = 0; i < loadOrder.getLength(); i++) {
65
                 String order = XMLUtils.getTextValue( loadOrder.item(i) );
66
 -601,6 +616,11 @@
67
         }
68
 
69
 
70
+        public String getJspFile() {
71
+            return _jspFile;
72
+        }
73
+
74
+
75
         boolean isLoadOnStartup() {
76
             return _loadOrder != DONT_AUTOLOAD;
77
         }
78
Index: httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java
79
===================================================================
80
--- httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java	(revision 1061)
81
+++ httpunit/src/com/meterware/servletunit/WebResourceConfiguration.java	(working copy)
82
 -49,7 +49,12 @@
83
 
84
 
85
     WebResourceConfiguration( Element resourceElement, String resourceNodeName ) throws SAXException {
86
-        this( XMLUtils.getChildNodeValue( resourceElement, resourceNodeName ) );
87
+	this( resourceElement, resourceNodeName, XMLUtils.getChildNodeValue( resourceElement, resourceNodeName ) );
88
+    }
89
+
90
+
91
+    WebResourceConfiguration( Element resourceElement, String resourceNodeName, String className ) throws SAXException {
92
+        this( className );
93
         final NodeList initParams = resourceElement.getElementsByTagName( "init-param" );
94
         for (int i = initParams.getLength() - 1; i >= 0; i--) {
95
             _initParams.put( XMLUtils.getChildNodeValue( (Element) initParams.item( i ), "param-name" ),
96
Index: httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java
97
===================================================================
98
--- httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java	(revision 1061)
99
+++ httpunit/src/com/meterware/servletunit/ServletUnitServletContext.java	(working copy)
100
 -23,6 +23,7 @@
101
 import java.io.File;
102
 import java.io.FileInputStream;
103
 import java.io.FileNotFoundException;
104
+import java.io.IOException;
105
 import java.io.PrintStream;
106
 import java.net.MalformedURLException;
107
 import java.net.URL;
108
 -34,6 +35,7 @@
109
 
110
 import javax.servlet.ServletContext;
111
 import javax.servlet.ServletException;
112
+import javax.servlet.*;
113
 
114
 
115
 
116
 -176,8 +178,54 @@
117
      *
118
      * This method returns null if the ServletContext cannot return a RequestDispatcher for any reason.
119
      **/
120
-    public javax.servlet.RequestDispatcher getNamedDispatcher(java.lang.String A) {
121
-        return null;   // XXX not implemented
122
+    public javax.servlet.RequestDispatcher getNamedDispatcher( String servletName ) {
123
+	final WebApplication.ServletConfiguration servletConfig = _application.getServletByName(servletName);
124
+	if(servletConfig==null) return null;
125
+	Servlet tempServlet;
126
+	Exception tempException;
127
+        try {
128
+            tempServlet = servletConfig.getServlet();
129
+	    tempException = null;
130
+	} catch (Exception e) {
131
+		tempServlet = null;
132
+		tempException = e;
133
+        }
134
+	final Servlet servlet = tempServlet;
135
+	final Exception instantiationException = tempException;
136
+
137
+	return new javax.servlet.RequestDispatcher() {
138
+		public void forward( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
139
+			if(instantiationException!=null) { 
140
+				if(instantiationException instanceof ServletException) {
141
+					throw (ServletException) instantiationException;
142
+				} else {
143
+					ServletException e = new ServletException(instantiationException.getMessage());
144
+					e.initCause(instantiationException);
145
+					throw e;
146
+				}
147
+			}
148
+			if(servletConfig.getJspFile()!=null) {
149
+				request.setAttribute("org.apache.catalina.jsp_file", servletConfig.getJspFile());
150
+			}
151
+			response.reset();
152
+			servlet.service( request, response );
153
+		}
154
+		public void include( ServletRequest request, ServletResponse response ) throws ServletException, IOException {
155
+			if(instantiationException!=null) { 
156
+				if(instantiationException instanceof ServletException) {
157
+					throw (ServletException) instantiationException;
158
+				} else {
159
+					ServletException e = new ServletException(instantiationException.getMessage());
160
+					e.initCause(instantiationException);
161
+					throw e;
162
+				}
163
+			}
164
+			if(servletConfig.getJspFile()!=null) {
165
+				request.setAttribute("org.apache.catalina.jsp_file", servletConfig.getJspFile());
166
+			}
167
+			servlet.service( request, response );
168
+		}
169
+	};
170
     }