0%

tomcat之Container容器

tomcat之Container容器

连接器负责对外连接,容器负责内部处理。

之前分析tomcat的组件时说过,Container 用于封装Servlet,以及具体处理request请求,Container是一个接口,针对不同级别的容器分为四个子接口:Engine、Host、Context、Wrapper

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
// Container是父接口
public interface Container extends Lifecycle {
/**
* Obtain the JMX domain under which this container will be / has been
* registered.
*
* @return The JMX domain name
*/
public String getDomain();


/**
* Return the Pipeline object that manages the Valves associated with
* this Container.
*
* @return The Pipeline
*/
public Pipeline getPipeline();


/**
* Return a name string (suitable for use by humans) that describes this
* Container. Within the set of child containers belonging to a particular
* parent, Container names must be unique.
*
* @return The human readable name of this container.
*/
public String getName();


/**
* Set a name string (suitable for use by humans) that describes this
* Container. Within the set of child containers belonging to a particular
* parent, Container names must be unique.
*
* @param name New name of this container
*
* @exception IllegalStateException if this Container has already been
* added to the children of a parent Container (after which the name
* may not be changed)
*/
public void setName(String name);


/**
* Get the parent container.
*
* @return Return the Container for which this Container is a child, if
* there is one. If there is no defined parent, return
* <code>null</code>.
*/
public Container getParent();


/**
* Set the parent Container to which this Container is being added as a
* child. This Container may refuse to become attached to the specified
* Container by throwing an exception.
*
* @param container Container to which this Container is being added
* as a child
*
* @exception IllegalArgumentException if this Container refuses to become
* attached to the specified Container
*/
public void setParent(Container container);


/**
* Get the parent class loader.
*
* @return the parent class loader for this component. If not set, return
* {@link #getParent()}.{@link #getParentClassLoader()}. If no
* parent has been set, return the system class loader.
*/
public ClassLoader getParentClassLoader();


/**
* Set the parent class loader for this component. For {@link Context}s
* this call is meaningful only <strong>before</strong> a Loader has
* been configured, and the specified value (if non-null) should be
* passed as an argument to the class loader constructor.
*
* @param parent The new parent class loader
*/
public void setParentClassLoader(ClassLoader parent);


/**
* Obtain the Realm with which this Container is associated.
*
* @return The associated Realm; if there is no associated Realm, the
* Realm associated with the parent Container (if any); otherwise
* return <code>null</code>.
*/
public Realm getRealm();


/**
* Set the Realm with which this Container is associated.
*
* @param realm The newly associated Realm
*/
public void setRealm(Realm realm);


/**
* Add a new child Container to those associated with this Container,
* if supported. Prior to adding this Container to the set of children,
* the child's <code>setParent()</code> method must be called, with this
* Container as an argument. This method may thrown an
* <code>IllegalArgumentException</code> if this Container chooses not
* to be attached to the specified Container, in which case it is not added
*
* @param child New child Container to be added
*
* @exception IllegalArgumentException if this exception is thrown by
* the <code>setParent()</code> method of the child Container
* @exception IllegalArgumentException if the new child does not have
* a name unique from that of existing children of this Container
* @exception IllegalStateException if this Container does not support
* child Containers
*/
public void addChild(Container child);

/**
* Obtain a child Container by name.
*
* @param name Name of the child Container to be retrieved
*
* @return The child Container with the given name or <code>null</code> if
* no such child exists.
*/
public Container findChild(String name);


/**
* Obtain the child Containers associated with this Container.
*
* @return An array containing all children of this container. If this
* Container has no children, a zero-length array is returned.
*/
public Container[] findChildren();


/**
* Remove an existing child Container from association with this parent
* Container.
*
* @param child Existing child Container to be removed
*/
public void removeChild(Container child);
}

四个子容器的装配关系如下:

Engine是最顶层的容器,每个Service最多只能有一个Engine,Engine中可以有多个Host,每个Host下可以有多个Context,每个Context下可以有多个Wrapper

