1 20 package org.apache.mina.example.httpserver.codec; 21 22 import java.util.Iterator ; 23 import java.util.Map ; 24 import java.util.Map.Entry; 25 26 32 public class HttpRequestMessage { 33 34 private Map headers = null; 35 36 public void setHeaders(Map headers) { 37 this.headers = headers; 38 } 39 40 public Map getHeaders() { 41 return headers; 42 } 43 44 public String getContext() { 45 String [] context = (String []) headers.get("Context"); 46 return context == null ? "" : context[0]; 47 } 48 49 public String getParameter(String name) { 50 String [] param = (String []) headers.get("@".concat(name)); 51 return param == null ? "" : param[0]; 52 } 53 54 public String [] getParameters(String name) { 55 String [] param = (String []) headers.get("@".concat(name)); 56 return param == null ? new String [] {} : param; 57 } 58 59 public String [] getHeader(String name) { 60 return (String []) headers.get(name); 61 } 62 63 public String toString() { 64 StringBuilder str = new StringBuilder (); 65 66 Iterator it = headers.entrySet().iterator(); 67 while (it.hasNext()) { 68 Entry e = (Entry) it.next(); 69 str.append(e.getKey() + " : " 70 + arrayToString((String []) e.getValue(), ',') + "\n"); 71 } 72 return str.toString(); 73 } 74 75 public static String arrayToString(String [] s, char sep) { 76 if (s == null || s.length == 0) 77 return ""; 78 StringBuffer buf = new StringBuffer (); 79 if (s != null) { 80 for (int i = 0; i < s.length; i++) { 81 if (i > 0) 82 buf.append(sep); 83 buf.append(s[i]); 84 } 85 } 86 return buf.toString(); 87 } 88 } 89 | Popular Tags |