KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 1999, 2000 ,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 java.util.Map JavaDoc;
22 import javax.servlet.*;
23 import javax.servlet.http.*;
24
25 /**
26  * Test getting the servlet input stream after we have retrieved the reader.
27  * This should throw an IllegalStateException.
28  *
29  * @author Craig R. McClanahan
30  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:57 $
31  */

32
33 public class GetParameterMap00 extends GenericServlet {
34
35     public void service(ServletRequest request, ServletResponse response)
36         throws IOException, ServletException {
37
38         response.setContentType("text/plain");
39         PrintWriter writer = response.getWriter();
40         String JavaDoc errors = "";
41         Map JavaDoc map = request.getParameterMap();
42         if (map == null)
43             errors += " getParameterMap() returned null.";
44         else {
45             if (map.size() != 2)
46                 errors += " map size is " + map.size() + ".";
47             String JavaDoc value1[] = (String JavaDoc[]) map.get("BestLanguage");
48             if (value1 == null)
49                 errors += " BestLanguage is NULL.";
50             else if (value1.length != 1)
51                 errors += " BestLanguage has " + value1.length + " values.";
52             else if (!value1[0].equals("Java"))
53                 errors += " BestLanguage is " + value1 + ".";
54             String JavaDoc value2[] = (String JavaDoc[]) map.get("BestJSP");
55             if (value2 == null)
56                 errors += " BestJSP is NULL.";
57             else if (value2.length != 1)
58                 errors += " BestJSP has " + value2.length + " values.";
59             else if (!value2[0].equals("Java2"))
60                 errors += " BestJSP is " + value2 + ".";
61             try {
62                 map.put("ABC", "XYZ");
63                 errors += " map.put() was allowed.";
64                 if (map.get("ABC") != null)
65                     errors += " map is not immutable.";
66             } catch (Throwable JavaDoc t) {
67                 ;
68             }
69         }
70
71         if (errors.equals(""))
72             writer.println("GetParameterMap00 PASSED");
73         else {
74             writer.println("GetParameterMap00 FAILED:" + errors);
75         }
76         while (true) {
77             String JavaDoc message = StaticLogger.read();
78             if (message == null)
79                 break;
80             writer.println(message);
81         }
82         StaticLogger.reset();
83
84     }
85
86 }
87
Popular Tags