1 16 package org.directwebremoting.util; 17 18 import java.io.BufferedReader ; 19 import java.io.IOException ; 20 import java.io.StringReader ; 21 import java.io.UnsupportedEncodingException ; 22 import java.security.Principal ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Enumeration ; 26 import java.util.HashMap ; 27 import java.util.Locale ; 28 import java.util.Map ; 29 import java.util.Vector ; 30 31 import javax.servlet.RequestDispatcher ; 32 import javax.servlet.ServletException ; 33 import javax.servlet.ServletInputStream ; 34 import javax.servlet.ServletRequest ; 35 import javax.servlet.ServletResponse ; 36 import javax.servlet.http.Cookie ; 37 import javax.servlet.http.HttpServletRequest ; 38 import javax.servlet.http.HttpSession ; 39 40 45 public class FakeHttpServletRequest implements HttpServletRequest 46 { 47 50 public String getAuthType() 51 { 52 return null; 53 } 54 55 58 public Cookie [] getCookies() 59 { 60 return null; 61 } 62 63 66 public long getDateHeader(String name) 67 { 68 return -1; 69 } 70 71 74 public String getHeader(String name) 75 { 76 return null; 77 } 78 79 82 public Enumeration getHeaders(String name) 83 { 84 return new Vector ().elements(); 85 } 86 87 90 public Enumeration getHeaderNames() 91 { 92 return new Vector ().elements(); 93 } 94 95 98 public int getIntHeader(String name) 99 { 100 return -1; 101 } 102 103 106 public String getMethod() 107 { 108 log.warn("Inventing data in FakeHttpServletRequest.getMethod() to remain plausible."); 109 return "GET"; 110 } 111 112 115 public String getPathInfo() 116 { 117 return null; 118 } 119 120 123 public String getPathTranslated() 124 { 125 return null; 126 } 127 128 131 public String getContextPath() 132 { 133 log.warn("Inventing data in FakeHttpServletRequest.getContextPath() to remain plausible."); 134 return ""; 135 } 136 137 140 public String getQueryString() 141 { 142 return null; 143 } 144 145 148 public String getRemoteUser() 149 { 150 return null; 151 } 152 153 156 public boolean isUserInRole(String role) 157 { 158 return false; 159 } 160 161 164 public Principal getUserPrincipal() 165 { 166 return null; 167 } 168 169 172 public String getRequestedSessionId() 173 { 174 return null; 175 } 176 177 180 public String getRequestURI() 181 { 182 log.warn("Inventing data in FakeHttpServletRequest.getRequestURI() to remain plausible."); 183 return "/"; 184 } 185 186 189 public StringBuffer getRequestURL() 190 { 191 log.warn("Inventing data in FakeHttpServletRequest.getRequestURL() to remain plausible."); 192 return new StringBuffer ("http://localhost/"); 193 } 194 195 198 public String getServletPath() 199 { 200 log.warn("Inventing data in FakeHttpServletRequest.getServletPath() to remain plausible."); 201 return ""; 202 } 203 204 207 public HttpSession getSession(boolean create) 208 { 209 if (!create) 210 { 211 return null; 212 } 213 214 return new FakeHttpSession(); 215 } 216 217 220 public HttpSession getSession() 221 { 222 return null; 223 } 224 225 228 public boolean isRequestedSessionIdValid() 229 { 230 return false; 231 } 232 233 236 public boolean isRequestedSessionIdFromCookie() 237 { 238 return false; 239 } 240 241 244 public boolean isRequestedSessionIdFromURL() 245 { 246 return false; 247 } 248 249 252 public boolean isRequestedSessionIdFromUrl() 253 { 254 return false; 255 } 256 257 260 public Object getAttribute(String name) 261 { 262 return attributes.get(name); 263 } 264 265 268 public Enumeration getAttributeNames() 269 { 270 return Collections.enumeration(attributes.keySet()); 271 } 272 273 276 public String getCharacterEncoding() 277 { 278 return characterEncoding; 279 } 280 281 284 public void setCharacterEncoding(String characterEncoding) throws UnsupportedEncodingException 285 { 286 this.characterEncoding = characterEncoding; 287 } 288 289 292 public int getContentLength() 293 { 294 return 0; 295 } 296 297 300 public String getContentType() 301 { 302 log.warn("Inventing data in FakeHttpServletRequest.getContentType() to remain plausible."); 303 return "text/plain"; 304 } 305 306 309 public ServletInputStream getInputStream() throws IOException 310 { 311 return new ServletInputStream () 312 { 313 316 public int read() throws IOException 317 { 318 return -1; 319 } 320 }; 321 } 322 323 326 public String getLocalAddr() 327 { 328 log.warn("Inventing data in FakeHttpServletRequest.getLocalAddr() to remain plausible."); 329 return "127.0.0.1"; 330 } 331 332 335 public String getLocalName() 336 { 337 log.warn("Inventing data in FakeHttpServletRequest.getLocalName() to remain plausible."); 338 return "localhost"; 339 } 340 341 344 public int getLocalPort() 345 { 346 log.warn("Inventing data in FakeHttpServletRequest.getLocalPort() to remain plausible."); 347 return 80; 348 } 349 350 353 public String getParameter(String name) 354 { 355 return null; 356 } 357 358 361 public Enumeration getParameterNames() 362 { 363 return new Vector ().elements(); 364 } 365 366 369 public String [] getParameterValues(String name) 370 { 371 return null; 372 } 373 374 377 public Map getParameterMap() 378 { 379 return Collections.EMPTY_MAP; 380 } 381 382 385 public String getProtocol() 386 { 387 log.warn("Inventing data in FakeHttpServletRequest.getProtocol() to remain plausible."); 388 return "HTTP/1.1"; 389 } 390 391 394 public String getScheme() 395 { 396 log.warn("Inventing data in FakeHttpServletRequest.getScheme() to remain plausible."); 397 return "http"; 398 } 399 400 403 public String getServerName() 404 { 405 log.warn("Inventing data in FakeHttpServletRequest.getServerName() to remain plausible."); 406 return "localhost"; 407 } 408 409 412 public int getServerPort() 413 { 414 log.warn("Inventing data in FakeHttpServletRequest.getServerPort() to remain plausible."); 415 return 80; 416 } 417 418 421 public BufferedReader getReader() throws IOException 422 { 423 return new BufferedReader (new StringReader ("")); 424 } 425 426 429 public String getRemoteAddr() 430 { 431 log.warn("Inventing data in FakeHttpServletRequest.getRemoteAddr() to remain plausible."); 432 return "localhost"; 433 } 434 435 438 public String getRemoteHost() 439 { 440 log.warn("Inventing data in FakeHttpServletRequest.getRemoteHost() to remain plausible."); 441 return "localhost"; 442 } 443 444 447 public int getRemotePort() 448 { 449 log.warn("Inventing data in FakeHttpServletRequest.getRemotePort() to remain plausible."); 450 return 80; 451 } 452 453 456 public void setAttribute(String name, Object o) 457 { 458 attributes.put(name, o); 459 } 460 461 464 public void removeAttribute(String name) 465 { 466 attributes.remove(name); 467 } 468 469 472 public Locale getLocale() 473 { 474 return Locale.getDefault(); 475 } 476 477 480 public Enumeration getLocales() 481 { 482 return Collections.enumeration(Arrays.asList(new Locale [] { Locale.getDefault() })); 483 } 484 485 488 public boolean isSecure() 489 { 490 return false; 491 } 492 493 496 public RequestDispatcher getRequestDispatcher(String path) 497 { 498 return new RequestDispatcher () 499 { 500 503 public void include(ServletRequest request, ServletResponse response) throws ServletException , IOException 504 { 505 } 506 507 510 public void forward(ServletRequest request, ServletResponse response) throws ServletException , IOException 511 { 512 } 513 }; 514 } 515 516 519 public String getRealPath(String path) 520 { 521 return null; 522 } 523 524 527 private String characterEncoding = null; 528 529 532 private Map attributes = new HashMap (); 533 534 537 private static final Logger log = Logger.getLogger(FakeHttpServletRequest.class); 538 } 539 | Popular Tags |