容器装配关系

  • Engine 表示整个Servlet引擎,用来管理多个站点。在tomcat中,Engine为最高级别的容器对象,Engine不是直接处理请求的容器,是获得目标容器的入口,一个Service中最多只有一个Engine,其实现类为StandardEngine,没有父容器,子容器也只能添加Host

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    public interface Engine extends Container {

    /**
    * @return the default host name for this Engine.
    */
    public String getDefaultHost();


    /**
    * Set the default hostname for this Engine.
    *
    * @param defaultHost The new default host
    */
    public void setDefaultHost(String defaultHost);


    /**
    * @return the JvmRouteId for this engine.
    */
    public String getJvmRoute();


    /**
    * Set the JvmRouteId for this engine.
    *
    * @param jvmRouteId the (new) JVM Route ID. Each Engine within a cluster
    * must have a unique JVM Route ID.
    */
    public void setJvmRoute(String jvmRouteId);


    /**
    * @return the <code>Service</code> with which we are associated (if any).
    */
    public Service getService();


    /**
    * Set the <code>Service</code> with which we are associated (if any).
    *
    * @param service The service that owns this Engine
    */
    public void setService(Service service);
    }
  • Host 是Engine容器的子容器,表示Servlet引擎(即Engine)中的虚拟机(即一个站点),与一个服务器的网络名有关,如域名等。客户端可以使用这个网络名连接服务器,这个名称必须要在DNS服务器上注册

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    public interface Host extends Container {


    // ----------------------------------------------------- Manifest Constants


    /**
    * The ContainerEvent event type sent when a new alias is added
    * by <code>addAlias()</code>.
    */
    public static final String ADD_ALIAS_EVENT = "addAlias";


    /**
    * The ContainerEvent event type sent when an old alias is removed
    * by <code>removeAlias()</code>.
    */
    public static final String REMOVE_ALIAS_EVENT = "removeAlias";


    // ------------------------------------------------------------- Properties


    /**
    * @return the XML root for this Host. This can be an absolute
    * pathname, a relative pathname, or a URL.
    * If null, defaults to
    * ${catalina.base}/conf/&lt;engine name&gt;/&lt;host name&gt; directory
    */
    public String getXmlBase();

    /**
    * Set the Xml root for this Host. This can be an absolute
    * pathname, a relative pathname, or a URL.
    * If null, defaults to
    * ${catalina.base}/conf/&lt;engine name&gt;/&lt;host name&gt; directory
    * @param xmlBase The new XML root
    */
    public void setXmlBase(String xmlBase);

    /**
    * @return a default configuration path of this Host. The file will be
    * canonical if possible.
    */
    public File getConfigBaseFile();

    /**
    * @return the application root for this Host. This can be an absolute
    * pathname, a relative pathname, or a URL.
    */
    public String getAppBase();


    /**
    * @return an absolute {@link File} for the appBase of this Host. The file
    * will be canonical if possible. There is no guarantee that that the
    * appBase exists.
    */
    public File getAppBaseFile();


    /**
    * Set the application root for this Host. This can be an absolute
    * pathname, a relative pathname, or a URL.
    *
    * @param appBase The new application root
    */
    public void setAppBase(String appBase);


    /**
    * @return the value of the auto deploy flag. If true, it indicates that
    * this host's child webapps should be discovered and automatically
    * deployed dynamically.
    */
    public boolean getAutoDeploy();


    /**
    * Set the auto deploy flag value for this host.
    *
    * @param autoDeploy The new auto deploy flag
    */
    public void setAutoDeploy(boolean autoDeploy);


    /**
    * @return the Java class name of the context configuration class
    * for new web applications.
    */
    public String getConfigClass();


    /**
    * Set the Java class name of the context configuration class
    * for new web applications.
    *
    * @param configClass The new context configuration class
    */
    public void setConfigClass(String configClass);


    /**
    * @return the value of the deploy on startup flag. If true, it indicates
    * that this host's child webapps should be discovered and automatically
    * deployed.
    */
    public boolean getDeployOnStartup();


    /**
    * Set the deploy on startup flag value for this host.
    *
    * @param deployOnStartup The new deploy on startup flag
    */
    public void setDeployOnStartup(boolean deployOnStartup);


    /**
    * @return the regular expression that defines the files and directories in
    * the host's appBase that will be ignored by the automatic deployment
    * process.
    */
    public String getDeployIgnore();


    /**
    * @return the compiled regular expression that defines the files and
    * directories in the host's appBase that will be ignored by the automatic
    * deployment process.
    */
    public Pattern getDeployIgnorePattern();


    /**
    * Set the regular expression that defines the files and directories in
    * the host's appBase that will be ignored by the automatic deployment
    * process.
    *
    * @param deployIgnore A regular expression matching file names
    */
    public void setDeployIgnore(String deployIgnore);


    /**
    * @return the executor that is used for starting and stopping contexts. This
    * is primarily for use by components deploying contexts that want to do
    * this in a multi-threaded manner.
    */
    public ExecutorService getStartStopExecutor();


    /**
    * Returns <code>true</code> if the Host will attempt to create directories for appBase and xmlBase
    * unless they already exist.
    * @return true if the Host will attempt to create directories
    */
    public boolean getCreateDirs();


    /**
    * Should the Host attempt to create directories for xmlBase and appBase
    * upon startup.
    *
    * @param createDirs The new value for this flag
    */
    public void setCreateDirs(boolean createDirs);


    /**
    * @return <code>true</code> of the Host is configured to automatically undeploy old
    * versions of applications deployed using parallel deployment. This only
    * takes effect is {@link #getAutoDeploy()} also returns <code>true</code>.
    */
    public boolean getUndeployOldVersions();


    /**
    * Set to <code>true</code> if the Host should automatically undeploy old versions of
    * applications deployed using parallel deployment. This only takes effect
    * if {@link #getAutoDeploy()} returns <code>true</code>.
    *
    * @param undeployOldVersions The new value for this flag
    */
    public void setUndeployOldVersions(boolean undeployOldVersions);


    // --------------------------------------------------------- Public Methods

    /**
    * Add an alias name that should be mapped to this same Host.
    *
    * @param alias The alias to be added
    */
    public void addAlias(String alias);


    /**
    * @return the set of alias names for this Host. If none are defined,
    * a zero length array is returned.
    */
    public String[] findAliases();


    /**
    * Remove the specified alias name from the aliases for this Host.
    *
    * @param alias Alias name to be removed
    */
    public void removeAlias(String alias);
    }
  • Context 表示ServletContext即一个应用程序,在Servlet规范中,一个ServletContext即表示一个独立的Web应用,直接管理Servlet在容器中的包装类Wrapper

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    502
    503
    504
    505
    506
    507
    508
    509
    510
    511
    512
    513
    514
    515
    516
    517
    518
    519
    520
    521
    522
    523
    524
    525
    526
    527
    528
    529
    530
    531
    532
    533
    534
    535
    536
    537
    538
    539
    540
    541
    542
    543
    544
    545
    546
    547
    548
    549
    550
    551
    552
    553
    554
    555
    556
    557
    558
    559
    560
    561
    562
    563
    564
    565
    566
    567
    568
    569
    570
    571
    572
    573
    574
    575
    576
    577
    578
    579
    580
    581
    582
    583
    584
    585
    586
    587
    588
    589
    590
    591
    592
    593
    594
    595
    596
    597
    598
    599
    600
    601
    602
    603
    604
    605
    606
    607
    608
    609
    610
    611
    612
    613
    614
    615
    616
    617
    618
    619
    620
    621
    622
    623
    624
    625
    626
    627
    628
    629
    630
    631
    632
    633
    634
    635
    636
    637
    638
    639
    640
    641
    642
    643
    644
    645
    646
    647
    648
    649
    650
    651
    652
    653
    654
    655
    656
    657
    658
    659
    660
    661
    662
    663
    664
    665
    666
    667
    668
    669
    670
    671
    672
    673
    674
    675
    676
    677
    678
    679
    680
    681
    682
    683
    684
    685
    686
    687
    688
    689
    690
    691
    692
    693
    694
    695
    696
    697
    698
    699
    700
    701
    702
    703
    704
    705
    706
    707
    708
    709
    710
    711
    712
    713
    714
    715
    716
    717
    718
    719
    720
    721
    722
    723
    724
    725
    726
    727
    728
    729
    730
    731
    732
    733
    734
    735
    736
    737
    738
    739
    740
    741
    742
    743
    744
    745
    746
    747
    748
    749
    750
    751
    752
    753
    754
    755
    756
    757
    758
    759
    760
    761
    762
    763
    764
    765
    766
    767
    768
    769
    770
    771
    772
    773
    774
    775
    776
    777
    778
    779
    780
    781
    782
    783
    784
    785
    786
    787
    788
    789
    790
    791
    792
    793
    794
    795
    796
    797
    798
    799
    800
    801
    802
    803
    804
    805
    806
    807
    808
    809
    810
    811
    812
    813
    814
    815
    816
    817
    818
    819
    820
    821
    822
    823
    824
    825
    826
    827
    828
    829
    830
    831
    832
    833
    834
    835
    836
    837
    838
    839
    840
    841
    842
    843
    844
    845
    846
    847
    848
    849
    850
    851
    852
    853
    854
    855
    856
    857
    858
    859
    860
    861
    862
    863
    864
    865
    866
    867
    868
    869
    870
    871
    872
    873
    874
    875
    876
    877
    878
    879
    880
    881
    882
    883
    884
    885
    886
    887
    888
    889
    890
    891
    892
    893
    894
    895
    896
    897
    898
    899
    900
    901
    902
    903
    904
    905
    906
    907
    908
    909
    910
    911
    912
    913
    914
    915
    916
    917
    918
    919
    920
    921
    922
    923
    924
    925
    926
    927
    928
    929
    930
    931
    932
    933
    934
    935
    936
    937
    938
    939
    940
    941
    942
    943
    944
    945
    946
    947
    948
    949
    950
    951
    952
    953
    954
    955
    956
    957
    958
    959
    960
    961
    962
    963
    964
    965
    966
    967
    968
    969
    970
    971
    972
    973
    974
    975
    976
    977
    978
    979
    980
    981
    982
    983
    984
    985
    986
    987
    988
    989
    990
    991
    992
    993
    994
    995
    996
    997
    998
    999
    1000
    1001
    1002
    1003
    1004
    1005
    1006
    1007
    1008
    1009
    1010
    1011
    1012
    1013
    1014
    1015
    1016
    1017
    1018
    1019
    1020
    1021
    1022
    1023
    1024
    1025
    1026
    1027
    1028
    1029
    1030
    1031
    1032
    1033
    1034
    1035
    1036
    1037
    1038
    1039
    1040
    1041
    1042
    1043
    1044
    1045
    1046
    1047
    1048
    1049
    1050
    1051
    1052
    1053
    1054
    1055
    1056
    1057
    1058
    1059
    1060
    1061
    1062
    1063
    1064
    1065
    1066
    1067
    1068
    1069
    1070
    1071
    1072
    1073
    1074
    1075
    1076
    1077
    1078
    1079
    1080
    1081
    1082
    1083
    1084
    1085
    1086
    1087
    1088
    1089
    1090
    1091
    1092
    1093
    1094
    1095
    1096
    1097
    1098
    1099
    1100
    1101
    1102
    1103
    1104
    1105
    1106
    1107
    1108
    1109
    1110
    1111
    1112
    1113
    1114
    1115
    1116
    1117
    1118
    1119
    1120
    1121
    1122
    1123
    1124
    1125
    1126
    1127
    1128
    1129
    1130
    1131
    1132
    1133
    1134
    1135
    1136
    1137
    1138
    1139
    1140
    1141
    1142
    1143
    1144
    1145
    1146
    1147
    1148
    1149
    1150
    1151
    1152
    1153
    1154
    1155
    1156
    1157
    1158
    1159
    1160
    1161
    1162
    1163
    1164
    1165
    1166
    1167
    1168
    1169
    1170
    1171
    1172
    1173
    1174
    1175
    1176
    1177
    1178
    1179
    1180
    1181
    1182
    1183
    1184
    1185
    1186
    1187
    1188
    1189
    1190
    1191
    1192
    1193
    1194
    1195
    1196
    1197
    1198
    1199
    1200
    1201
    1202
    1203
    1204
    1205
    1206
    1207
    1208
    1209
    1210
    1211
    1212
    1213
    1214
    1215
    1216
    1217
    1218
    1219
    1220
    1221
    1222
    1223
    1224
    1225
    1226
    1227
    1228
    1229
    1230
    1231
    1232
    1233
    1234
    1235
    1236
    1237
    1238
    1239
    1240
    1241
    1242
    1243
    1244
    1245
    1246
    1247
    1248
    1249
    1250
    1251
    1252
    1253
    1254
    1255
    1256
    1257
    1258
    1259
    1260
    1261
    1262
    1263
    1264
    1265
    1266
    1267
    1268
    1269
    1270
    1271
    1272
    1273
    1274
    1275
    1276
    1277
    1278
    1279
    1280
    1281
    1282
    1283
    1284
    1285
    1286
    1287
    1288
    1289
    1290
    1291
    1292
    1293
    1294
    1295
    1296
    1297
    1298
    1299
    1300
    1301
    1302
    1303
    1304
    1305
    1306
    1307
    1308
    1309
    1310
    1311
    1312
    1313
    1314
    1315
    1316
    1317
    1318
    1319
    1320
    1321
    1322
    1323
    1324
    1325
    1326
    1327
    1328
    1329
    1330
    1331
    1332
    1333
    1334
    1335
    1336
    1337
    1338
    1339
    1340
    1341
    1342
    1343
    1344
    1345
    1346
    1347
    1348
    1349
    1350
    1351
    1352
    1353
    1354
    1355
    1356
    1357
    1358
    1359
    1360
    1361
    1362
    1363
    1364
    1365
    1366
    1367
    1368
    1369
    1370
    1371
    1372
    1373
    1374
    1375
    1376
    1377
    1378
    1379
    1380
    1381
    1382
    1383
    1384
    1385
    1386
    1387
    1388
    1389
    1390
    1391
    1392
    1393
    1394
    1395
    1396
    1397
    1398
    1399
    1400
    1401
    1402
    1403
    1404
    1405
    1406
    1407
    1408
    1409
    1410
    1411
    1412
    1413
    1414
    1415
    1416
    1417
    1418
    1419
    1420
    1421
    1422
    1423
    1424
    1425
    1426
    1427
    1428
    1429
    1430
    1431
    1432
    1433
    1434
    1435
    1436
    1437
    1438
    1439
    1440
    1441
    1442
    1443
    1444
    1445
    1446
    1447
    1448
    1449
    1450
    1451
    1452
    1453
    1454
    1455
    1456
    1457
    1458
    1459
    1460
    1461
    1462
    1463
    1464
    1465
    1466
    1467
    1468
    1469
    1470
    1471
    1472
    1473
    1474
    1475
    1476
    1477
    1478
    1479
    1480
    1481
    1482
    1483
    1484
    1485
    1486
    1487
    1488
    1489
    1490
    1491
    1492
    1493
    1494
    1495
    1496
    1497
    1498
    1499
    1500
    1501
    1502
    1503
    1504
    1505
    1506
    1507
    1508
    1509
    1510
    1511
    1512
    1513
    1514
    1515
    1516
    1517
    1518
    1519
    1520
    1521
    1522
    1523
    1524
    1525
    1526
    1527
    1528
    1529
    1530
    1531
    1532
    1533
    1534
    1535
    1536
    1537
    1538
    1539
    1540
    1541
    1542
    1543
    1544
    1545
    1546
    1547
    1548
    1549
    1550
    1551
    1552
    1553
    1554
    1555
    1556
    1557
    1558
    1559
    1560
    1561
    1562
    1563
    1564
    1565
    1566
    1567
    1568
    1569
    1570
    1571
    1572
    1573
    1574
    1575
    1576
    1577
    1578
    1579
    1580
    1581
    1582
    1583
    1584
    1585
    1586
    1587
    1588
    1589
    1590
    1591
    1592
    1593
    1594
    1595
    1596
    1597
    1598
    1599
    1600
    1601
    1602
    1603
    1604
    1605
    1606
    1607
    1608
    1609
    1610
    1611
    1612
    1613
    1614
    1615
    1616
    1617
    1618
    1619
    1620
    1621
    1622
    1623
    1624
    1625
    1626
    1627
    1628
    1629
    1630
    1631
    1632
    1633
    1634
    1635
    1636
    1637
    1638
    1639
    1640
    1641
    1642
    1643
    1644
    1645
    1646
    1647
    1648
    1649
    1650
    1651
    1652
    1653
    1654
    1655
    1656
    1657
    1658
    1659
    1660
    1661
    1662
    1663
    1664
    1665
    1666
    1667
    1668
    1669
    1670
    1671
    1672
    1673
    1674
    1675
    1676
    1677
    1678
    1679
    1680
    1681
    1682
    1683
    1684
    1685
    1686
    1687
    1688
    1689
    1690
    1691
    1692
    1693
    1694
    1695
    1696
    1697
    1698
    1699
    1700
    1701
    1702
    1703
    1704
    1705
    1706
    1707
    1708
    1709
    1710
    1711
    1712
    1713
    1714
    1715
    1716
    1717
    1718
    1719
    1720
    1721
    1722
    1723
    1724
    1725
    1726
    1727
    1728
    1729
    1730
    1731
    1732
    1733
    1734
    1735
    1736
    1737
    1738
    1739
    1740
    1741
    1742
    1743
    1744
    1745
    1746
    1747
    1748
    1749
    1750
    1751
    1752
    1753
    1754
    1755
    1756
    1757
    1758
    1759
    1760
    1761
    1762
    1763
    1764
    1765
    1766
    1767
    1768
    1769
    1770
    1771
    1772
    1773
    1774
    1775
    1776
    1777
    1778
    1779
    1780
    1781
    1782
    1783
    1784
    1785
    1786
    1787
    1788
    1789
    1790
    1791
    public interface Context extends Container, ContextBind {


    // ----------------------------------------------------- Manifest Constants

    /**
    * Container event for adding a welcome file.
    */
    public static final String ADD_WELCOME_FILE_EVENT = "addWelcomeFile";

    /**
    * Container event for removing a wrapper.
    */
    public static final String REMOVE_WELCOME_FILE_EVENT = "removeWelcomeFile";

    /**
    * Container event for clearing welcome files.
    */
    public static final String CLEAR_WELCOME_FILES_EVENT = "clearWelcomeFiles";

    /**
    * Container event for changing the ID of a session.
    */
    public static final String CHANGE_SESSION_ID_EVENT = "changeSessionId";


    // ------------------------------------------------------------- Properties

    /**
    * Returns <code>true</code> if requests mapped to servlets without
    * "multipart config" to parse multipart/form-data requests anyway.
    *
    * @return <code>true</code> if requests mapped to servlets without
    * "multipart config" to parse multipart/form-data requests,
    * <code>false</code> otherwise.
    */
    public boolean getAllowCasualMultipartParsing();


    /**
    * Set to <code>true</code> to allow requests mapped to servlets that
    * do not explicitly declare @MultipartConfig or have
    * &lt;multipart-config&gt; specified in web.xml to parse
    * multipart/form-data requests.
    *
    * @param allowCasualMultipartParsing <code>true</code> to allow such
    * casual parsing, <code>false</code> otherwise.
    */
    public void setAllowCasualMultipartParsing(boolean allowCasualMultipartParsing);


    /**
    * Obtain the registered application event listeners.
    *
    * @return An array containing the application event listener instances for
    * this web application in the order they were specified in the web
    * application deployment descriptor
    */
    public Object[] getApplicationEventListeners();


    /**
    * Store the set of initialized application event listener objects,
    * in the order they were specified in the web application deployment
    * descriptor, for this application.
    *
    * @param listeners The set of instantiated listener objects.
    */
    public void setApplicationEventListeners(Object listeners[]);


    /**
    * Obtain the registered application lifecycle listeners.
    *
    * @return An array containing the application lifecycle listener instances
    * for this web application in the order they were specified in the
    * web application deployment descriptor
    */
    public Object[] getApplicationLifecycleListeners();


    /**
    * Store the set of initialized application lifecycle listener objects,
    * in the order they were specified in the web application deployment
    * descriptor, for this application.
    *
    * @param listeners The set of instantiated listener objects.
    */
    public void setApplicationLifecycleListeners(Object listeners[]);


    /**
    * Obtain the character set name to use with the given Locale. Note that
    * different Contexts may have different mappings of Locale to character
    * set.
    *
    * @param locale The locale for which the mapped character set should be
    * returned
    *
    * @return The name of the character set to use with the given Locale
    */
    public String getCharset(Locale locale);


    /**
    * Return the URL of the XML descriptor for this context.
    *
    * @return The URL of the XML descriptor for this context
    */
    public URL getConfigFile();


    /**
    * Set the URL of the XML descriptor for this context.
    *
    * @param configFile The URL of the XML descriptor for this context.
    */
    public void setConfigFile(URL configFile);


    /**
    * Return the "correctly configured" flag for this Context.
    *
    * @return <code>true</code> if the Context has been correctly configured,
    * otherwise <code>false</code>
    */
    public boolean getConfigured();


    /**
    * Set the "correctly configured" flag for this Context. This can be
    * set to false by startup listeners that detect a fatal configuration
    * error to avoid the application from being made available.
    *
    * @param configured The new correctly configured flag
    */
    public void setConfigured(boolean configured);


    /**
    * Return the "use cookies for session ids" flag.
    *
    * @return <code>true</code> if it is permitted to use cookies to track
    * session IDs for this web application, otherwise
    * <code>false</code>
    */
    public boolean getCookies();


    /**
    * Set the "use cookies for session ids" flag.
    *
    * @param cookies The new flag
    */
    public void setCookies(boolean cookies);


    /**
    * Gets the name to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @return The value of the default session cookie name or null if not
    * specified
    */
    public String getSessionCookieName();


    /**
    * Sets the name to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @param sessionCookieName The name to use
    */
    public void setSessionCookieName(String sessionCookieName);


    /**
    * Gets the value of the use HttpOnly cookies for session cookies flag.
    *
    * @return <code>true</code> if the HttpOnly flag should be set on session
    * cookies
    */
    public boolean getUseHttpOnly();


    /**
    * Sets the use HttpOnly cookies for session cookies flag.
    *
    * @param useHttpOnly Set to <code>true</code> to use HttpOnly cookies
    * for session cookies
    */
    public void setUseHttpOnly(boolean useHttpOnly);


    /**
    * Gets the domain to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @return The value of the default session cookie domain or null if not
    * specified
    */
    public String getSessionCookieDomain();


    /**
    * Sets the domain to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @param sessionCookieDomain The domain to use
    */
    public void setSessionCookieDomain(String sessionCookieDomain);


    /**
    * Gets the path to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @return The value of the default session cookie path or null if not
    * specified
    */
    public String getSessionCookiePath();


    /**
    * Sets the path to use for session cookies. Overrides any setting that
    * may be specified by the application.
    *
    * @param sessionCookiePath The path to use
    */
    public void setSessionCookiePath(String sessionCookiePath);


    /**
    * Is a / added to the end of the session cookie path to ensure browsers,
    * particularly IE, don't send a session cookie for context /foo with
    * requests intended for context /foobar.
    *
    * @return <code>true</code> if the slash is added, otherwise
    * <code>false</code>
    */
    public boolean getSessionCookiePathUsesTrailingSlash();


    /**
    * Configures if a / is added to the end of the session cookie path to
    * ensure browsers, particularly IE, don't send a session cookie for context
    * /foo with requests intended for context /foobar.
    *
    * @param sessionCookiePathUsesTrailingSlash <code>true</code> if the
    * slash is should be added,
    * otherwise <code>false</code>
    */
    public void setSessionCookiePathUsesTrailingSlash(
    boolean sessionCookiePathUsesTrailingSlash);


    /**
    * Return the "allow crossing servlet contexts" flag.
    *
    * @return <code>true</code> if cross-contest requests are allowed from this
    * web applications, otherwise <code>false</code>
    */
    public boolean getCrossContext();


    /**
    * Return the alternate Deployment Descriptor name.
    *
    * @return the name
    */
    public String getAltDDName();


    /**
    * Set an alternate Deployment Descriptor name.
    *
    * @param altDDName The new name
    */
    public void setAltDDName(String altDDName) ;


    /**
    * Set the "allow crossing servlet contexts" flag.
    *
    * @param crossContext The new cross contexts flag
    */
    public void setCrossContext(boolean crossContext);


    /**
    * Return the deny-uncovered-http-methods flag for this web application.
    *
    * @return The current value of the flag
    */
    public boolean getDenyUncoveredHttpMethods();


    /**
    * Set the deny-uncovered-http-methods flag for this web application.
    *
    * @param denyUncoveredHttpMethods The new deny-uncovered-http-methods flag
    */
    public void setDenyUncoveredHttpMethods(boolean denyUncoveredHttpMethods);


    /**
    * Return the display name of this web application.
    *
    * @return The display name
    */
    public String getDisplayName();


    /**
    * Set the display name of this web application.
    *
    * @param displayName The new display name
    */
    public void setDisplayName(String displayName);


    /**
    * Get the distributable flag for this web application.
    *
    * @return The value of the distributable flag for this web application.
    */
    public boolean getDistributable();


    /**
    * Set the distributable flag for this web application.
    *
    * @param distributable The new distributable flag
    */
    public void setDistributable(boolean distributable);


    /**
    * Obtain the document root for this Context.
    *
    * @return An absolute pathname, a relative pathname, or a URL.
    */
    public String getDocBase();


    /**
    * Set the document root for this Context. This can be an absolute
    * pathname, a relative pathname, or a URL.
    *
    * @param docBase The new document root
    */
    public void setDocBase(String docBase);


    /**
    * Return the URL encoded context path
    *
    * @return The URL encoded (with UTF-8) context path
    */
    public String getEncodedPath();


    /**
    * Determine if annotations parsing is currently disabled
    *
    * @return {@code true} if annotation parsing is disabled for this web
    * application
    */
    public boolean getIgnoreAnnotations();


    /**
    * Set the boolean on the annotations parsing for this web
    * application.
    *
    * @param ignoreAnnotations The boolean on the annotations parsing
    */
    public void setIgnoreAnnotations(boolean ignoreAnnotations);


    /**
    * @return the login configuration descriptor for this web application.
    */
    public LoginConfig getLoginConfig();


    /**
    * Set the login configuration descriptor for this web application.
    *
    * @param config The new login configuration
    */
    public void setLoginConfig(LoginConfig config);


    /**
    * @return the naming resources associated with this web application.
    */
    public NamingResourcesImpl getNamingResources();


    /**
    * Set the naming resources for this web application.
    *
    * @param namingResources The new naming resources
    */
    public void setNamingResources(NamingResourcesImpl namingResources);


    /**
    * @return the context path for this web application.
    */
    public String getPath();


    /**
    * Set the context path for this web application.
    *
    * @param path The new context path
    */
    public void setPath(String path);


    /**
    * @return the public identifier of the deployment descriptor DTD that is
    * currently being parsed.
    */
    public String getPublicId();


    /**
    * Set the public identifier of the deployment descriptor DTD that is
    * currently being parsed.
    *
    * @param publicId The public identifier
    */
    public void setPublicId(String publicId);


    /**
    * @return the reloadable flag for this web application.
    */
    public boolean getReloadable();


    /**
    * Set the reloadable flag for this web application.
    *
    * @param reloadable The new reloadable flag
    */
    public void setReloadable(boolean reloadable);


    /**
    * @return the override flag for this web application.
    */
    public boolean getOverride();


    /**
    * Set the override flag for this web application.
    *
    * @param override The new override flag
    */
    public void setOverride(boolean override);


    /**
    * @return the privileged flag for this web application.
    */
    public boolean getPrivileged();


    /**
    * Set the privileged flag for this web application.
    *
    * @param privileged The new privileged flag
    */
    public void setPrivileged(boolean privileged);


    /**
    * @return the Servlet context for which this Context is a facade.
    */
    public ServletContext getServletContext();


    /**
    * @return the default session timeout (in minutes) for this
    * web application.
    */
    public int getSessionTimeout();


    /**
    * Set the default session timeout (in minutes) for this
    * web application.
    *
    * @param timeout The new default session timeout
    */
    public void setSessionTimeout(int timeout);


    /**
    * Returns <code>true</code> if remaining request data will be read
    * (swallowed) even the request violates a data size constraint.
    *
    * @return <code>true</code> if data will be swallowed (default),
    * <code>false</code> otherwise.
    */
    public boolean getSwallowAbortedUploads();


    /**
    * Set to <code>false</code> to disable request data swallowing
    * after an upload was aborted due to size constraints.
    *
    * @param swallowAbortedUploads <code>false</code> to disable
    * swallowing, <code>true</code> otherwise (default).
    */
    public void setSwallowAbortedUploads(boolean swallowAbortedUploads);

    /**
    * @return the value of the swallowOutput flag.
    */
    public boolean getSwallowOutput();


    /**
    * Set the value of the swallowOutput flag. If set to true, the system.out
    * and system.err will be redirected to the logger during a servlet
    * execution.
    *
    * @param swallowOutput The new value
    */
    public void setSwallowOutput(boolean swallowOutput);


    /**
    * @return the Java class name of the Wrapper implementation used
    * for servlets registered in this Context.
    */
    public String getWrapperClass();


    /**
    * Set the Java class name of the Wrapper implementation used
    * for servlets registered in this Context.
    *
    * @param wrapperClass The new wrapper class
    */
    public void setWrapperClass(String wrapperClass);


    /**
    * Will the parsing of web.xml and web-fragment.xml files for this Context
    * be performed by a namespace aware parser?
    *
    * @return true if namespace awareness is enabled.
    */
    public boolean getXmlNamespaceAware();


    /**
    * Controls whether the parsing of web.xml and web-fragment.xml files for
    * this Context will be performed by a namespace aware parser.
    *
    * @param xmlNamespaceAware true to enable namespace awareness
    */
    public void setXmlNamespaceAware(boolean xmlNamespaceAware);


    /**
    * Will the parsing of web.xml and web-fragment.xml files for this Context
    * be performed by a validating parser?
    *
    * @return true if validation is enabled.
    */
    public boolean getXmlValidation();


    /**
    * Controls whether the parsing of web.xml and web-fragment.xml files
    * for this Context will be performed by a validating parser.
    *
    * @param xmlValidation true to enable xml validation
    */
    public void setXmlValidation(boolean xmlValidation);


    /**
    * Will the parsing of web.xml, web-fragment.xml, *.tld, *.jspx, *.tagx and
    * tagplugin.xml files for this Context block the use of external entities?
    *
    * @return true if access to external entities is blocked
    */
    public boolean getXmlBlockExternal();


    /**
    * Controls whether the parsing of web.xml, web-fragment.xml, *.tld, *.jspx,
    * *.tagx and tagplugin.xml files for this Context will block the use of
    * external entities.
    *
    * @param xmlBlockExternal true to block external entities
    */
    public void setXmlBlockExternal(boolean xmlBlockExternal);


    /**
    * Will the parsing of *.tld files for this Context be performed by a
    * validating parser?
    *
    * @return true if validation is enabled.
    */
    public boolean getTldValidation();


    /**
    * Controls whether the parsing of *.tld files for this Context will be
    * performed by a validating parser.
    *
    * @param tldValidation true to enable xml validation
    */
    public void setTldValidation(boolean tldValidation);


    /**
    * Get the Jar Scanner to be used to scan for JAR resources for this
    * context.
    * @return The Jar Scanner configured for this context.
    */
    public JarScanner getJarScanner();

    /**
    * Set the Jar Scanner to be used to scan for JAR resources for this
    * context.
    * @param jarScanner The Jar Scanner to be used for this context.
    */
    public void setJarScanner(JarScanner jarScanner);

    /**
    * @return the {@link Authenticator} that is used by this context or
    * <code>null</code> if none is used.
    */
    public Authenticator getAuthenticator();

    /**
    * Set whether or not the effective web.xml for this context should be
    * logged on context start.
    *
    * @param logEffectiveWebXml set to <code>true</code> to log the complete
    * web.xml that will be used for the webapp
    */
    public void setLogEffectiveWebXml(boolean logEffectiveWebXml);

    /**
    * Should the effective web.xml for this context be logged on context start?
    *
    * @return true if the reconstructed web.xml that will be used for the
    * webapp should be logged
    */
    public boolean getLogEffectiveWebXml();

    /**
    * @return the instance manager associated with this context.
    */
    public InstanceManager getInstanceManager();

    /**
    * Set the instance manager associated with this context.
    *
    * @param instanceManager the new instance manager instance
    */
    public void setInstanceManager(InstanceManager instanceManager);

    /**
    * Sets the regular expression that specifies which container provided SCIs
    * should be filtered out and not used for this context. Matching uses
    * {@link java.util.regex.Matcher#find()} so the regular expression only has
    * to match a sub-string of the fully qualified class name of the container
    * provided SCI for it to be filtered out.
    *
    * @param containerSciFilter The regular expression against which the fully
    * qualified class name of each container provided
    * SCI should be checked
    */
    public void setContainerSciFilter(String containerSciFilter);

    /**
    * Obtains the regular expression that specifies which container provided
    * SCIs should be filtered out and not used for this context. Matching uses
    * {@link java.util.regex.Matcher#find()} so the regular expression only has
    * to match a sub-string of the fully qualified class name of the container
    * provided SCI for it to be filtered out.
    *
    * @return The regular expression against which the fully qualified class
    * name of each container provided SCI will be checked
    */
    public String getContainerSciFilter();


    // --------------------------------------------------------- Public Methods

    /**
    * Add a new Listener class name to the set of Listeners
    * configured for this application.
    *
    * @param listener Java class name of a listener class
    */
    public void addApplicationListener(String listener);


    /**
    * Add a new application parameter for this application.
    *
    * @param parameter The new application parameter
    */
    public void addApplicationParameter(ApplicationParameter parameter);


    /**
    * Add a security constraint to the set for this web application.
    *
    * @param constraint The security constraint that should be added
    */
    public void addConstraint(SecurityConstraint constraint);


    /**
    * Add an error page for the specified error or Java exception.
    *
    * @param errorPage The error page definition to be added
    */
    public void addErrorPage(ErrorPage errorPage);


    /**
    * Add a filter definition to this Context.
    *
    * @param filterDef The filter definition to be added
    */
    public void addFilterDef(FilterDef filterDef);


    /**
    * Add a filter mapping to this Context.
    *
    * @param filterMap The filter mapping to be added
    */
    public void addFilterMap(FilterMap filterMap);

    /**
    * Add a filter mapping to this Context before the mappings defined in the
    * deployment descriptor but after any other mappings added via this method.
    *
    * @param filterMap The filter mapping to be added
    *
    * @exception IllegalArgumentException if the specified filter name
    * does not match an existing filter definition, or the filter mapping
    * is malformed
    */
    public void addFilterMapBefore(FilterMap filterMap);


    /**
    * Add a Locale Encoding Mapping (see Sec 5.4 of Servlet spec 2.4)
    *
    * @param locale locale to map an encoding for
    * @param encoding encoding to be used for a give locale
    */
    public void addLocaleEncodingMappingParameter(String locale, String encoding);


    /**
    * Add a new MIME mapping, replacing any existing mapping for
    * the specified extension.
    *
    * @param extension Filename extension being mapped
    * @param mimeType Corresponding MIME type
    */
    public void addMimeMapping(String extension, String mimeType);


    /**
    * Add a new context initialization parameter, replacing any existing
    * value for the specified name.
    *
    * @param name Name of the new parameter
    * @param value Value of the new parameter
    */
    public void addParameter(String name, String value);


    /**
    * Add a security role reference for this web application.
    *
    * @param role Security role used in the application
    * @param link Actual security role to check for
    */
    public void addRoleMapping(String role, String link);


    /**
    * Add a new security role for this web application.
    *
    * @param role New security role
    */
    public void addSecurityRole(String role);


    /**
    * Add a new servlet mapping, replacing any existing mapping for
    * the specified pattern.
    *
    * @param pattern URL pattern to be mapped. The pattern will be % decoded
    * using UTF-8
    * @param name Name of the corresponding servlet to execute
    *
    * @deprecated Will be removed in Tomcat 9. Use
    * {@link #addServletMappingDecoded(String, String)}
    */
    @Deprecated
    public void addServletMapping(String pattern, String name);


    /**
    * Add a new servlet mapping, replacing any existing mapping for
    * the specified pattern.
    *
    * @param pattern URL pattern to be mapped. The pattern will be %
    * decoded using UTF-8
    * @param name Name of the corresponding servlet to execute
    * @param jspWildcard true if name identifies the JspServlet and pattern
    * contains a wildcard; false otherwise
    *
    * @deprecated Will be removed in Tomcat 9. Use
    * {@link #addServletMappingDecoded(String, String, boolean)}
    */
    @Deprecated
    public void addServletMapping(String pattern, String name, boolean jspWildcard);


    /**
    * Add a new servlet mapping, replacing any existing mapping for
    * the specified pattern.
    *
    * @param pattern URL pattern to be mapped
    * @param name Name of the corresponding servlet to execute
    */
    public void addServletMappingDecoded(String pattern, String name);


    /**
    * Add a new servlet mapping, replacing any existing mapping for
    * the specified pattern.
    *
    * @param pattern URL pattern to be mapped
    * @param name Name of the corresponding servlet to execute
    * @param jspWildcard true if name identifies the JspServlet
    * and pattern contains a wildcard; false otherwise
    */
    public void addServletMappingDecoded(String pattern, String name,
    boolean jspWildcard);


    /**
    * Add a resource which will be watched for reloading by the host auto
    * deployer. Note: this will not be used in embedded mode.
    *
    * @param name Path to the resource, relative to docBase
    */
    public void addWatchedResource(String name);


    /**
    * Add a new welcome file to the set recognized by this Context.
    *
    * @param name New welcome file name
    */
    public void addWelcomeFile(String name);


    /**
    * Add the classname of a LifecycleListener to be added to each
    * Wrapper appended to this Context.
    *
    * @param listener Java class name of a LifecycleListener class
    */
    public void addWrapperLifecycle(String listener);


    /**
    * Add the classname of a ContainerListener to be added to each
    * Wrapper appended to this Context.
    *
    * @param listener Java class name of a ContainerListener class
    */
    public void addWrapperListener(String listener);


    /**
    * Factory method to create and return a new Wrapper instance, of
    * the Java implementation class appropriate for this Context
    * implementation. The constructor of the instantiated Wrapper
    * will have been called, but no properties will have been set.
    *
    * @return a newly created wrapper instance that is used to wrap a Servlet
    */
    public Wrapper createWrapper();


    /**
    * @return the set of application listener class names configured
    * for this application.
    */
    public String[] findApplicationListeners();


    /**
    * @return the set of application parameters for this application.
    */
    public ApplicationParameter[] findApplicationParameters();


    /**
    * @return the set of security constraints for this web application.
    * If there are none, a zero-length array is returned.
    */
    public SecurityConstraint[] findConstraints();


    /**
    * @return the error page entry for the specified HTTP error code,
    * if any; otherwise return <code>null</code>.
    *
    * @param errorCode Error code to look up
    */
    public ErrorPage findErrorPage(int errorCode);


    /**
    * @return the error page entry for the specified Java exception type,
    * if any; otherwise return <code>null</code>.
    *
    * @param exceptionType Exception type to look up
    */
    public ErrorPage findErrorPage(String exceptionType);



    /**
    * @return the set of defined error pages for all specified error codes
    * and exception types.
    */
    public ErrorPage[] findErrorPages();


    /**
    * @return the filter definition for the specified filter name, if any;
    * otherwise return <code>null</code>.
    *
    * @param filterName Filter name to look up
    */
    public FilterDef findFilterDef(String filterName);


    /**
    * @return the set of defined filters for this Context.
    */
    public FilterDef[] findFilterDefs();


    /**
    * @return the set of filter mappings for this Context.
    */
    public FilterMap[] findFilterMaps();


    /**
    * @return the MIME type to which the specified extension is mapped,
    * if any; otherwise return <code>null</code>.
    *
    * @param extension Extension to map to a MIME type
    */
    public String findMimeMapping(String extension);


    /**
    * @return the extensions for which MIME mappings are defined. If there
    * are none, a zero-length array is returned.
    */
    public String[] findMimeMappings();


    /**
    * @return the value for the specified context initialization
    * parameter name, if any; otherwise return <code>null</code>.
    *
    * @param name Name of the parameter to return
    */
    public String findParameter(String name);


    /**
    * @return the names of all defined context initialization parameters
    * for this Context. If no parameters are defined, a zero-length
    * array is returned.
    */
    public String[] findParameters();


    /**
    * For the given security role (as used by an application), return the
    * corresponding role name (as defined by the underlying Realm) if there
    * is one. Otherwise, return the specified role unchanged.
    *
    * @param role Security role to map
    * @return The role name that was mapped to the specified role
    */
    public String findRoleMapping(String role);


    /**
    * @return <code>true</code> if the specified security role is defined
    * for this application; otherwise return <code>false</code>.
    *
    * @param role Security role to verify
    */
    public boolean findSecurityRole(String role);


    /**
    * @return the security roles defined for this application. If none
    * have been defined, a zero-length array is returned.
    */
    public String[] findSecurityRoles();


    /**
    * @return the servlet name mapped by the specified pattern (if any);
    * otherwise return <code>null</code>.
    *
    * @param pattern Pattern for which a mapping is requested
    */
    public String findServletMapping(String pattern);


    /**
    * @return the patterns of all defined servlet mappings for this
    * Context. If no mappings are defined, a zero-length array is returned.
    */
    public String[] findServletMappings();


    /**
    * @return the context-relative URI of the error page for the specified
    * HTTP status code, if any; otherwise return <code>null</code>.
    *
    * @param status HTTP status code to look up
    */
    public String findStatusPage(int status);


    /**
    * @return the set of HTTP status codes for which error pages have
    * been specified. If none are specified, a zero-length array
    * is returned.
    */
    public int[] findStatusPages();


    /**
    * @return the associated ThreadBindingListener.
    */
    public ThreadBindingListener getThreadBindingListener();


    /**
    * Get the associated ThreadBindingListener.
    *
    * @param threadBindingListener Set the listener that will receive
    * notifications when entering and exiting the application scope
    */
    public void setThreadBindingListener(ThreadBindingListener threadBindingListener);


    /**
    * @return the set of watched resources for this Context. If none are
    * defined, a zero length array will be returned.
    */
    public String[] findWatchedResources();


    /**
    * @return <code>true</code> if the specified welcome file is defined
    * for this Context; otherwise return <code>false</code>.
    *
    * @param name Welcome file to verify
    */
    public boolean findWelcomeFile(String name);


    /**
    * @return the set of welcome files defined for this Context. If none are
    * defined, a zero-length array is returned.
    */
    public String[] findWelcomeFiles();


    /**
    * @return the set of LifecycleListener classes that will be added to
    * newly created Wrappers automatically.
    */
    public String[] findWrapperLifecycles();


    /**
    * @return the set of ContainerListener classes that will be added to
    * newly created Wrappers automatically.
    */
    public String[] findWrapperListeners();


    /**
    * Notify all {@link javax.servlet.ServletRequestListener}s that a request
    * has started.
    *
    * @param request The request object that will be passed to the listener
    * @return <code>true</code> if the listeners fire successfully, else
    * <code>false</code>
    */
    public boolean fireRequestInitEvent(ServletRequest request);

    /**
    * Notify all {@link javax.servlet.ServletRequestListener}s that a request
    * has ended.
    *
    * @param request The request object that will be passed to the listener
    * @return <code>true</code> if the listeners fire successfully, else
    * <code>false</code>
    */
    public boolean fireRequestDestroyEvent(ServletRequest request);

    /**
    * Reload this web application, if reloading is supported.
    *
    * @exception IllegalStateException if the <code>reloadable</code>
    * property is set to <code>false</code>.
    */
    public void reload();


    /**
    * Remove the specified application listener class from the set of
    * listeners for this application.
    *
    * @param listener Java class name of the listener to be removed
    */
    public void removeApplicationListener(String listener);


    /**
    * Remove the application parameter with the specified name from
    * the set for this application.
    *
    * @param name Name of the application parameter to remove
    */
    public void removeApplicationParameter(String name);


    /**
    * Remove the specified security constraint from this web application.
    *
    * @param constraint Constraint to be removed
    */
    public void removeConstraint(SecurityConstraint constraint);


    /**
    * Remove the error page for the specified error code or
    * Java language exception, if it exists; otherwise, no action is taken.
    *
    * @param errorPage The error page definition to be removed
    */
    public void removeErrorPage(ErrorPage errorPage);


    /**
    * Remove the specified filter definition from this Context, if it exists;
    * otherwise, no action is taken.
    *
    * @param filterDef Filter definition to be removed
    */
    public void removeFilterDef(FilterDef filterDef);


    /**
    * Remove a filter mapping from this Context.
    *
    * @param filterMap The filter mapping to be removed
    */
    public void removeFilterMap(FilterMap filterMap);


    /**
    * Remove the MIME mapping for the specified extension, if it exists;
    * otherwise, no action is taken.
    *
    * @param extension Extension to remove the mapping for
    */
    public void removeMimeMapping(String extension);


    /**
    * Remove the context initialization parameter with the specified
    * name, if it exists; otherwise, no action is taken.
    *
    * @param name Name of the parameter to remove
    */
    public void removeParameter(String name);


    /**
    * Remove any security role reference for the specified name
    *
    * @param role Security role (as used in the application) to remove
    */
    public void removeRoleMapping(String role);


    /**
    * Remove any security role with the specified name.
    *
    * @param role Security role to remove
    */
    public void removeSecurityRole(String role);


    /**
    * Remove any servlet mapping for the specified pattern, if it exists;
    * otherwise, no action is taken.
    *
    * @param pattern URL pattern of the mapping to remove
    */
    public void removeServletMapping(String pattern);


    /**
    * Remove the specified watched resource name from the list associated
    * with this Context.
    *
    * @param name Name of the watched resource to be removed
    */
    public void removeWatchedResource(String name);


    /**
    * Remove the specified welcome file name from the list recognized
    * by this Context.
    *
    * @param name Name of the welcome file to be removed
    */
    public void removeWelcomeFile(String name);


    /**
    * Remove a class name from the set of LifecycleListener classes that
    * will be added to newly created Wrappers.
    *
    * @param listener Class name of a LifecycleListener class to be removed
    */
    public void removeWrapperLifecycle(String listener);


    /**
    * Remove a class name from the set of ContainerListener classes that
    * will be added to newly created Wrappers.
    *
    * @param listener Class name of a ContainerListener class to be removed
    */
    public void removeWrapperListener(String listener);


    /**
    * @return the real path for a given virtual path, if possible; otherwise
    * return <code>null</code>.
    *
    * @param path The path to the desired resource
    */
    public String getRealPath(String path);


    /**
    * @return the effective major version of the Servlet spec used by this
    * context.
    */
    public int getEffectiveMajorVersion();


    /**
    * Set the effective major version of the Servlet spec used by this
    * context.
    *
    * @param major Set the version number
    */
    public void setEffectiveMajorVersion(int major);


    /**
    * @return the effective minor version of the Servlet spec used by this
    * context.
    */
    public int getEffectiveMinorVersion();


    /**
    * Set the effective minor version of the Servlet spec used by this
    * context.
    *
    * @param minor Set the version number
    */
    public void setEffectiveMinorVersion(int minor);


    /**
    * @return the JSP configuration for this context.
    * Will be null if there is no JSP configuration.
    */
    public JspConfigDescriptor getJspConfigDescriptor();

    /**
    * Set the JspConfigDescriptor for this context.
    * A null value indicates there is not JSP configuration.
    *
    * @param descriptor the new JSP configuration
    */
    public void setJspConfigDescriptor(JspConfigDescriptor descriptor);

    /**
    * Add a ServletContainerInitializer instance to this web application.
    *
    * @param sci The instance to add
    * @param classes The classes in which the initializer expressed an
    * interest
    */
    public void addServletContainerInitializer(
    ServletContainerInitializer sci, Set<Class<?>> classes);

    /**
    * Is this Context paused whilst it is reloaded?
    *
    * @return <code>true</code> if the context has been paused
    */
    public boolean getPaused();


    /**
    * Is this context using version 2.2 of the Servlet spec?
    *
    * @return <code>true</code> for a legacy Servlet 2.2 webapp
    */
    boolean isServlet22();

    /**
    * Notification that Servlet security has been dynamically set in a
    * {@link javax.servlet.ServletRegistration.Dynamic}
    * @param registration Servlet security was modified for
    * @param servletSecurityElement new security constraints for this Servlet
    * @return urls currently mapped to this registration that are already
    * present in web.xml
    */
    Set<String> addServletSecurity(ServletRegistration.Dynamic registration,
    ServletSecurityElement servletSecurityElement);

    /**
    * Sets the (comma separated) list of Servlets that expect a resource to be
    * present. Used to ensure that welcome files associated with Servlets that
    * expect a resource to be present are not mapped when there is no resource.
    *
    * @param resourceOnlyServlets The Servlet names comma separated list
    */
    public void setResourceOnlyServlets(String resourceOnlyServlets);

    /**
    * Obtains the list of Servlets that expect a resource to be present.
    *
    * @return A comma separated list of Servlet names as used in web.xml
    */
    public String getResourceOnlyServlets();

    /**
    * Checks the named Servlet to see if it expects a resource to be present.
    *
    * @param servletName Name of the Servlet (as per web.xml) to check
    * @return <code>true</code> if the Servlet expects a resource,
    * otherwise <code>false</code>
    */
    public boolean isResourceOnlyServlet(String servletName);

    /**
    * @return the base name to use for WARs, directories or context.xml files
    * for this context.
    */
    public String getBaseName();

    /**
    * Set the version of this web application - used to differentiate
    * different versions of the same web application when using parallel
    * deployment.
    *
    * @param webappVersion The webapp version associated with the context,
    * which should be unique
    */
    public void setWebappVersion(String webappVersion);

    /**
    * @return The version of this web application, used to differentiate
    * different versions of the same web application when using parallel
    * deployment.
    */
    public String getWebappVersion();

    /**
    * Configure whether or not requests listeners will be fired on forwards for
    * this Context.
    *
    * @param enable <code>true</code> to fire request listeners when forwarding
    */
    public void setFireRequestListenersOnForwards(boolean enable);

    /**
    * @return whether or not requests listeners will be fired on forwards for
    * this Context.
    */
    public boolean getFireRequestListenersOnForwards();

    /**
    * Configures if a user presents authentication credentials, whether the
    * context will process them when the request is for a non-protected
    * resource.
    *
    * @param enable <code>true</code> to perform authentication even outside
    * security constraints
    */
    public void setPreemptiveAuthentication(boolean enable);

    /**
    * @return if a user presents authentication credentials, will the
    * context will process them when the request is for a non-protected
    * resource.
    */
    public boolean getPreemptiveAuthentication();

    /**
    * Configures if a response body is included when a redirect response is
    * sent to the client.
    *
    * @param enable <code>true</code> to send a response body for redirects
    */
    public void setSendRedirectBody(boolean enable);

    /**
    * @return if the context is configured to include a response body as
    * part of a redirect response.
    */
    public boolean getSendRedirectBody();

    /**
    * @return the Loader with which this Context is associated.
    */
    public Loader getLoader();

    /**
    * Set the Loader with which this Context is associated.
    *
    * @param loader The newly associated loader
    */
    public void setLoader(Loader loader);

    /**
    * @return the Resources with which this Context is associated.
    */
    public WebResourceRoot getResources();

    /**
    * Set the Resources object with which this Context is associated.
    *
    * @param resources The newly associated Resources
    */
    public void setResources(WebResourceRoot resources);

    /**
    * @return the Manager with which this Context is associated. If there is
    * no associated Manager, return <code>null</code>.
    */
    public Manager getManager();


    /**
    * Set the Manager with which this Context is associated.
    *
    * @param manager The newly associated Manager
    */
    public void setManager(Manager manager);

    /**
    * Sets the flag that indicates if /WEB-INF/classes should be treated like
    * an exploded JAR and JAR resources made available as if they were in a
    * JAR.
    *
    * @param addWebinfClassesResources The new value for the flag
    */
    public void setAddWebinfClassesResources(boolean addWebinfClassesResources);

    /**
    * @return the flag that indicates if /WEB-INF/classes should be treated like
    * an exploded JAR and JAR resources made available as if they were in a
    * JAR.
    */
    public boolean getAddWebinfClassesResources();

    /**
    * Add a post construct method definition for the given class, if there is
    * an existing definition for the specified class - IllegalArgumentException
    * will be thrown.
    *
    * @param clazz Fully qualified class name
    * @param method
    * Post construct method name
    * @throws IllegalArgumentException
    * if the fully qualified class name or method name are
    * <code>NULL</code>; if there is already post construct method
    * definition for the given class
    */
    public void addPostConstructMethod(String clazz, String method);

    /**
    * Add a pre destroy method definition for the given class, if there is an
    * existing definition for the specified class - IllegalArgumentException
    * will be thrown.
    *
    * @param clazz Fully qualified class name
    * @param method
    * Post construct method name
    * @throws IllegalArgumentException
    * if the fully qualified class name or method name are
    * <code>NULL</code>; if there is already pre destroy method
    * definition for the given class
    */
    public void addPreDestroyMethod(String clazz, String method);

    /**
    * Removes the post construct method definition for the given class, if it
    * exists; otherwise, no action is taken.
    *
    * @param clazz
    * Fully qualified class name
    */
    public void removePostConstructMethod(String clazz);

    /**
    * Removes the pre destroy method definition for the given class, if it
    * exists; otherwise, no action is taken.
    *
    * @param clazz
    * Fully qualified class name
    */
    public void removePreDestroyMethod(String clazz);

    /**
    * Returns the method name that is specified as post construct method for
    * the given class, if it exists; otherwise <code>NULL</code> will be
    * returned.
    *
    * @param clazz
    * Fully qualified class name
    *
    * @return the method name that is specified as post construct method for
    * the given class, if it exists; otherwise <code>NULL</code> will
    * be returned.
    */
    public String findPostConstructMethod(String clazz);

    /**
    * Returns the method name that is specified as pre destroy method for the
    * given class, if it exists; otherwise <code>NULL</code> will be returned.
    *
    * @param clazz
    * Fully qualified class name
    *
    * @return the method name that is specified as pre destroy method for the
    * given class, if it exists; otherwise <code>NULL</code> will be
    * returned.
    */
    public String findPreDestroyMethod(String clazz);

    /**
    * Returns a map with keys - fully qualified class names of the classes that
    * have post construct methods and the values are the corresponding method
    * names. If there are no such classes an empty map will be returned.
    *
    * @return a map with keys - fully qualified class names of the classes that
    * have post construct methods and the values are the corresponding
    * method names.
    */
    public Map<String, String> findPostConstructMethods();

    /**
    * Returns a map with keys - fully qualified class names of the classes that
    * have pre destroy methods and the values are the corresponding method
    * names. If there are no such classes an empty map will be returned.
    *
    * @return a map with keys - fully qualified class names of the classes that
    * have pre destroy methods and the values are the corresponding
    * method names.
    */
    public Map<String, String> findPreDestroyMethods();

    /**
    * @return the token necessary for operations on the associated JNDI naming
    * context.
    */
    public Object getNamingToken();

    /**
    * Sets the {@link CookieProcessor} that will be used to process cookies
    * for this Context.
    *
    * @param cookieProcessor The new cookie processor
    *
    * @throws IllegalArgumentException If a {@code null} CookieProcessor is
    * specified
    */
    public void setCookieProcessor(CookieProcessor cookieProcessor);

    /**
    * @return the {@link CookieProcessor} that will be used to process cookies
    * for this Context.
    */
    public CookieProcessor getCookieProcessor();

    /**
    * When a client provides the ID for a new session, should that ID be
    * validated? The only use case for using a client provided session ID is to
    * have a common session ID across multiple web applications. Therefore,
    * any client provided session ID should already exist in another web
    * application. If this check is enabled, the client provided session ID
    * will only be used if the session ID exists in at least one other web
    * application for the current host. Note that the following additional
    * tests are always applied, irrespective of this setting:
    * <ul>
    * <li>The session ID is provided by a cookie</li>
    * <li>The session cookie has a path of {@code /}</li>
    * </ul>
    *
    * @param validateClientProvidedNewSessionId
    * {@code true} if validation should be applied
    */
    public void setValidateClientProvidedNewSessionId(boolean validateClientProvidedNewSessionId);

    /**
    * Will client provided session IDs be validated (see {@link
    * #setValidateClientProvidedNewSessionId(boolean)}) before use?
    *
    * @return {@code true} if validation will be applied. Otherwise, {@code
    * false}
    */
    public boolean getValidateClientProvidedNewSessionId();

    /**
    * If enabled, requests for a web application context root will be
    * redirected (adding a trailing slash) by the Mapper. This is more
    * efficient but has the side effect of confirming that the context path is
    * valid.
    *
    * @param mapperContextRootRedirectEnabled Should the redirects be enabled?
    */
    public void setMapperContextRootRedirectEnabled(boolean mapperContextRootRedirectEnabled);

    /**
    * Determines if requests for a web application context root will be
    * redirected (adding a trailing slash) by the Mapper. This is more
    * efficient but has the side effect of confirming that the context path is
    * valid.
    *
    * @return {@code true} if the Mapper level redirect is enabled for this
    * Context.
    */
    public boolean getMapperContextRootRedirectEnabled();

    /**
    * If enabled, requests for a directory will be redirected (adding a
    * trailing slash) by the Mapper. This is more efficient but has the
    * side effect of confirming that the directory is valid.
    *
    * @param mapperDirectoryRedirectEnabled Should the redirects be enabled?
    */
    public void setMapperDirectoryRedirectEnabled(boolean mapperDirectoryRedirectEnabled);

    /**
    * Determines if requests for a directory will be redirected (adding a
    * trailing slash) by the Mapper. This is more efficient but has the
    * side effect of confirming that the directory is valid.
    *
    * @return {@code true} if the Mapper level redirect is enabled for this
    * Context.
    */
    public boolean getMapperDirectoryRedirectEnabled();

    /**
    * Controls whether HTTP 1.1 and later location headers generated by a call
    * to {@link javax.servlet.http.HttpServletResponse#sendRedirect(String)}
    * will use relative or absolute redirects.
    * <p>
    * Relative redirects are more efficient but may not work with reverse
    * proxies that change the context path. It should be noted that it is not
    * recommended to use a reverse proxy to change the context path because of
    * the multiple issues it creates.
    * <p>
    * Absolute redirects should work with reverse proxies that change the
    * context path but may cause issues with the
    * {@link org.apache.catalina.filters.RemoteIpFilter} if the filter is
    * changing the scheme and/or port.
    *
    * @param useRelativeRedirects {@code true} to use relative redirects and
    * {@code false} to use absolute redirects
    */
    public void setUseRelativeRedirects(boolean useRelativeRedirects);

    /**
    * Will HTTP 1.1 and later location headers generated by a call to
    * {@link javax.servlet.http.HttpServletResponse#sendRedirect(String)} use
    * relative or absolute redirects.
    *
    * @return {@code true} if relative redirects will be used {@code false} if
    * absolute redirects are used.
    *
    * @see #setUseRelativeRedirects(boolean)
    */
    public boolean getUseRelativeRedirects();

    /**
    * Are paths used in calls to obtain a request dispatcher expected to be
    * encoded? This affects both how Tomcat handles calls to obtain a request
    * dispatcher as well as how Tomcat generates paths used to obtain request
    * dispatchers internally.
    *
    * @param dispatchersUseEncodedPaths {@code true} to use encoded paths,
    * otherwise {@code false}
    */
    public void setDispatchersUseEncodedPaths(boolean dispatchersUseEncodedPaths);

    /**
    * Are paths used in calls to obtain a request dispatcher expected to be
    * encoded? This applys to both how Tomcat handles calls to obtain a request
    * dispatcher as well as how Tomcat generates paths used to obtain request
    * dispatchers internally.
    *
    * @return {@code true} if encoded paths will be used, otherwise
    * {@code false}
    */
    public boolean getDispatchersUseEncodedPaths();

    /**
    * Set the default request body encoding for this web application.
    *
    * @param encoding The default encoding
    */
    public void setRequestCharacterEncoding(String encoding);

    /**
    * Get the default request body encoding for this web application.
    *
    * @return The default request body encoding
    */
    public String getRequestCharacterEncoding();

    /**
    * Set the default response body encoding for this web application.
    *
    * @param encoding The default encoding
    */
    public void setResponseCharacterEncoding(String encoding);

    /**
    * Get the default response body encoding for this web application.
    *
    * @return The default response body encoding
    */
    public String getResponseCharacterEncoding();
    }
  • Wrapper 表示Web应用中定义的Servlet,包括Servlet的装载、初始化、执行以及资源回收,是最底层的容器,实现类为StandardWrapper,但是其并不会调用Servlet的service方法,而是由StandardWrapperValve来获取对应的servlet,通过拦截器去过滤之后调用的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    public interface Wrapper extends Container {

    /**
    * Container event for adding a wrapper.
    */
    public static final String ADD_MAPPING_EVENT = "addMapping";

    /**
    * Container event for removing a wrapper.
    */
    public static final String REMOVE_MAPPING_EVENT = "removeMapping";

    // ------------------------------------------------------------- Properties


    /**
    * @return the available date/time for this servlet, in milliseconds since
    * the epoch. If this date/time is in the future, any request for this
    * servlet will return an SC_SERVICE_UNAVAILABLE error. If it is zero,
    * the servlet is currently available. A value equal to Long.MAX_VALUE
    * is considered to mean that unavailability is permanent.
    */
    public long getAvailable();


    /**
    * Set the available date/time for this servlet, in milliseconds since the
    * epoch. If this date/time is in the future, any request for this servlet
    * will return an SC_SERVICE_UNAVAILABLE error. A value equal to
    * Long.MAX_VALUE is considered to mean that unavailability is permanent.
    *
    * @param available The new available date/time
    */
    public void setAvailable(long available);


    /**
    * @return the load-on-startup order value (negative value means
    * load on first call).
    */
    public int getLoadOnStartup();


    /**
    * Set the load-on-startup order value (negative value means
    * load on first call).
    *
    * @param value New load-on-startup value
    */
    public void setLoadOnStartup(int value);


    /**
    * @return the run-as identity for this servlet.
    */
    public String getRunAs();


    /**
    * Set the run-as identity for this servlet.
    *
    * @param runAs New run-as identity value
    */
    public void setRunAs(String runAs);


    /**
    * @return the fully qualified servlet class name for this servlet.
    */
    public String getServletClass();


    /**
    * Set the fully qualified servlet class name for this servlet.
    *
    * @param servletClass Servlet class name
    */
    public void setServletClass(String servletClass);


    /**
    * Gets the names of the methods supported by the underlying servlet.
    *
    * This is the same set of methods included in the Allow response header
    * in response to an OPTIONS request method processed by the underlying
    * servlet.
    *
    * @return Array of names of the methods supported by the underlying
    * servlet
    *
    * @throws ServletException If the target servlet cannot be loaded
    */
    public String[] getServletMethods() throws ServletException;


    /**
    * @return <code>true</code> if this Servlet is currently unavailable.
    */
    public boolean isUnavailable();


    /**
    * @return the associated Servlet instance.
    */
    public Servlet getServlet();


    /**
    * Set the associated Servlet instance
    *
    * @param servlet The associated Servlet
    */
    public void setServlet(Servlet servlet);

    // --------------------------------------------------------- Public Methods


    /**
    * Add a new servlet initialization parameter for this servlet.
    *
    * @param name Name of this initialization parameter to add
    * @param value Value of this initialization parameter to add
    */
    public void addInitParameter(String name, String value);


    /**
    * Add a mapping associated with the Wrapper.
    *
    * @param mapping The new wrapper mapping
    */
    public void addMapping(String mapping);


    /**
    * Add a new security role reference record to the set of records for
    * this servlet.
    *
    * @param name Role name used within this servlet
    * @param link Role name used within the web application
    */
    public void addSecurityReference(String name, String link);


    /**
    * Allocate an initialized instance of this Servlet that is ready to have
    * its <code>service()</code> method called. If the Servlet class does
    * not implement <code>SingleThreadModel</code>, the (only) initialized
    * instance may be returned immediately. If the Servlet class implements
    * <code>SingleThreadModel</code>, the Wrapper implementation must ensure
    * that this instance is not allocated again until it is deallocated by a
    * call to <code>deallocate()</code>.
    *
    * @exception ServletException if the Servlet init() method threw
    * an exception
    * @exception ServletException if a loading error occurs
    * @return a new Servlet instance
    */
    public Servlet allocate() throws ServletException;


    /**
    * Return this previously allocated servlet to the pool of available
    * instances. If this servlet class does not implement SingleThreadModel,
    * no action is actually required.
    *
    * @param servlet The servlet to be returned
    *
    * @exception ServletException if a deallocation error occurs
    */
    public void deallocate(Servlet servlet) throws ServletException;


    /**
    * @return the value for the specified initialization parameter name,
    * if any; otherwise return <code>null</code>.
    *
    * @param name Name of the requested initialization parameter
    */
    public String findInitParameter(String name);


    /**
    * @return the names of all defined initialization parameters for this
    * servlet.
    */
    public String[] findInitParameters();


    /**
    * @return the mappings associated with this wrapper.
    */
    public String[] findMappings();


    /**
    * @return the security role link for the specified security role
    * reference name, if any; otherwise return <code>null</code>.
    *
    * @param name Security role reference used within this servlet
    */
    public String findSecurityReference(String name);


    /**
    * @return the set of security role reference names associated with
    * this servlet, if any; otherwise return a zero-length array.
    */
    public String[] findSecurityReferences();


    /**
    * Increment the error count value used when monitoring.
    */
    public void incrementErrorCount();


    /**
    * Load and initialize an instance of this Servlet, if there is not already
    * at least one initialized instance. This can be used, for example, to
    * load Servlets that are marked in the deployment descriptor to be loaded
    * at server startup time.
    *
    * @exception ServletException if the Servlet init() method threw
    * an exception or if some other loading problem occurs
    */
    public void load() throws ServletException;


    /**
    * Remove the specified initialization parameter from this Servlet.
    *
    * @param name Name of the initialization parameter to remove
    */
    public void removeInitParameter(String name);


    /**
    * Remove a mapping associated with the wrapper.
    *
    * @param mapping The pattern to remove
    */
    public void removeMapping(String mapping);


    /**
    * Remove any security role reference for the specified role name.
    *
    * @param name Security role used within this servlet to be removed
    */
    public void removeSecurityReference(String name);


    /**
    * Process an UnavailableException, marking this Servlet as unavailable
    * for the specified amount of time.
    *
    * @param unavailable The exception that occurred, or <code>null</code>
    * to mark this Servlet as permanently unavailable
    */
    public void unavailable(UnavailableException unavailable);


    /**
    * Unload all initialized instances of this servlet, after calling the
    * <code>destroy()</code> method for each instance. This can be used,
    * for example, prior to shutting down the entire servlet engine, or
    * prior to reloading all of the classes from the Loader associated with
    * our Loader's repository.
    *
    * @exception ServletException if an unload error occurs
    */
    public void unload() throws ServletException;


    /**
    * @return the multi-part configuration for the associated Servlet. If no
    * multi-part configuration has been defined, then <code>null</code> will be
    * returned.
    */
    public MultipartConfigElement getMultipartConfigElement();


    /**
    * Set the multi-part configuration for the associated Servlet. To clear the
    * multi-part configuration specify <code>null</code> as the new value.
    *
    * @param multipartConfig The configuration associated with the Servlet
    */
    public void setMultipartConfigElement(
    MultipartConfigElement multipartConfig);

    /**
    * Does the associated Servlet support async processing? Defaults to
    * <code>false</code>.
    *
    * @return <code>true</code> if the Servlet supports async
    */
    public boolean isAsyncSupported();

    /**
    * Set the async support for the associated Servlet.
    *
    * @param asyncSupport the new value
    */
    public void setAsyncSupported(boolean asyncSupport);

    /**
    * Is the associated Servlet enabled? Defaults to <code>true</code>.
    *
    * @return <code>true</code> if the Servlet is enabled
    */
    public boolean isEnabled();

    /**
    * Sets the enabled attribute for the associated servlet.
    *
    * @param enabled the new value
    */
    public void setEnabled(boolean enabled);

    /**
    * Set the flag that indicates
    * {@link javax.servlet.annotation.ServletSecurity} annotations must be
    * scanned when the Servlet is first used.
    *
    * @param b The new value of the flag
    */
    public void setServletSecurityAnnotationScanRequired(boolean b);

    /**
    * Scan for (if necessary) and process (if found) the
    * {@link javax.servlet.annotation.ServletSecurity} annotations for the
    * Servlet associated with this wrapper.
    *
    * @throws ServletException if an annotation scanning error occurs
    */
    public void servletSecurityAnnotationScan() throws ServletException;

    /**
    * Is the Servlet overridable by a ServletContainerInitializer?
    *
    * @return <code>true</code> if the Servlet can be overridden in a ServletContainerInitializer
    */
    public boolean isOverridable();

    /**
    * Sets the overridable attribute for this Servlet.
    *
    * @param overridable the new value
    */
    public void setOverridable(boolean overridable);
    }

