KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > springframework > web > servlet > mvc > MultiActionControllerTests


1 /*
2  * Copyright 2002-2005 the original author or authors.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.springframework.web.servlet.mvc;
18
19 import java.sql.SQLException JavaDoc;
20 import java.util.HashMap JavaDoc;
21 import java.util.Map JavaDoc;
22 import java.util.Properties JavaDoc;
23
24 import javax.servlet.ServletException JavaDoc;
25 import javax.servlet.http.HttpServletRequest JavaDoc;
26 import javax.servlet.http.HttpServletResponse JavaDoc;
27 import javax.servlet.http.HttpSession JavaDoc;
28
29 import junit.framework.TestCase;
30
31 import org.springframework.beans.FatalBeanException;
32 import org.springframework.beans.TestBean;
33 import org.springframework.mock.web.MockHttpServletRequest;
34 import org.springframework.mock.web.MockHttpServletResponse;
35 import org.springframework.mock.web.MockHttpSession;
36 import org.springframework.web.bind.ServletRequestBindingException;
37 import org.springframework.web.servlet.ModelAndView;
38 import org.springframework.web.servlet.mvc.multiaction.InternalPathMethodNameResolver;
39 import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
40 import org.springframework.web.servlet.mvc.multiaction.NoSuchRequestHandlingMethodException;
41 import org.springframework.web.servlet.mvc.multiaction.ParameterMethodNameResolver;
42 import org.springframework.web.servlet.mvc.multiaction.PropertiesMethodNameResolver;
43 import org.springframework.web.servlet.support.SessionRequiredException;
44
45 /**
46  * @author Rod Johnson
47  * @author Juergen Hoeller
48  * @author Colin Sampaleanu
49  */

