| 1 17 18 19 package org.apache.catalina.core; 20 21 import java.io.BufferedReader ; 22 import java.io.File ; 23 import java.io.FileInputStream ; 24 import java.io.FileOutputStream ; 25 import java.io.IOException ; 26 import java.io.InputStream ; 27 import java.io.InputStreamReader ; 28 import java.io.ObjectOutputStream ; 29 import java.io.Serializable ; 30 import java.util.ArrayList ; 31 import java.util.HashMap ; 32 import java.util.Hashtable ; 33 import java.util.Iterator ; 34 import java.util.Stack ; 35 import java.util.TreeMap ; 36 37 import javax.management.AttributeNotFoundException ; 38 import javax.management.ListenerNotFoundException ; 39 import javax.management.MBeanNotificationInfo ; 40 import javax.management.MBeanRegistrationException ; 41 import javax.management.MBeanServer ; 42 import javax.management.MalformedObjectNameException ; 43 import javax.management.Notification ; 44 import javax.management.NotificationBroadcasterSupport ; 45 import javax.management.NotificationEmitter ; 46 import javax.management.NotificationFilter ; 47 import javax.management.NotificationListener ; 48 import javax.management.ObjectName ; 49 import javax.naming.NamingException ; 50 import javax.naming.directory.DirContext ; 51 import javax.servlet.FilterConfig ; 52 import javax.servlet.ServletContext ; 53 import javax.servlet.ServletContextAttributeListener ; 54 import javax.servlet.ServletContextEvent ; 55 import javax.servlet.ServletContextListener ; 56 import javax.servlet.ServletException ; 57 import javax.servlet.ServletRequestAttributeListener ; 58 import javax.servlet.ServletRequestListener ; 59 import javax.servlet.http.HttpSessionAttributeListener ; 60 import javax.servlet.http.HttpSessionListener ; 61 62 import org.apache.AnnotationProcessor; 63 import org.apache.catalina.Container; 64 import org.apache.catalina.ContainerListener; 65 import org.apache.catalina.Context; 66 import org.apache.catalina.Engine; 67 import org.apache.catalina.Globals; 68 import org.apache.catalina.Host; 69 import org.apache.catalina.InstanceListener; 70 import org.apache.catalina.Lifecycle; 71 import org.apache.catalina.LifecycleException; 72 import org.apache.catalina.LifecycleListener; 73 import org.apache.catalina.Loader; 74 import org.apache.catalina.Manager; 75 import org.apache.catalina.Wrapper; 76 import org.apache.catalina.deploy.ApplicationParameter; 77 import org.apache.catalina.deploy.ErrorPage; 78 import org.apache.catalina.deploy.FilterDef; 79 import org.apache.catalina.deploy.FilterMap; 80 import org.apache.catalina.deploy.LoginConfig; 81 import org.apache.catalina.deploy.MessageDestination; 82 import org.apache.catalina.deploy.MessageDestinationRef; 83 import org.apache.catalina.deploy.NamingResources; 84 import org.apache.catalina.deploy.SecurityCollection; 85 import org.apache.catalina.deploy.SecurityConstraint; 86 import org.apache.catalina.loader.WebappLoader; 87 import org.apache.catalina.session.StandardManager; 88 import org.apache.catalina.startup.ContextConfig; 89 import org.apache.catalina.startup.TldConfig; 90 import org.apache.catalina.util.CharsetMapper; 91 import org.apache.catalina.util.DefaultAnnotationProcessor; 92 import org.apache.catalina.util.ExtensionValidator; 93 import org.apache.catalina.util.RequestUtil; 94 import org.apache.catalina.util.URLEncoder; 95 import org.apache.commons.logging.Log; 96 import org.apache.commons.logging.LogFactory; 97 import org.apache.naming.ContextBindings; 98 import org.apache.naming.resources.BaseDirContext; 99 import org.apache.naming.resources.DirContextURLStreamHandler; 100 import org.apache.naming.resources.FileDirContext; 101 import org.apache.naming.resources.ProxyDirContext; 102 import org.apache.naming.resources.WARDirContext; 103 import org.apache.tomcat.util.modeler.Registry; 104 105 114 115 public class StandardContext 116 extends ContainerBase 117 implements Context , Serializable , NotificationEmitter  118 { 119 private static transient Log log = LogFactory.getLog(StandardContext.class); 120 121 122 124 125 128 public StandardContext() { 129 130 super(); 131 pipeline.setBasic(new StandardContextValve()); 132 broadcaster = new NotificationBroadcasterSupport (); 133 134 } 135 136 137 139 140 143 private static final String info = 144 "org.apache.catalina.core.StandardContext/1.0"; 145 146 147 150 protected static URLEncoder urlEncoder; 151 152 153 156 static { 157 urlEncoder = new URLEncoder(); 158 urlEncoder.addSafeCharacter('~'); 159 urlEncoder.addSafeCharacter('-'); 160 urlEncoder.addSafeCharacter('_'); 161 urlEncoder.addSafeCharacter('.'); 162 urlEncoder.addSafeCharacter('*'); 163 urlEncoder.addSafeCharacter('/'); 164 } 165 166 167 169 170 173 private String altDDName = null; 174 175 176 179 private AnnotationProcessor annotationProcessor = null; 180 181 182 185 private String hostName; 186 187 188 191 private boolean antiJARLocking = false; 192 193 194 197 private boolean antiResourceLocking = false; 198 199 200 204 private String applicationListeners[] = new String [0]; 205 206 207 210 private transient Object applicationEventListenersObjects[] = 211 new Object [0]; 212 213 214 217 private transient Object applicationLifecycleListenersObjects[] = 218 new Object [0]; 219 220 221 224 private ApplicationParameter applicationParameters[] = 225 new ApplicationParameter[0]; 226 227 228 231 private boolean available = false; 232 233 236 private NotificationBroadcasterSupport broadcaster = null; 237 238 241 private transient CharsetMapper charsetMapper = null; 242 243 244 247 private String charsetMapperClass = 248 "org.apache.catalina.util.CharsetMapper"; 249 250 251 254 private String configFile = null; 255 256 257 260 private boolean configured = false; 261 262 263 266 private SecurityConstraint constraints[] = new SecurityConstraint[0]; 267 268 269 272 protected transient ApplicationContext context = null; 273 274 275 278 private String compilerClasspath = null; 279 280 281 284 private boolean cookies = true; 285 286 287 291 private boolean crossContext = false; 292 293 294 297 private String encodedPath = null; 298 299 300 304 private boolean delegate = false; 305 306 307 310 private String displayName = null; 311 312 313 316 private String defaultContextXml; 317 318 319 322 private String defaultWebXml; 323 324 325 328 private boolean distributable = false; 329 330 331 334 private String docBase = null; 335 336 337 341 private HashMap exceptionPages = new HashMap (); 342 343 344 348 private HashMap filterConfigs = new HashMap (); 349 350 351 355 private HashMap filterDefs = new HashMap (); 356 357 358 362 private FilterMap filterMaps[] = new FilterMap[0]; 363 364 365 368 private boolean ignoreAnnotations = false; 369 370 371 375 private String instanceListeners[] = new String [0]; 376 377 378 381 private LoginConfig loginConfig = null; 382 383 384 387 private org.apache.tomcat.util.http.mapper.Mapper mapper = 388 new org.apache.tomcat.util.http.mapper.Mapper(); 389 390 391 394 private transient NamingContextListener namingContextListener = null; 395 396 397 400 private NamingResources namingResources = null; 401 402 403 406 private HashMap messageDestinations = new HashMap (); 407 408 409 412 private HashMap mimeMappings = new HashMap (); 413 414 415 418 private ErrorPage okErrorPage = null; 419 420 421 425 private HashMap parameters = new HashMap (); 426 427 428 431 private boolean paused = false; 432 433 434 439 private String publicId = null; 440 441 442 445 private boolean reloadable = false; 446 447 448 451 private boolean unpackWAR = true; 452 453 454 457 private boolean override = false; 458 459 460 463 private String originalDocBase = null; 464 465 466 469 private boolean privileged = false; 470 471 472 479 private boolean replaceWelcomeFiles = false; 480 481 482 486 private HashMap roleMappings = new HashMap (); 487 488 489 492 private String securityRoles[] = new String [0]; 493 494 495 499 private HashMap servletMappings = new HashMap (); 500 501 502 505 private int sessionTimeout = 30; 506 507 510 private long sequenceNumber = 0; 511 512 516 private HashMap statusPages = new HashMap (); 517 518 519 523 private boolean swallowOutput = false; 524 525 526 529 private HashMap taglibs = new HashMap (); 530 531 532 535 private long unloadDelay = 2000; 536 537 538 541 private String watchedResources[] = new String [0]; 542 543 544 547 private String welcomeFiles[] = new String [0]; 548 549 550 554 private String wrapperLifecycles[] = new String [0]; 555 556 557 561 private String wrapperListeners[] = new String [0]; 562 563 564 568 private String workDir = null; 569 570 571 574 private String wrapperClassName = StandardWrapper.class.getName(); 575 private Class wrapperClass = null; 576 577 578 581 private boolean useNaming = true; 582 583 584 587 private boolean filesystemBased = false; 588 589 590 593 private String namingContextName = null; 594 595 596 599 private boolean cachingAllowed = true; 600 601 602 605 protected boolean caseSensitive = true; 606 607 608 611 protected boolean allowLinking = false; 612 613 614 617 protected int cacheMaxSize = 10240; 619 620 623 protected int cacheTTL = 5000; 624 625 626 private boolean lazy=true; 627 628 631 private transient DirContext webappResources = null; 632 633 private long startupTime; 634 private long startTime; 635 private long tldScanTime; 636 637 640 private String engineName = null; 641 private String j2EEApplication="none"; 642 private String j2EEServer="none"; 643 644 645 648 private boolean webXmlValidation = false; 649 650 651 654 private boolean webXmlNamespaceAware = false; 655 656 659 private boolean processTlds = true; 660 661 664 private boolean tldValidation = false; 665 666 667 670 private boolean tldNamespaceAware = false; 671 672 673 676 private boolean saveConfig = true; 677 678 679 681 682 public AnnotationProcessor getAnnotationProcessor() { 683 return annotationProcessor; 684 } 685 686 687 public void setAnnotationProcessor(AnnotationProcessor annotationProcessor) { 688 this.annotationProcessor = annotationProcessor; 689 } 690 691 692 public String getEncodedPath() { 693 return encodedPath; 694 } 695 696 697 public void setName( String name ) { 698 super.setName( name ); 699 encodedPath = urlEncoder.encode(name); 700 } 701 702 703 706 public boolean isCachingAllowed() { 707 return cachingAllowed; 708 } 709 710 711 714 public void setCachingAllowed(boolean cachingAllowed) { 715 this.cachingAllowed = cachingAllowed; 716 } 717 718 719 722 public void setCaseSensitive(boolean caseSensitive) { 723 this.caseSensitive = caseSensitive; 724 } 725 726 727 730 public boolean isCaseSensitive() { 731 return caseSensitive; 732 } 733 734 735 738 public void setAllowLinking(boolean allowLinking) { 739 this.allowLinking = allowLinking; 740 } 741 742 743 746 public boolean isAllowLinking() { 747 return allowLinking; 748 } 749 750 751 754 public void setCacheTTL(int cacheTTL) { 755 this.cacheTTL = cacheTTL; 756 } 757 758 759 762 public int getCacheTTL() { 763 return cacheTTL; 764 } 765 766 767 770 public int getCacheMaxSize() { 771 return cacheMaxSize; 772 } 773 774 775 778 public void setCacheMaxSize(int cacheMaxSize) { 779 this.cacheMaxSize = cacheMaxSize; 780 } 781 782 783 787 public boolean getDelegate() { 788 789 return (this.delegate); 790 791 } 792 793 794 800 public void setDelegate(boolean delegate) { 801 802 boolean oldDelegate = this.delegate; 803 this.delegate = delegate; 804 support.firePropertyChange("delegate", new Boolean (oldDelegate), 805 new Boolean (this.delegate)); 806 807 } 808 809 810 813 public boolean isUseNaming() { 814 815 return (useNaming); 816 817 } 818 819 820 823 public void setUseNaming(boolean useNaming) { 824 this.useNaming = useNaming; 825 } 826 827 828 832 public boolean isFilesystemBased() { 833 834 return (filesystemBased); 835 836 } 837 838 839 847 public Object [] getApplicationEventListeners() { 848 return (applicationEventListenersObjects); 849 } 850 851 852 859 public void setApplicationEventListeners(Object listeners[]) { 860 applicationEventListenersObjects = listeners; 861 } 862 863 864 872 public Object [] getApplicationLifecycleListeners() { 873 return (applicationLifecycleListenersObjects); 874 } 875 876 877 884 public void setApplicationLifecycleListeners(Object listeners[]) { 885 applicationLifecycleListenersObjects = listeners; 886 } 887 888 889 892 public boolean getAntiJARLocking() { 893 894 return (this.antiJARLocking); 895 896 } 897 898 899 902 public boolean getAntiResourceLocking() { 903 904 return (this.antiResourceLocking); 905 906 } 907 908 909 914 public void setAntiJARLocking(boolean antiJARLocking) { 915 916 boolean oldAntiJARLocking = this.antiJARLocking; 917 this.antiJARLocking = antiJARLocking; 918 support.firePropertyChange("antiJARLocking", 919 new Boolean (oldAntiJARLocking), 920 new Boolean (this.antiJARLocking)); 921 922 } 923 924 925 930 public void setAntiResourceLocking(boolean antiResourceLocking) { 931 932 boolean oldAntiResourceLocking = this.antiResourceLocking; 933 this.antiResourceLocking = antiResourceLocking; 934 support.firePropertyChange("antiResourceLocking", 935 new Boolean (oldAntiResourceLocking), 936 new Boolean (this.antiResourceLocking)); 937 938 } 939 940 941 944 public boolean getAvailable() { 945 946 return (this.available); 947 948 } 949 950 951 956 public void setAvailable(boolean available) { 957 958 boolean oldAvailable = this.available; 959 this.available = available; 960 support.firePropertyChange("available", 961 new Boolean (oldAvailable), 962 new Boolean (this.available)); 963 964 } 965 966 967 970 public CharsetMapper getCharsetMapper() { 971 972 if (this.charsetMapper == null) { 974 try { 975 Class clazz = Class.forName(charsetMapperClass); 976 this.charsetMapper = 977 (CharsetMapper) clazz.newInstance(); 978 } catch (Throwable t) { 979 this.charsetMapper = new CharsetMapper(); 980 } 981 } 982 983 return (this.charsetMapper); 984 985 } 986 987 988 993 public void setCharsetMapper(CharsetMapper mapper) { 994 995 CharsetMapper oldCharsetMapper = this.charsetMapper; 996 this.charsetMapper = mapper; 997 <
|