1 17 18 23 24 package org.apache.tomcat.util.http; 25 26 import java.io.PrintWriter ; 27 import java.io.StringWriter ; 28 29 import java.util.HashMap ; 30 import java.util.Iterator ; 31 32 import org.apache.tomcat.util.buf.MessageBytes; 33 34 38 public class BaseRequest { 39 40 public static final String SCHEME_HTTP = "http"; 42 public static final String SCHEME_HTTPS = "https"; 43 44 MessageBytes method = MessageBytes.newInstance(); 46 MessageBytes protocol = MessageBytes.newInstance(); 47 MessageBytes requestURI = MessageBytes.newInstance(); 48 MessageBytes remoteAddr = MessageBytes.newInstance(); 49 MessageBytes remoteHost = MessageBytes.newInstance(); 50 MessageBytes serverName = MessageBytes.newInstance(); 51 int serverPort = 80; 52 MessageBytes remoteUser = MessageBytes.newInstance(); 53 MessageBytes authType = MessageBytes.newInstance(); 54 MessageBytes queryString = MessageBytes.newInstance(); 55 MessageBytes authorization = MessageBytes.newInstance(); 56 String scheme = SCHEME_HTTP; 57 boolean secure = false; 58 int contentLength = 0; 59 MessageBytes contentType = MessageBytes.newInstance(); 60 MimeHeaders headers = new MimeHeaders(); 61 Cookies cookies = new Cookies(); 62 HashMap attributes = new HashMap (); 63 64 MessageBytes tomcatInstanceId = MessageBytes.newInstance(); 65 66 69 public void recycle() { 70 method.recycle(); 71 protocol.recycle(); 72 requestURI.recycle(); 73 remoteAddr.recycle(); 74 remoteHost.recycle(); 75 serverName.recycle(); 76 serverPort = 80; 77 remoteUser.recycle(); 78 authType.recycle(); 79 queryString.recycle(); 80 authorization.recycle(); 81 scheme = SCHEME_HTTP; 82 secure = false; 83 contentLength = 0; 84 contentType.recycle(); 85 headers.recycle(); 86 cookies.recycle(); 87 attributes.clear(); 88 tomcatInstanceId.recycle(); 89 } 90 91 95 public MessageBytes method() { 96 return method; 97 } 98 99 103 public MessageBytes protocol() { 104 return protocol; 105 } 106 107 111 public MessageBytes requestURI() { 112 return requestURI; 113 } 114 115 119 public MessageBytes remoteAddr() { 120 return remoteAddr; 121 } 122 123 127 public MessageBytes remoteHost() { 128 return remoteHost; 129 } 130 131 135 public MessageBytes serverName() { 136 return serverName; 137 } 138 139 143 public int getServerPort() { 144 return serverPort; 145 } 146 147 151 public void setServerPort(int i) { 152 serverPort = i; 153 } 154 155 159 public MessageBytes remoteUser() { 160 return remoteUser; 161 } 162 163 167 public MessageBytes authType() { 168 return authType; 169 } 170 171 175 public MessageBytes queryString() { 176 return queryString; 177 } 178 179 183 public MessageBytes authorization() { 184 return authorization; 185 } 186 187 191 public String getScheme() { 192 return scheme; 193 } 194 195 199 public void setScheme(String s) { 200 scheme = s; 201 } 202 203 207 public boolean getSecure() { 208 return secure; 209 } 210 211 215 public void setSecure(boolean b) { 216 secure = b; 217 } 218 219 223 public int getContentLength() { 224 return contentLength; 225 } 226 227 231 public void setContentLength(int i) { 232 contentLength = i; 233 } 234 235 239 public MessageBytes contentType() { 240 return contentType; 241 } 242 243 247 public MimeHeaders headers() { 248 return headers; 249 } 250 251 255 public Cookies cookies() { 256 return cookies; 257 } 258 259 264 public void setAttribute(String name, Object value) { 265 if (name == null || value == null) { 266 return; 267 } 268 attributes.put(name, value); 269 } 270 271 276 public Object getAttribute(String name) { 277 if (name == null) { 278 return null; 279 } 280 281 return attributes.get(name); 282 } 283 284 288 public Iterator getAttributeNames() { 289 return attributes.keySet().iterator(); 290 } 291 292 296 public MessageBytes instanceId() { 297 return tomcatInstanceId; 298 } 299 300 public MessageBytes jvmRoute() { 304 return tomcatInstanceId; 305 } 306 307 private Object notes[]=new Object [16]; 308 309 public final Object getNote(int id) { 310 return notes[id]; 311 } 312 313 public final void setNote(int id, Object cr) { 314 notes[id]=cr; 315 } 316 317 320 public String toString() { 321 StringWriter sw = new StringWriter (); 322 PrintWriter pw = new PrintWriter (sw); 323 324 pw.println("=== BaseRequest ==="); 325 pw.println("method = " + method.toString()); 326 pw.println("protocol = " + protocol.toString()); 327 pw.println("requestURI = " + requestURI.toString()); 328 pw.println("remoteAddr = " + remoteAddr.toString()); 329 pw.println("remoteHost = " + remoteHost.toString()); 330 pw.println("serverName = " + serverName.toString()); 331 pw.println("serverPort = " + serverPort); 332 pw.println("remoteUser = " + remoteUser.toString()); 333 pw.println("authType = " + authType.toString()); 334 pw.println("queryString = " + queryString.toString()); 335 pw.println("scheme = " + scheme.toString()); 336 pw.println("secure = " + secure); 337 pw.println("contentLength = " + contentLength); 338 pw.println("contentType = " + contentType); 339 pw.println("attributes = " + attributes.toString()); 340 pw.println("headers = " + headers.toString()); 341 pw.println("cookies = " + cookies.toString()); 342 pw.println("jvmRoute = " + tomcatInstanceId.toString()); 343 return sw.toString(); 344 } 345 346 } 347 | Popular Tags |