| 1 17 18 19 package org.apache.catalina.connector; 20 21 22 import java.io.InputStream ; 23 import java.io.IOException ; 24 import java.io.BufferedReader ; 25 import java.io.UnsupportedEncodingException ; 26 import java.security.Principal ; 27 import java.text.SimpleDateFormat ; 28 import java.util.ArrayList ; 29 import java.util.Enumeration ; 30 import java.util.HashMap ; 31 import java.util.Iterator ; 32 import java.util.Locale ; 33 import java.util.Map ; 34 import java.util.TimeZone ; 35 import java.util.TreeMap ; 36 37 import javax.security.auth.Subject ; 38 import javax.servlet.FilterChain ; 39 import javax.servlet.RequestDispatcher ; 40 import javax.servlet.ServletContext ; 41 import javax.servlet.ServletInputStream ; 42 import javax.servlet.ServletRequestAttributeEvent ; 43 import javax.servlet.ServletRequestAttributeListener ; 44 import javax.servlet.http.Cookie ; 45 import javax.servlet.http.HttpServletRequest ; 46 import javax.servlet.http.HttpSession ; 47 48 import org.apache.tomcat.util.buf.B2CConverter; 49 import org.apache.tomcat.util.buf.MessageBytes; 50 import org.apache.tomcat.util.buf.StringCache; 51 import org.apache.tomcat.util.http.Cookies; 52 import org.apache.tomcat.util.http.FastHttpDateFormat; 53 import org.apache.tomcat.util.http.Parameters; 54 import org.apache.tomcat.util.http.ServerCookie; 55 import org.apache.tomcat.util.http.mapper.MappingData; 56 57 import org.apache.coyote.ActionCode; 58 59 import org.apache.catalina.Context; 60 import org.apache.catalina.Globals; 61 import org.apache.catalina.Host; 62 import org.apache.catalina.Manager; 63 import org.apache.catalina.Realm; 64 import org.apache.catalina.Session; 65 import org.apache.catalina.Wrapper; 66 import org.apache.catalina.core.ApplicationFilterFactory; 67 import org.apache.catalina.realm.GenericPrincipal; 68 import org.apache.catalina.util.Enumerator; 69 import org.apache.catalina.util.ParameterMap; 70 import org.apache.catalina.util.RequestUtil; 71 import org.apache.catalina.util.StringManager; 72 import org.apache.catalina.util.StringParser; 73 74 75 82 83 public class Request 84 implements HttpServletRequest { 85 86 87 89 90 static { 91 new StringCache.ByteEntry(); 93 new StringCache.CharEntry(); 94 } 95 96 public Request() { 97 98 formats[0].setTimeZone(GMT_ZONE); 99 formats[1].setTimeZone(GMT_ZONE); 100 formats[2].setTimeZone(GMT_ZONE); 101 102 } 103 104 105 107 108 111 protected org.apache.coyote.Request coyoteRequest; 112 113 118 public void setCoyoteRequest(org.apache.coyote.Request coyoteRequest) { 119 this.coyoteRequest = coyoteRequest; 120 inputBuffer.setRequest(coyoteRequest); 121 } 122 123 126 public org.apache.coyote.Request getCoyoteRequest() { 127 return (this.coyoteRequest); 128 } 129 130 131 133 134 protected static final TimeZone GMT_ZONE = TimeZone.getTimeZone("GMT"); 135 136 137 140 protected static StringManager sm = 141 StringManager.getManager(Constants.Package); 142 143 144 147 protected Cookie [] cookies = null; 148 149 150 156 protected SimpleDateFormat formats[] = { 157 new SimpleDateFormat ("EEE, dd MMM yyyy HH:mm:ss zzz", Locale.US), 158 new SimpleDateFormat ("EEEEEE, dd-MMM-yy HH:mm:ss zzz", Locale.US), 159 new SimpleDateFormat ("EEE MMMM d HH:mm:ss yyyy", Locale.US) 160 }; 161 162 163 166 protected static Locale defaultLocale = Locale.getDefault(); 167 168 169 172 protected HashMap attributes = new HashMap (); 173 174 175 178 private HashMap readOnlyAttributes = new HashMap (); 179 180 181 184 protected ArrayList locales = new ArrayList (); 185 186 187 191 private transient HashMap notes = new HashMap (); 192 193 194 197 protected String authType = null; 198 199 200 203 protected CometEventImpl event = null; 204 205 206 209 protected boolean comet = false; 210 211 212 215 protected Object dispatcherType = null; 216 217 218 221 protected InputBuffer inputBuffer = new InputBuffer(); 222 223 224 227 protected CoyoteInputStream inputStream = 228 new CoyoteInputStream(inputBuffer); 229 230 231 234 protected CoyoteReader reader = new CoyoteReader(inputBuffer); 235 236 237 240 protected boolean usingInputStream = false; 241 242 243 246 protected boolean usingReader = false; 247 248 249 252 protected Principal userPrincipal = null; 253 254 255 258 protected boolean sessionParsed = false; 259 260 261 264 protected boolean parametersParsed = false; 265 266 267 270 protected boolean cookiesParsed = false; 271 272 273 276 protected boolean secure = false; 277 278 279 282 protected transient Subject subject = null; 283 284 285 288 protected static int CACHED_POST_LEN = 8192; 289 protected byte[] postData = null; 290 291 292 295 protected ParameterMap parameterMap = new ParameterMap(); 296 297 298 301 protected Session session = null; 302 303 304 307 protected Object requestDispatcherPath = null; 308 309 310 313 protected boolean requestedSessionCookie = false; 314 315 316 319 protected String requestedSessionId = null; 320 321 322 325 protected boolean requestedSessionURL = false; 326 327 328 331 protected boolean localesParsed = false; 332 333 334 337 private StringParser parser = new StringParser(); 338 339 340 343 protected int localPort = -1; 344 345 348 protected String remoteAddr = null; 349 350 351 354 protected String remoteHost = null; 355 356 357 360 protected int remotePort = -1; 361 362 365 protected String localAddr = null; 366 367 368 371 protected String localName = null; 372 373 374 376 377 381 public void recycle() { 382 383 context = null; 384 wrapper = null; 385 386 dispatcherType = null; 387 requestDispatcherPath = null; 388 389 comet = false; 390 if (event != null) { 391 event.clear(); 392 event = null; 393 } 394 395 authType = null; 396 inputBuffer.recycle(); 397 usingInputStream = false; 398 usingReader = false; 399 userPrincipal = null; 400 subject = null; 401 sessionParsed = false; 402 parametersParsed = false; 403 cookiesParsed = false; 404 locales.clear(); 405 localesParsed = false; 406 secure = false; 407 remoteAddr = null; 408 remoteHost = null; 409 remotePort = -1; 410 localPort = -1; 411 localAddr = null; 412 localName = null; 413 414 attributes.clear(); 415 notes.clear(); 416 cookies = null; 417 418 if (session != null) { 419 session.endAccess(); 420 } 421 session = null; 422 requestedSessionCookie = false; 423 requestedSessionId = null; 424 requestedSessionURL = false; 425 426 if (Constants.SECURITY || Connector.RECYCLE_FACADES) { 427 parameterMap = new ParameterMap(); 428 } else { 429 parameterMap.setLocked(false); 430 parameterMap.clear(); 431 } 432 433 mappingData.recycle(); 434 435 if (Constants.SECURITY || Connector.RECYCLE_FACADES) { 436 if (facade != null) { 437 facade.clear(); 438 facade = null; 439 } 440 if (inputStream != null) { 441 inputStream.clear(); 442 inputStream = null; 443 } 444 if (reader != null) { 445 reader.clear(); 446 reader = null; 447 } 448 } 449 450 } 451 452 453 456 public void clearEncoders() { 457 inputBuffer.clearEncoders(); 458 } 459 460 461 463 464 467 protected Connector connector; 468 469 472 public Connector getConnector() { 473 return (this.connector); 474 } 475 476 481 public void setConnector(Connector connector) { 482 this.connector = connector; 483 } 484 485 486 489 protected Context context = null; 490 491 494 public Context getContext() { 495 return (this.context); 496 } 497 498 499 507 public void setContext(Context context) { 508 this.context = context; 509 } 510 511 512 515 protected FilterChain filterChain = null; 516 517 520 public FilterChain getFilterChain() { 521 return (this.filterChain); 522 } 523 524 529 public void setFilterChain(FilterChain filterChain) { 530 this.filterChain = filterChain; 531 } 532 533 534 537 public Host getHost() { 538 if (getContext() == null) 539 return null; 540 return (Host) getContext().getParent(); 541 } 543 544 545 552 public void setHost(Host host) { 553 mappingData.host = host; 554 } 555 556 557 560 protected static final String info = 561 "org.apache.coyote.catalina.CoyoteRequest/1.0"; 562 563 568 public String getInfo() { 569 return (info); 570 } 571 572 573 576 protected MappingData mappingData = new MappingData(); 577 578 581 public MappingData getMappingData() { 582 return (mappingData); 583 } 584 585 586 589 protected RequestFacade facade = null; 590 591 595 public HttpServletRequest getRequest() { 596 if (facade == null) { 597 facade = new RequestFacade(this); 598 } 599 return (facade); 600 } 601 602 603 606 protected org.apache.catalina.connector.Response response = null; 607 608 611 public org.apache.catalina.connector.Response getResponse() { 612 return (this.response); 613 } 614 615 620 public void setResponse(org.apache.catalina.connector.Response response) { 621 this.response = response; 622 } 623 624 627 public InputStream getStream() { 628 if (inputStream == null) { 629 inputStream = new CoyoteInputStream(inputBuffer); 630 } 631 return inputStream; 632 } 633 634 639 public void setStream(InputStream stream) { 640 } 642 643 644 647 protected B2CConverter URIConverter = null; 648 649 652 protected B2CConverter getURIConverter() { 653 return URIConverter; 654 } 655 656 661 protected void setURIConverter(B2CConverter URIConverter) { 662 this.URIConverter = URIConverter; 663 } 664 665 666 669 protected Wrapper wrapper = null; 670 671 674 public Wrapper getWrapper() { 675 return (this.wrapper); 676 } 677 678 679 685 public void setWrapper(Wrapper wrapper) { 686 this.wrapper = wrapper; 687 } 688 689 690 692 693 699 public ServletInputStream createInputStream() 700 throws IOException { 701 if (inputStream == null) { 702 inputStream = new CoyoteInputStream(inputBuffer); 703 } 704 return inputStream; 705 } 706 707 708 714 public void finishRequest() throws IOException { 715 } 717 718 719 725 public Object getNote(String name) { 726 return (notes.get(name)); 727 } 728 729 730 734 public Iterator getNoteNames() { 735 return (notes.keySet().iterator()); 736 } 737 738 739 745 public void removeNote(String name) { 746 notes.remove(name); 747 } 748 749 750 757 public void setNote(String name, Object value) { 758 notes.put(name, value); 759 } 760 761 762 767 public void setContentLength(int length) { 768 } 770 771 772 779 public void setContentType(String type) { 780 } 782 783 784 789 public void setProtocol(String protocol) { 790 } 792 793 794 799 public void setRemoteAddr(String remoteAddr) { 800 } 802 803 804 810 public void setRemoteHost(String remoteHost) { 811 } 813 814 815 821 public void setScheme(String scheme) { 822 } 824 825 826 832 public void setSecure(boolean secure) { 833 this.secure = secure; 834 } 835 836 837 842 public void setServerName(String name) { 843 coyoteRequest.serverName().setString(name); 844 } 845 846 847 852 public void setServerPort(int port) { 853 coyoteRequest.setServerPort(port); 854 } 855 856 857 859 860 866 public Object getAttribute(String name) { 867 868 if (name.equals(Globals.DISPATCHER_TYPE_ATTR)) { 869 return (dispatcherType == null) 870 ? ApplicationFilterFactory.REQUEST_INTEGER 871 : dispatcherType; 872 } else if (name.equals(Globals.DISPATCHER_REQUEST_PATH_ATTR)) { 873 return (requestDispatcherPath == null) 874 ? getRequestPathMB().toString() 875 : requestDispatcherPath.toString(); 876 } 877 878 Object attr=attributes.get(name); 879 880 if(attr!=null) 881 return(attr); 882 883 attr = coyoteRequest.getAttribute(name); 884 if(attr != null) 885 return attr; 886 if( isSSLAttribute(name) ) { 887 coyoteRequest.action(ActionCode.ACTION_REQ_SSL_ATTRIBUTE, 888 coyoteRequest); 889 attr = coyoteRequest.getAttribute(Globals.CERTIFICATES_ATTR); 890 if( attr != null) { 891 attributes.put(Globals.CERTIFICATES_ATTR, attr); 892 } 893 attr = coyoteRequest.getAttribute(Globals.CIPHER_SUITE_ATTR); 894 if(attr != null) { 895 attributes.put(Globals.CIPHER_SUITE_ATTR, attr); 896 } 897 attr = coyoteRequest.getAttribute(Globals.KEY_SIZE_ATTR); 898 if(attr != null) { 899 attributes.put(Globals.KEY_SIZE_ATTR, attr); 900 } 901 attr = coyoteRequest.getAttribute(Globals.SSL_SESSION_ID_ATTR); 902 if(attr != null) { 903 attributes.put(Globals.SSL_SESSION_ID_ATTR, attr); 904 } 905 attr = attributes.get(name); 906 } 907 return attr; 908 } 909 910 911 914 static boolean isSSLAttribute(String name) { 915 return Globals.CERTIFICATES_ATTR.equals(name) || 916 Globals.CIPHER_SUITE_ATTR.equals(name) || 917 Globals.KEY_SIZE_ATTR.equals(name) || 918 Globals.SSL_SESSION_ID_ATTR.equals(name); 919 } 920 921 925 public Enumeration getAttributeNames() { 926 if (isSecure()) { 927 getAttribute(Globals.CERTIFICATES_ATTR); 928 } 929 return new Enumerator(attributes.keySet(), true); 930 } 931 932 933 936 public String getCharacterEncoding() { 937 return (coyoteRequest.getCharacterEncoding()); 938 } 939 940 941 944 public int getContentLength() { 945 return (coyoteRequest.getContentLength()); 946 } 947 948 949 952 public String getContentType() { 953 return (coyoteRequest.getContentType()); 954 } 955 956 957 966 public ServletInputStream getInputStream() throws IOException { 967 968 if (usingReader) 969 throw new IllegalStateException  970 (sm.getString("coyoteRequest.getInputStream.ise")); 971 972 usingInputStream = true; 973 if (inputStream == null) { 974 inputStream = new CoyoteInputStream(inputBuffer); 975 } 976 return inputStream; 977 978 } 979 980 981 987 public Locale getLocale() { 988 989 if (!localesParsed) 990 parseLocales(); 991 992 if (locales.size() > 0) { 993 return ((Locale ) locales.get(0)); 994 } else { 995 return (defaultLocale); 996 } 997 998 } 999 1000 1001 1007 public Enumeration getLocales() { 1008 1009 if (!localesParsed) 1010 parseLocales(); 1011 1012 if (locales.size() > 0) 1013 return (new Enumerator(locales)); 1014 ArrayList results = new ArrayList (); 1015 results.add(defaultLocale); 1016 return (new Enumerator(results)); 1017 1018 } 1019 1020 1021 |