1 |
| |
2 |
| |
3 |
| |
4 |
| |
5 |
| |
6 |
| |
7 |
| |
8 |
| |
9 |
| |
10 |
| |
11 |
| |
12 |
| |
13 |
| |
14 |
| |
15 |
| package org.apache.tapestry.test.mock; |
16 |
| |
17 |
| import java.io.FileInputStream; |
18 |
| import java.io.IOException; |
19 |
| import java.io.InputStream; |
20 |
| import java.io.OutputStream; |
21 |
| |
22 |
| import javax.servlet.RequestDispatcher; |
23 |
| import javax.servlet.ServletException; |
24 |
| import javax.servlet.ServletRequest; |
25 |
| import javax.servlet.ServletResponse; |
26 |
| |
27 |
| |
28 |
| |
29 |
| |
30 |
| |
31 |
| |
32 |
| |
33 |
| public class MockRequestDispatcher implements RequestDispatcher |
34 |
| { |
35 |
| private String _resourcePath; |
36 |
| |
37 |
0
| public MockRequestDispatcher(String resourcePath)
|
38 |
| { |
39 |
0
| _resourcePath = resourcePath;
|
40 |
| } |
41 |
| |
42 |
0
| public void forward(ServletRequest request, ServletResponse response)
|
43 |
| throws ServletException, IOException |
44 |
| { |
45 |
0
| if (_resourcePath.endsWith("/FAIL_SERVLET"))
|
46 |
0
| throw new ServletException("Test-directed ServletException from RequestDispatcher forward().");
|
47 |
| |
48 |
| |
49 |
| |
50 |
| |
51 |
0
| InputStream in = new FileInputStream(_resourcePath);
|
52 |
| |
53 |
0
| response.setContentType("test/html");
|
54 |
| |
55 |
0
| OutputStream out = response.getOutputStream();
|
56 |
| |
57 |
| |
58 |
0
| byte[] buffer = new byte[1000];
|
59 |
| |
60 |
0
| while (true)
|
61 |
| { |
62 |
0
| int length = in.read(buffer);
|
63 |
| |
64 |
0
| if (length < 0)
|
65 |
0
| break;
|
66 |
| |
67 |
0
| out.write(buffer, 0, length);
|
68 |
| } |
69 |
| |
70 |
0
| in.close();
|
71 |
0
| out.close();
|
72 |
| } |
73 |
| |
74 |
0
| public void include(ServletRequest request, ServletResponse response)
|
75 |
| throws ServletException, IOException |
76 |
| { |
77 |
0
| throw new ServletException("MockRequestDispatcher.include() not supported.");
|
78 |
| } |
79 |
| |
80 |
| } |