50 public class MultiActionControllerTests extends TestCase {
51
52     public void testDefaultInternalPathMethodNameResolver() throws Exception JavaDoc {
53         doDefaultTestInternalPathMethodNameResolver("/foo.html", "foo");
54         doDefaultTestInternalPathMethodNameResolver("/foo/bar.html", "bar");
55         doDefaultTestInternalPathMethodNameResolver("/bugal.xyz", "bugal");
56         doDefaultTestInternalPathMethodNameResolver("/x/y/z/q/foo.html", "foo");
57         doDefaultTestInternalPathMethodNameResolver("qqq.q", "qqq");
58     }
59
60     private void doDefaultTestInternalPathMethodNameResolver(String JavaDoc in, String JavaDoc expected) throws Exception JavaDoc {
61         MultiActionController rc = new MultiActionController();
62         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", in);
63         String JavaDoc actual = rc.getMethodNameResolver().getHandlerMethodName(request);
64         assertEquals("Wrong method name resolved", expected, actual);
65     }
66
67     public void testCustomizedInternalPathMethodNameResolver() throws Exception JavaDoc {
68         doTestCustomizedInternalPathMethodNameResolver("/foo.html", "my", null, "myfoo");
69         doTestCustomizedInternalPathMethodNameResolver("/foo/bar.html", null, "Handler", "barHandler");
70         doTestCustomizedInternalPathMethodNameResolver("/Bugal.xyz", "your", "Method", "yourBugalMethod");
71     }
72
73     private void doTestCustomizedInternalPathMethodNameResolver(
74             String JavaDoc in, String JavaDoc prefix, String JavaDoc suffix, String JavaDoc expected) throws Exception JavaDoc {
75         MultiActionController rc = new MultiActionController();
76         InternalPathMethodNameResolver resolver = new InternalPathMethodNameResolver();
77         if (prefix != null) {
78             resolver.setPrefix(prefix);
79         }
80         if (suffix != null) {
81             resolver.setSuffix(suffix);
82         }
83         rc.setMethodNameResolver(resolver);
84         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", in);
85         String JavaDoc actual = rc.getMethodNameResolver().getHandlerMethodName(request);
86         assertEquals("Wrong method name resolved", expected, actual);
87     }
88
89     public void testParameterMethodNameResolver() throws NoSuchRequestHandlingMethodException {
90         ParameterMethodNameResolver mnr = new ParameterMethodNameResolver();
91         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.html");
92         request.addParameter("action", "bar");
93         assertEquals("bar", mnr.getHandlerMethodName(request));
94         request = new MockHttpServletRequest("GET", "/foo.html");
95         try {
96             mnr.getHandlerMethodName(request);
97             // should have thrown NoSuchRequestHandlingMethodException
98
}
99         catch (NoSuchRequestHandlingMethodException ex) {
100             // expected
101
}
102     }
103
104     public void testParameterMethodNameResolverWithCustomParamName() throws NoSuchRequestHandlingMethodException {
105         ParameterMethodNameResolver mnr = new ParameterMethodNameResolver();
106         mnr.setParamName("myparam");
107         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.html");
108         request.addParameter("myparam", "bar");
109         assertEquals("bar", mnr.getHandlerMethodName(request));
110     }
111
112     public void testParameterMethodNameResolverWithParamNames() throws NoSuchRequestHandlingMethodException {
113         ParameterMethodNameResolver resolver = new ParameterMethodNameResolver();
114         resolver.setDefaultMethodName("default");
115         resolver.setMethodParamNames(new String JavaDoc[] {"hello", "spring", "colin"});
116         Properties JavaDoc logicalMappings = new Properties JavaDoc();
117         logicalMappings.setProperty("hello", "goodbye");
118         logicalMappings.setProperty("nina", "colin");
119         resolver.setLogicalMappings(logicalMappings);
120
121         MockHttpServletRequest request = new MockHttpServletRequest();
122         request.addParameter("nomatch", "whatever");
123         try {
124             resolver.getHandlerMethodName(request);
125         }
126         catch (NoSuchRequestHandlingMethodException ex) {
127             //expected
128
}
129
130         // verify default handler
131
request = new MockHttpServletRequest();
132         request.addParameter("this will not match anything", "whatever");
133         assertEquals("default", resolver.getHandlerMethodName(request));
134
135         // verify first resolution strategy (action=method)
136
request = new MockHttpServletRequest();
137         request.addParameter("action", "reset");
138         assertEquals("reset", resolver.getHandlerMethodName(request));
139         // this one also tests logical mapping
140
request = new MockHttpServletRequest();
141         request.addParameter("action", "nina");
142         assertEquals("colin", resolver.getHandlerMethodName(request));
143
144         // now validate second resolution strategy (parameter existence)
145
// this also tests logical mapping
146
request = new MockHttpServletRequest();
147         request.addParameter("hello", "whatever");
148         assertEquals("goodbye", resolver.getHandlerMethodName(request));
149
150         request = new MockHttpServletRequest();
151         request.addParameter("spring", "whatever");
152         assertEquals("spring", resolver.getHandlerMethodName(request));
153
154         request = new MockHttpServletRequest();
155         request.addParameter("hello", "whatever");
156         request.addParameter("spring", "whatever");
157         assertEquals("goodbye", resolver.getHandlerMethodName(request));
158
159         request = new MockHttpServletRequest();
160         request.addParameter("colin", "whatever");
161         request.addParameter("spring", "whatever");
162         assertEquals("spring", resolver.getHandlerMethodName(request));
163         
164         // validate image button handling
165
request = new MockHttpServletRequest();
166         request.addParameter("spring.x", "whatever");
167         assertEquals("spring", resolver.getHandlerMethodName(request));
168
169         request = new MockHttpServletRequest();
170         request.addParameter("hello.x", "whatever");
171         request.addParameter("spring", "whatever");
172         assertEquals("goodbye", resolver.getHandlerMethodName(request));
173     }
174
175     public void testParameterMethodNameResolverWithDefaultMethodName() throws NoSuchRequestHandlingMethodException {
176         ParameterMethodNameResolver mnr = new ParameterMethodNameResolver();
177         mnr.setDefaultMethodName("foo");
178         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/foo.html");
179         request.addParameter("action", "bar");
180         assertEquals("bar", mnr.getHandlerMethodName(request));
181         request = new MockHttpServletRequest("GET", "/foo.html");
182         assertEquals("foo", mnr.getHandlerMethodName(request));
183     }
184
185     public void testInvokesCorrectMethod() throws Exception JavaDoc {
186         TestMaController mc = new TestMaController();
187         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/welcome.html");
188         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
189         Properties JavaDoc p = new Properties JavaDoc();
190         p.put("/welcome.html", "welcome");
191         PropertiesMethodNameResolver mnr = new PropertiesMethodNameResolver();
192         mnr.setMappings(p);
193         mc.setMethodNameResolver(mnr);
194
195         ModelAndView mv = mc.handleRequest(request, response);
196         assertTrue("Invoked welcome method", mc.wasInvoked("welcome"));
197         assertTrue("view name is welcome", mv.getViewName().equals("welcome"));
198         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
199
200         mc = new TestMaController();
201         request = new MockHttpServletRequest("GET", "/subdir/test.html");
202         response = new MockHttpServletResponse();
203         mv = mc.handleRequest(request, response);
204         assertTrue("Invoked test method", mc.wasInvoked("test"));
205         assertTrue("view name is subdir_test", mv.getViewName().equals("test"));
206         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
207     }
208
209     public void testPathMatching() throws Exception JavaDoc {
210         TestMaController mc = new TestMaController();
211         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/welcome.html");
212         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
213         Properties JavaDoc p = new Properties JavaDoc();
214         p.put("/welc*.html", "welcome");
215         PropertiesMethodNameResolver mn = new PropertiesMethodNameResolver();
216         mn.setMappings(p);
217         mc.setMethodNameResolver(mn);
218
219         ModelAndView mv = mc.handleRequest(request, response);
220         assertTrue("Invoked welcome method", mc.wasInvoked("welcome"));
221         assertTrue("view name is welcome", mv.getViewName().equals("welcome"));
222         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
223
224         mc = new TestMaController();
225         mc.setMethodNameResolver(mn);
226         request = new MockHttpServletRequest("GET", "/nomatch");
227         response = new MockHttpServletResponse();
228         try {
229             mv = mc.handleRequest(request, response);
230         }
231         catch (Exception JavaDoc e) {
232             // expected
233
}
234         assertFalse("Not invoking welcome method", mc.wasInvoked("welcome"));
235         assertTrue("No method invoked", mc.getInvokedMethods() == 0);
236     }
237
238     public static class TestDelegate {
239
240         boolean invoked;
241
242         public ModelAndView test(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
243             invoked = true;
244             return new ModelAndView("test");
245         }
246     }
247
248     public void testInvokesCorrectMethodOnDelegate() throws Exception JavaDoc {
249         MultiActionController mac = new MultiActionController();
250         TestDelegate d = new TestDelegate();
251         mac.setDelegate(d);
252         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/test.html");
253         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
254         ModelAndView mv = mac.handleRequest(request, response);
255         assertTrue("view name is test", mv.getViewName().equals("test"));
256         assertTrue("Delegate was invoked", d.invoked);
257     }
258
259     public void testInvokesCorrectMethodWithSession() throws Exception JavaDoc {
260         TestMaController mc = new TestMaController();
261         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/inSession.html");
262         request.setSession(new MockHttpSession(null));
263         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
264         ModelAndView mv = mc.handleRequest(request, response);
265         assertTrue("Invoked inSession method", mc.wasInvoked("inSession"));
266         assertTrue("view name is welcome", mv.getViewName().equals("inSession"));
267         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
268
269         request = new MockHttpServletRequest("GET", "/inSession.html");
270         response = new MockHttpServletResponse();
271         try {
272
273             mc.handleRequest(request, response);
274             fail("Should have rejected request without session");
275         }
276         catch (ServletException JavaDoc ex) {
277             //OK
278
}
279     }
280
281     public void testInvokesCommandMethodNoSession() throws Exception JavaDoc {
282         TestMaController mc = new TestMaController();
283         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/commandNoSession.html");
284         request.addParameter("name", "rod");
285         request.addParameter("age", "32");
286         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
287         ModelAndView mv = mc.handleRequest(request, response);
288         assertTrue("Invoked commandNoSession method", mc.wasInvoked("commandNoSession"));
289         assertTrue("view name is commandNoSession", mv.getViewName().equals("commandNoSession"));
290         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
291
292         // mc = new TestMaController();
293
// request = new MockHttpServletRequest("GET", "/subdir/test.html");
294
// response = new MockHttpServletResponse();
295
// mv = mc.handleRequest(request, response);
296
// assertTrue("Invoked subdir_test method", mc.wasInvoked("subdir_test"));
297
// assertTrue("view name is subdir_test", mv.getViewName().equals("subdir_test"));
298
// assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
299
}
300
301
302     public void testInvokesCommandMethodWithSession() throws Exception JavaDoc {
303         TestMaController mc = new TestMaController();
304         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/commandInSession.html");
305         request.addParameter("name", "rod");
306         request.addParameter("age", "32");
307
308         request.setSession(new MockHttpSession(null));
309         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
310         ModelAndView mv = mc.handleRequest(request, response);
311         assertTrue("Invoked commandInSession method", mc.wasInvoked("commandInSession"));
312         assertTrue("view name is commandInSession", mv.getViewName().equals("commandInSession"));
313         assertTrue("Only one method invoked", mc.getInvokedMethods() == 1);
314
315         request = new MockHttpServletRequest("GET", "/commandInSession.html");
316         response = new MockHttpServletResponse();
317         try {
318
319             mc.handleRequest(request, response);
320             fail("Should have rejected request without session");
321         }
322         catch (ServletException JavaDoc ex) {
323             //OK
324
}
325     }
326
327     public void testSessionRequiredCatchable() throws Exception JavaDoc {
328         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/testSession.html");
329         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
330         TestMaController contr = new TestSessionRequiredController();
331         try {
332             contr.handleRequest(request, response);
333             fail("Should have thrown exception");
334         }
335         catch (SessionRequiredException ex) {
336             //assertTrue("session required", ex.equals(t));
337
}
338         request = new MockHttpServletRequest("GET", "/testSession.html");
339         response = new MockHttpServletResponse();
340         contr = new TestSessionRequiredExceptionHandler();
341         ModelAndView mv = contr.handleRequest(request, response);
342         assertTrue("Name is ok", mv.getViewName().equals("handle(SRE)"));
343     }
344
345     private void testExceptionNoHandler(TestMaController mc, Throwable JavaDoc t) throws Exception JavaDoc {
346         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/testException.html");
347         request.setAttribute(TestMaController.THROWABLE_ATT, t);
348         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
349         try {
350             mc.handleRequest(request, response);
351             fail("Should have thrown exception");
352         }
353         catch (Throwable JavaDoc ex) {
354             assertTrue(ex.equals(t));
355         }
356     }
357
358     private void testExceptionNoHandler(Throwable JavaDoc t) throws Exception JavaDoc {
359         testExceptionNoHandler(new TestMaController(), t);
360     }
361
362     public void testExceptionNoHandler() throws Exception JavaDoc {
363         testExceptionNoHandler(new Exception JavaDoc());
364
365         // Should go straight through
366
testExceptionNoHandler(new ServletException JavaDoc());
367
368         // subclass of servlet exception
369
testExceptionNoHandler(new ServletRequestBindingException("foo"));
370         testExceptionNoHandler(new RuntimeException JavaDoc());
371         testExceptionNoHandler(new Error JavaDoc());
372     }
373
374     public void testLastModifiedDefault() throws Exception JavaDoc {
375         TestMaController mc = new TestMaController();
376         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/welcome.html");
377         long lastMod = mc.getLastModified(request);
378         assertTrue("default last modified is -1", lastMod == -1L);
379     }
380
381     public void testLastModifiedWithMethod() throws Exception JavaDoc {
382         LastModController mc = new LastModController();
383         MockHttpServletRequest request = new MockHttpServletRequest("GET", "/welcome.html");
384         long lastMod = mc.getLastModified(request);
385         assertTrue("last modified with method is > -1", lastMod == mc.getLastModified(request));
386     }
387
388     private ModelAndView testHandlerCaughtException(TestMaController mc, Throwable JavaDoc t) throws Exception JavaDoc {
389         HttpServletRequest JavaDoc request = new MockHttpServletRequest("GET", "/testException.html");
390         request.setAttribute(TestMaController.THROWABLE_ATT, t);
391         HttpServletResponse JavaDoc response = new MockHttpServletResponse();
392         ModelAndView mv = mc.handleRequest(request, response);
393         return mv;
394     }
395
396     public void testHandlerCaughtException() throws Exception JavaDoc {
397         TestMaController mc = new TestExceptionHandler();
398         ModelAndView mv = testHandlerCaughtException(mc, new Exception JavaDoc());
399         assertTrue("mv name is handle(Exception)", mv.getViewName().equals("handle(Exception)"));
400         assertTrue("Invoked correct method", mc.wasInvoked("handle(Exception)"));
401
402         // WILL GET RUNTIME EXCEPTIONS TOO
403
testExceptionNoHandler(mc, new Error JavaDoc());
404
405         mc = new TestServletExceptionHandler();
406         mv = testHandlerCaughtException(mc, new ServletException JavaDoc());
407         assertTrue(mv.getViewName().equals("handle(ServletException)"));
408         assertTrue("Invoke correct method", mc.wasInvoked("handle(ServletException)"));
409
410         mv = testHandlerCaughtException(mc, new ServletRequestBindingException("foo"));
411         assertTrue(mv.getViewName().equals("handle(ServletException)"));
412         assertTrue("Invoke correct method", mc.wasInvoked("handle(ServletException)"));
413
414         // Check it doesn't affect unknown exceptions
415
testExceptionNoHandler(mc, new RuntimeException JavaDoc());
416         testExceptionNoHandler(mc, new Error JavaDoc());
417         testExceptionNoHandler(mc, new SQLException JavaDoc());
418         testExceptionNoHandler(mc, new Exception JavaDoc());
419
420
421         mc = new TestRuntimeExceptionHandler();
422         mv = testHandlerCaughtException(mc, new RuntimeException JavaDoc());
423         assertTrue(mv.getViewName().equals("handle(RTE)"));
424         assertTrue("Invoke correct method", mc.wasInvoked("handle(RTE)"));
425         mv = testHandlerCaughtException(mc, new FatalBeanException(null, null));
426         assertTrue(mv.getViewName().equals("handle(RTE)"));
427         assertTrue("Invoke correct method", mc.wasInvoked("handle(RTE)"));
428
429         testExceptionNoHandler(mc, new SQLException JavaDoc());
430         testExceptionNoHandler(mc, new Exception JavaDoc());
431     }
432
433
434     /** No error handlers */
435     public static class TestMaController extends MultiActionController {
436
437         public static final String JavaDoc THROWABLE_ATT = "throwable";
438
439         /** Method name -> object */
440         protected Map JavaDoc invoked = new HashMap JavaDoc();
441
442         public void clear() {
443             invoked.clear();
444         }
445
446         public ModelAndView welcome(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
447             invoked.put("welcome", Boolean.TRUE);
448             return new ModelAndView("welcome");
449         }
450
451         public ModelAndView commandNoSession(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, TestBean command) {
452             invoked.put("commandNoSession", Boolean.TRUE);
453
454             String JavaDoc pname = request.getParameter("name");
455             String JavaDoc page = request.getParameter("age");
456             // ALLOW FOR NULL
457
if (pname == null)
458                 assertTrue("name null", command.getName() == null);
459             else
460                 assertTrue("name param set", pname.equals(command.getName()));
461             // if (page == null)
462
// assertTrue("age default", command.getAge() == 0);
463
// else
464
// assertTrue("age set", command.getName().equals(pname));
465
//assertTrue("a", command.getAge().equals(request.getParameter("name")));
466
return new ModelAndView("commandNoSession");
467         }
468
469         public ModelAndView inSession(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, HttpSession JavaDoc session) {
470             invoked.put("inSession", Boolean.TRUE);
471             assertTrue("session non null", session != null);
472             return new ModelAndView("inSession");
473         }
474
475         public ModelAndView commandInSession(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, HttpSession JavaDoc session, TestBean command) {
476             invoked.put("commandInSession", Boolean.TRUE);
477             assertTrue("session non null", session != null);
478             return new ModelAndView("commandInSession");
479         }
480
481         public ModelAndView test(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
482             invoked.put("test", Boolean.TRUE);
483             return new ModelAndView("test");
484         }
485
486         public ModelAndView testException(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) throws Throwable JavaDoc {
487             invoked.put("testException", Boolean.TRUE);
488             Throwable JavaDoc t = (Throwable JavaDoc) request.getAttribute(THROWABLE_ATT);
489             if (t != null)
490                 throw t;
491             else
492                 return new ModelAndView("no throwable");
493         }
494
495         public boolean wasInvoked(String JavaDoc method) {
496             return invoked.get(method) != null;
497         }
498
499         public int getInvokedMethods() {
500             return invoked.size();
501         }
502     }
503
504
505     public static class TestExceptionHandler extends TestMaController {
506
507         public ModelAndView handleAnyException(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, Exception JavaDoc ex) {
508             invoked.put("handle(Exception)", Boolean.TRUE);
509             return new ModelAndView("handle(Exception)");
510         }
511     }
512
513
514     public static class TestRuntimeExceptionHandler extends TestMaController {
515
516         public ModelAndView handleRuntimeProblem(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, RuntimeException JavaDoc ex) {
517             invoked.put("handle(RTE)", Boolean.TRUE);
518             return new ModelAndView("handle(RTE)");
519         }
520     }
521
522
523     public static class TestSessionRequiredController extends TestMaController {
524
525         public ModelAndView testSession(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, HttpSession JavaDoc sess) {
526             return null;
527         }
528     }
529
530
531     /** Extends previous to handle exception */
532     public static class TestSessionRequiredExceptionHandler extends TestSessionRequiredController {
533
534         public ModelAndView handleServletException(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, SessionRequiredException ex) {
535             invoked.put("handle(SRE)", Boolean.TRUE);
536             return new ModelAndView("handle(SRE)");
537         }
538     }
539
540
541     public static class TestServletExceptionHandler extends TestMaController {
542
543         public ModelAndView handleServletException(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response, ServletException JavaDoc ex) {
544             invoked.put("handle(ServletException)", Boolean.TRUE);
545             return new ModelAndView("handle(ServletException)");
546         }
547     }
548
549
550     public static class LastModController extends MultiActionController {
551
552         public static final String JavaDoc THROWABLE_ATT = "throwable";
553
554         /** Method name -> object */
555         protected HashMap JavaDoc invoked = new HashMap JavaDoc();
556
557         public void clear() {
558             invoked.clear();
559         }
560
561         public ModelAndView welcome(HttpServletRequest JavaDoc request, HttpServletResponse JavaDoc response) {
562             invoked.put("welcome", Boolean.TRUE);
563             return new ModelAndView("welcome");
564         }
565
566         /** Always says content is up to date */
567         public long welcomeLastModified(HttpServletRequest JavaDoc request) {
568             return 1111L;
569         }
570     }
571
572 }
573
Popular Tags