catalina

配置

来通过配置理解一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
<?xml version="1.0" encoding="UTF-8"?>
<!-- 定义一个Server,表示一个Tomcat实例,8005端口监听SHUTDOWN关闭命令 -->
<Server port="8005" shutdown="SHUTDOWN">

<!-- 定义了一个名为Catalina的Service,一个Server可以有多个Service -->
<Service name="Catalina">

<!-- Service中定义了一个Connector,使用HTTP协议 -->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8" relaxedPathChars="|{}[],%"
relaxedQueryChars="|{}[],%"/>

<!-- Service中定义了一个名为Catalina的Engine,一个Service只能有一个Engine,默认的虚拟主机为localhost,如果接收到请求的域名在所有的Host的name和Alias中都找到不到时使用默认的Host -->
<Engine name="Catalina" defaultHost="localhost">

<!--Engine中定义了一个Host,name表示域名,appBase指定站点的位置,unpackWARs表示是否自动解压war文件 ,autoDeploy表示是否自动部署,如果为true,在运行过程中如果在webapps目录下新增应用将会自动部署并启动 -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true">

</Host>
</Engine>
</Service>
</Server>

看到上述的Server.xml发现只是配置到站点了,没有应用Context的配置,那么Context如何配置呢

Context配置

Context有三种配置方式

  • 通过文件进行配置,前三种配置是应用单独的配置,后两个是Context共享的配置
    • conf/server.xml文件中使用Context标签进行配置
    • conf/{EngineName}/{HostName}目录下以应用名称名称的xml文件
    • 应用自己的/META-INF/context.xml
    • conf/context.xml,整个Tomcat共享
    • conf/{EngineName}/{HostName}/context.xml.default,整个站点共享
  • 将war包直接放在Host目录下,Tomcat会自动查找并添加到Host中
  • 将应用的文件夹放到Host目录下,Tomcat会自动查找并添加到Host中

