-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Configuration.java
195 lines (177 loc) · 6.98 KB
/
Configuration.java
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
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.webapp;
import java.util.Collection;
import java.util.Collections;
import java.util.ServiceLoader;
import org.eclipse.jetty.util.ClassMatcher;
import org.eclipse.jetty.util.TopologicalSort;
/**
* A pluggable Configuration for {@link WebAppContext}s.
* <p>
* A {@link WebAppContext} is configured by the application of one or more {@link Configuration}
* instances. Typically each implemented Configuration is responsible for an aspect of the
* servlet specification (eg {@link WebXmlConfiguration}, {@link FragmentConfiguration}, etc.)
* or feature (eg {@code JakartaWebSocketConfiguration}, {@code JmxConfiguration} etc.)
* </p>
* <p>Configuration instances are discovered by the {@link Configurations} class using either the
* {@link ServiceLoader} mechanism or by an explicit call to {@link Configurations#setKnown(String...)}.
* By default, all Configurations that do not return false from {@link #isEnabledByDefault()}
* are applied to all {@link WebAppContext}s within the JVM. However a Server wide default {@link Configurations}
* collection may also be defined with {@link Configurations#setServerDefault(org.eclipse.jetty.server.Server)}.
* Furthermore, each individual Context may have its Configurations list explicitly set and/or amended with
* {@link WebAppContext#setConfigurations(Configuration[])}, {@link WebAppContext#addConfiguration(Configuration...)}
* or {@link WebAppContext#getConfigurations()}.
* </p>
* <p>Since EE10 in Jetty-12, Configuration implementations must be stateless/immutable.</p>
* <p>Since Jetty-9.4, Configurations are self ordering using the {@link #getDependencies()} and
* {@link #getDependents()} methods for a {@link TopologicalSort} initiated by {@link Configurations#sort()}
* when a {@link WebAppContext} is started. This means that feature configurations
* (eg {@link JndiConfiguration}, {@link JaasConfiguration}} etc.) can be added or removed without concern
* for ordering.
* </p>
* <p>Also since Jetty-9.4, Configurations are responsible for providing {@link #getHiddenClasses()} and
* {@link #getProtectedClasses()} to configure the {@link WebAppClassLoader} for each context.
* </p>
*/
public interface Configuration
{
/**
* @return True if the feature this configuration represents is available and has all its dependencies.
*/
default boolean isAvailable()
{
return true;
}
/**
* Get a class that this class replaces/extends.
* If this is added to {@link Configurations} collection that already contains a
* configuration of the replaced class or that reports to replace the same class, then
* it is replaced with this instance.
*
* @return The class this Configuration replaces/extends or null if it replaces no other configuration
*/
default Class<? extends Configuration> replaces()
{
return null;
}
/**
* Get known Configuration Dependencies.
*
* @return The names of Configurations that {@link TopologicalSort} must order
* before this configuration.
*/
default Collection<String> getDependencies()
{
return Collections.emptyList();
}
/**
* Get known Configuration Dependents.
*
* @return The names of Configurations that {@link TopologicalSort} must order
* after this configuration.
*/
default Collection<String> getDependents()
{
return Collections.emptyList();
}
/**
* Get the system (protected) classes associated with this Configuration.
*
* @return ClassMatcher of system classes.
*/
default ClassMatcher getProtectedClasses()
{
return new ClassMatcher();
}
/**
* Get the server (hidden) classes associated with this Configuration.
*
* @return ClassMatcher of server classes.
*/
default ClassMatcher getHiddenClasses()
{
return new ClassMatcher();
}
/**
* @deprecated use {@link #getProtectedClasses()} instead
*/
@Deprecated(since = "12.0.8", forRemoval = true)
default org.eclipse.jetty.ee10.webapp.ClassMatcher getSystemClasses()
{
return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getProtectedClasses());
}
/**
* @deprecated use {@link #getHiddenClasses()} instead
*/
@Deprecated(since = "12.0.8", forRemoval = true)
default org.eclipse.jetty.ee10.webapp.ClassMatcher getServerClasses()
{
return new org.eclipse.jetty.ee10.webapp.ClassMatcher(getHiddenClasses());
}
/**
* Set up for configuration.
* <p>
* Typically this step discovers configuration resources.
* Calls to preConfigure may alter the Configurations configured on the
* WebAppContext, so long as configurations prior to this configuration
* are not altered.
*
* @param context The context to configure
* @throws Exception if unable to pre configure
*/
void preConfigure(WebAppContext context) throws Exception;
/**
* Configure WebApp.
* <p>
* Typically this step applies the discovered configuration resources to
* either the {@link WebAppContext} or the associated {@link MetaData}.
*
* @param context The context to configure
* @throws Exception if unable to configure
*/
void configure(WebAppContext context) throws Exception;
/**
* Clear down after configuration.
*
* @param context The context to configure
* @throws Exception if unable to post configure
*/
void postConfigure(WebAppContext context) throws Exception;
/**
* DeConfigure WebApp.
* This method is called to undo all configuration done. This is
* called to allow the context to work correctly over a stop/start cycle
*
* @param context The context to configure
* @throws Exception if unable to deconfigure
*/
void deconfigure(WebAppContext context) throws Exception;
/**
* Destroy WebApp.
* This method is called to destroy a webappcontext. It is typically called when a context
* is removed from a server handler hierarchy by the deployer.
*
* @param context The context to configure
* @throws Exception if unable to destroy
*/
void destroy(WebAppContext context) throws Exception;
/**
* @return true if configuration is enabled by default
*/
boolean isEnabledByDefault();
/**
* @return true if configuration should be aborted
*/
boolean abort(WebAppContext context);
}