KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tester > Include10a


1 /*
2  * Copyright 1999, 2000, 2001 ,2004 The Apache Software Foundation.
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.apache.tester;
18
19
20 import java.io.*;
21 import javax.servlet.*;
22 import javax.servlet.http.*;
23
24 /**
25  * Ensure the correct container managed request attributes are set.
26  *
27  * @author Craig R. McClanahan
28  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:57 $
29  */

30
31 public class Include10a extends HttpServlet {
32
33     private static final String JavaDoc specials[] =
34     { "javax.servlet.include.request_uri",
35       "javax.servlet.include.context_path",
36       "javax.servlet.include.servlet_path",
37       "javax.servlet.include.path_info",
38       "javax.servlet.include.query_string" };
39
40
41     public void doGet(HttpServletRequest request, HttpServletResponse response)
42         throws IOException, ServletException {
43
44         // Prepare this response
45
StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
46     PrintWriter writer = response.getWriter();
47
48         // Validate the original request properties
49
String JavaDoc value = null;
50         value = (String JavaDoc) request.getAttribute("original.request_uri");
51         if (!value.equals(request.getRequestURI()))
52             sb.append(" getRequestURI() is " + request.getRequestURI() +
53                       " but should be " + value + "|");
54         value = (String JavaDoc) request.getAttribute("original.context_path");
55         if (!value.equals(request.getContextPath()))
56             sb.append(" getContextPath() is " + request.getContextPath() +
57                       " but should be " + value + "|");
58         value = (String JavaDoc) request.getAttribute("original.servlet_path");
59         if (!value.equals(request.getServletPath()))
60             sb.append(" getServletPath() is " + request.getServletPath() +
61                       " but should be " + value + "|");
62         value = (String JavaDoc) request.getAttribute("original.path_info");
63         if (!value.equals(request.getPathInfo()))
64             sb.append(" getPathInfo() is " + request.getPathInfo() +
65                       " but should be " + value + "|");
66         value = (String JavaDoc) request.getAttribute("original.query_string");
67         if (!value.equals(request.getQueryString()))
68             sb.append(" getQueryString() is " + request.getQueryString() +
69                       " but should be " + value + "|");
70
71         // Validate the container provided request attributes
72
value = (String JavaDoc)
73             request.getAttribute("javax.servlet.include.request_uri");
74         if (!(request.getContextPath() + "/Include10a/include/path").equals(value))
75             sb.append(" request_uri is " + value +
76                       " but should be " + request.getContextPath() +
77                       "/Include10a/include/path|");
78         value = (String JavaDoc)
79             request.getAttribute("javax.servlet.include.context_path");
80         if (!request.getContextPath().equals(value))
81             sb.append(" context_path is " + value +
82                       " but should be " + request.getContextPath() + "|");
83         value = (String JavaDoc)
84             request.getAttribute("javax.servlet.include.servlet_path");
85         if (!"/Include10a".equals(value))
86             sb.append(" servlet_path is " + value +
87                       " but should be /Include10a|");
88         value = (String JavaDoc)
89             request.getAttribute("javax.servlet.include.path_info");
90         if (!"/include/path".equals(value))
91             sb.append(" path_info is " + value +
92                       " but should be /include/path|");
93         value = (String JavaDoc)
94             request.getAttribute("javax.servlet.include.query_string");
95         if (!"name2=value2".equals(value))
96             sb.append(" query_string is " + value +
97                       " but should be name2=value2|");
98
99         // Generate our success or failure report
100
if (sb.length() < 1)
101             writer.println("Include10a PASSED");
102         else
103             writer.println("Include10a FAILED -" + sb.toString());
104
105     }
106
107 }
108
Popular Tags