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 ; 6 import java.util.HashMap ; 7 import java.util.Enumeration ; 8 import javax.servlet.http.Cookie ; 9 10 19 20 public class SamplePO implements HttpPresentation { 21 22 25 public static final String Answer1 = "<html><head/><body>A GET request</body></html>"; 26 private String method = null; 27 private Map headers = new HashMap (); 28 private Map params = new HashMap (); 29 private Map cookies = new HashMap (); 30 31 36 public void run(HttpPresentationComms comms) throws Exception { 37 38 method = comms.request.getMethod(); 39 40 for(Enumeration em = comms.request.getParameterNames();em.hasMoreElements();){ 41 String key = (String )em.nextElement(); 42 String value = comms.request.getParameter(key); 43 params.put(key, value); 44 } 45 for(Enumeration em = comms.request.getHeaderNames();em.hasMoreElements();){ 46 String key = (String )em.nextElement(); 47 String value = comms.request.getHeader(key); 48 headers.put(key, value); 49 } 50 Cookie [] cookieArray = comms.request.getCookies(); 51 if (cookieArray != null) { 52 for (int i = 0; i < cookieArray.length; i++) { 53 Cookie cookie = cookieArray[i]; 54 cookies.put(cookie.getName(), cookie.getValue()); 55 } 56 } 57 comms.response.writeHTML(Answer1); 58 } 59 60 public String checkMethod(){ 61 return method; 62 } 63 64 public Map getRequestParameters(){ 65 return params; 66 } 67 68 public String getRequestHeader(String name){ 69 return (String )headers.get(name); 70 } 71 72 public Map getRequestCookies(){ 73 return cookies; 74 } 75 76 } | Popular Tags |