Wrapper配置

Wrapper的配置就是应用中的web.xml中配置的Servlet,每个Servlet对应一个Wrapper

认识一下四个子接口

通过addChild来向某容器添加子容器

1
public void addChild(Container child);

通过removeChild来删除某容器中的子容器

1
public void removeChild(Container child);

Engine

表示整个Catalina servlet引擎,一个Engine可以有多个Host站点,一个Service只能有一个Engine。默认实现为StandardEngine

Host

表示包含有一个或多个Context容器的虚拟主机,默认实现为StandardHost

Context

表示一个Web应用程序,一个Context可以有多个Wrapper,默认实现为StandardContext

Wrapper

表示一个独立的servlet,默认实现为StandardWrapper,其实最低级的servlet容器了,不可以再向其中添加子容器了,负责管理servlet类的生命周期,即调用servlet的init()、service()、destory等方法,比较重要的两个方法load和allocate

load方法载入并初始化servlet类

1
2
3
public void load() throws ServletException;

// servlet的init方法就是在此时调用的

allocate方法会分配一个已经初始化的servlet实例

1
public Servlet allocate() throws ServletException;

allocate方法会由StandardWrapperValve#invoke方法调用,获取到servlet实例后且会调用servlet#service方法(在执行拦截器链时internalDoFilter调用servlet#service)

定位到Servlet的过程

  • 根据协议和端口确定Service和Engine
  • 根据域名确定Host
  • 根据URL路径找到Context
  • 根据URL路径找到Servlet

欢迎关注我的其它发布渠道