KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > hamletsoft > enhydra > cactus > presentation > sample > SamplePO


1 package org.hamletsoft.enhydra.cactus.presentation.sample;
2
3 import com.lutris.appserver.server.httpPresentation.HttpPresentation;
4 import com.lutris.appserver.server.httpPresentation.HttpPresentationComms;
5 import java.util.Map JavaDoc;
6 import java.util.HashMap JavaDoc;
7 import java.util.Enumeration JavaDoc;
8 import javax.servlet.http.Cookie JavaDoc;
9
10 /**
11  * SamplePO.java <br>
12  * Test sample presentation object for Enhydra Testing framework using Jakarta Cactus.
13  *
14  * Created: Thu Jan 31 11:29:30 2002
15  *
16  * @author <a HREF="mailto:hattori@hitachizosen.co.jp">Ryuji Hattori</a>
17  * @version
18  */

19
20 public class SamplePO implements HttpPresentation {
21
22     // public SamplePO (){;}
23
// implementation of com.lutris.appserver.server.httpPresentation.HttpPresentation interface
24

25     public static final String JavaDoc Answer1 = "<html><head/><body>A GET request</body></html>";
26     private String JavaDoc method = null;
27     private Map JavaDoc headers = new HashMap JavaDoc();
28     private Map JavaDoc params = new HashMap JavaDoc();
29     private Map JavaDoc cookies = new HashMap JavaDoc();
30     
31     /**
32      *
33      * @param comms <description>
34      * @exception java.lang.Exception <description>
35      */

36     public void run(HttpPresentationComms comms) throws Exception JavaDoc {
37     
38     method = comms.request.getMethod();
39     
40     for(Enumeration JavaDoc em = comms.request.getParameterNames();em.hasMoreElements();){
41         String JavaDoc key = (String JavaDoc)em.nextElement();
42         String JavaDoc value = comms.request.getParameter(key);
43         params.put(key, value);
44     }
45     for(Enumeration JavaDoc em = comms.request.getHeaderNames();em.hasMoreElements();){
46         String JavaDoc key = (String JavaDoc)em.nextElement();
47         String JavaDoc value = comms.request.getHeader(key);
48         headers.put(key, value);
49     }
50         Cookie JavaDoc[] cookieArray = comms.request.getCookies();
51         if (cookieArray != null) {
52             for (int i = 0; i < cookieArray.length; i++) {
53                 Cookie JavaDoc cookie = cookieArray[i];
54                 cookies.put(cookie.getName(), cookie.getValue());
55             }
56         }
57     comms.response.writeHTML(Answer1);
58     }
59     
60     public String JavaDoc checkMethod(){
61     return method;
62     }
63
64     public Map JavaDoc getRequestParameters(){
65     return params;
66     }
67
68     public String JavaDoc getRequestHeader(String JavaDoc name){
69     return (String JavaDoc)headers.get(name);
70     }
71
72     public Map JavaDoc getRequestCookies(){
73     return cookies;
74     }
75
76 }// SamplePO
77
Popular Tags