0
# Application Providers
1
2
Provider system for discovering and deploying applications from various sources like directories, WAR files, and XML descriptors. Providers implement pluggable discovery mechanisms that automatically detect deployable applications and create App instances for the DeploymentManager.
3
4
## Capabilities
5
6
### AppProvider Interface
7
8
Base interface for objects responsible for providing Apps to the DeploymentManager. Providers discover applications from various sources and create appropriate context handlers.
9
10
```java { .api }
11
/**
12
* Interface for objects responsible for providing Apps to the DeploymentManager
13
*/
14
public interface AppProvider extends LifeCycle {
15
/** Sets the deployment manager that will receive discovered apps */
16
void setDeploymentManager(DeploymentManager deploymentManager);
17
18
/** Creates a context handler for the specified app */
19
ContextHandler createContextHandler(App app) throws Exception;
20
21
/** Returns the environment name this provider is designed for */
22
String getEnvironmentName();
23
}
24
```
25
26
### ScanningAppProvider
27
28
Abstract base provider for loading webapps by scanning directories. Provides file system monitoring, change detection, and automatic deployment/redeployment capabilities.
29
30
```java { .api }
31
/**
32
* Abstract base provider for loading webapps by scanning directories
33
*/
34
public abstract class ScanningAppProvider extends ContainerLifeCycle implements AppProvider {
35
/** Creates a new scanning provider with default settings */
36
public ScanningAppProvider();
37
38
/** Creates a new scanning provider with a custom filename filter */
39
public ScanningAppProvider(FilenameFilter filter);
40
41
/** Returns the environment name this provider targets */
42
public String getEnvironmentName();
43
44
/** Sets the environment name this provider is for */
45
public void setEnvironmentName(String environmentName);
46
47
/** Returns if real paths should be used instead of symbolic links */
48
public boolean isUseRealPaths();
49
50
/** Sets whether to use real paths instead of following symbolic links */
51
public void setUseRealPaths(boolean useRealPaths);
52
53
/** Returns the deployment manager */
54
public DeploymentManager getDeploymentManager();
55
56
/** Sets the deployment manager that will receive discovered apps */
57
public void setDeploymentManager(DeploymentManager deploymentManager);
58
59
/** Returns the monitored directory as a Resource */
60
public Resource getMonitoredDirResource();
61
62
/** Returns the monitored directory name */
63
public String getMonitoredDirName();
64
65
/** Sets a single monitored directory resource */
66
public void setMonitoredDirResource(Resource resource);
67
68
/** Sets the monitored directory by name */
69
public void setMonitoredDirName(String dir);
70
71
/** Sets multiple monitored directories */
72
public void setMonitoredDirectories(Collection<String> directories);
73
74
/** Sets monitored resources directly */
75
public void setMonitoredResources(List<Resource> resources);
76
77
/** Returns all monitored resources */
78
public List<Resource> getMonitoredResources();
79
80
/** Returns the scan interval in seconds */
81
public int getScanInterval();
82
83
/** Sets the scan interval in seconds (0 disables scanning) */
84
public void setScanInterval(int scanInterval);
85
86
/** Returns if the initial scan is deferred until after startup */
87
public boolean isDeferInitialScan();
88
89
/** Sets whether to defer the initial scan until after startup */
90
public void setDeferInitialScan(boolean defer);
91
92
/** Adds a scanner listener for custom file change handling */
93
public void addScannerListener(Scanner.Listener listener);
94
95
/** Triggers a manual scan of monitored directories */
96
public void scan();
97
98
/** Returns string representation of the provider */
99
public String toString();
100
101
// Protected methods for extension
102
/** Returns index of currently deployed applications */
103
protected Map<Path, App> getDeployedApps();
104
105
/** Creates a new App object for the specified path */
106
protected App createApp(Path path);
107
108
/** Called when a new deployable path is discovered */
109
protected void pathAdded(Path path) throws Exception;
110
111
/** Called when a deployable path changes */
112
protected void pathChanged(Path path) throws Exception;
113
114
/** Called when a deployable path is removed */
115
protected void pathRemoved(Path path) throws Exception;
116
}
117
```
118
119
**Usage Examples:**
120
121
```java
122
import org.eclipse.jetty.deploy.providers.ScanningAppProvider;
123
import org.eclipse.jetty.util.Scanner;
124
125
// Custom provider extending ScanningAppProvider
126
public class CustomProvider extends ScanningAppProvider {
127
public CustomProvider() {
128
super();
129
setEnvironmentName("ee10");
130
}
131
132
@Override
133
public ContextHandler createContextHandler(App app) throws Exception {
134
// Custom context handler creation logic
135
ContextHandler handler = new ContextHandler();
136
handler.setContextPath(app.getContextPath());
137
return handler;
138
}
139
}
140
141
// Configure scanning provider
142
CustomProvider provider = new CustomProvider();
143
provider.setMonitoredDirName("/opt/webapps");
144
provider.setScanInterval(30); // Scan every 30 seconds
145
provider.setDeferInitialScan(false);
146
provider.setUseRealPaths(true);
147
148
// Add custom scanner listener
149
provider.addScannerListener(new Scanner.Listener() {
150
@Override
151
public void fileAdded(String filename) throws Exception {
152
System.out.println("New app detected: " + filename);
153
}
154
155
@Override
156
public void fileRemoved(String filename) throws Exception {
157
System.out.println("App removed: " + filename);
158
}
159
});
160
161
deploymentManager.addAppProvider(provider);
162
```
163
164
### ContextProvider
165
166
Concrete provider for scanning webapps directories for contexts to deploy including WAR files, directories, and XML descriptors. Provides comprehensive webapp deployment with extensive configuration options.
167
168
```java { .api }
169
/**
170
* Provider for scanning webapps directories for contexts to deploy
171
* (WAR files, directories, XML descriptors)
172
*/
173
public class ContextProvider extends ScanningAppProvider {
174
/** Creates a new context provider with default settings */
175
public ContextProvider();
176
177
/** Returns provider-specific properties */
178
public Map<String, String> getProperties();
179
180
/** Loads properties from a resource */
181
public void loadProperties(Resource resource) throws IOException;
182
183
/** Loads properties from a file path */
184
public void loadPropertiesFromPath(Path path) throws IOException;
185
186
/** Loads properties from a string path */
187
public void loadPropertiesFromString(String path) throws IOException;
188
189
/** Returns whether WAR files should be extracted */
190
public boolean isExtractWars();
191
192
/** Sets whether WAR files should be extracted during deployment */
193
public void setExtractWars(boolean extractWars);
194
195
/** Returns parent classloader priority setting */
196
public boolean isParentLoaderPriority();
197
198
/** Sets parent classloader priority for web applications */
199
public void setParentLoaderPriority(boolean parentLoaderPriority);
200
201
/** Returns the defaults descriptor path */
202
public String getDefaultsDescriptor();
203
204
/** Sets the defaults descriptor for web applications */
205
public void setDefaultsDescriptor(String defaultsDescriptor);
206
207
/** Sets configuration classes as comma-separated string */
208
public void setConfigurationClasses(String configurations);
209
210
/** Sets configuration classes array */
211
public void setConfigurationClasses(String[] configurations);
212
213
/** Returns the configuration classes */
214
public String[] getConfigurationClasses();
215
216
/** Creates a context handler for the specified app */
217
public ContextHandler createContextHandler(App app) throws Exception;
218
}
219
```
220
221
**Usage Examples:**
222
223
```java
224
import org.eclipse.jetty.deploy.providers.ContextProvider;
225
226
// Basic context provider setup
227
ContextProvider contextProvider = new ContextProvider();
228
contextProvider.setMonitoredDirName("webapps");
229
contextProvider.setScanInterval(10);
230
231
// Configure webapp deployment options
232
contextProvider.setExtractWars(true);
233
contextProvider.setParentLoaderPriority(false);
234
contextProvider.setDefaultsDescriptor("etc/webdefault.xml");
235
236
// Set configuration classes for specific webapp features
237
contextProvider.setConfigurationClasses(new String[] {
238
"org.eclipse.jetty.ee10.webapp.WebInfConfiguration",
239
"org.eclipse.jetty.ee10.webapp.WebXmlConfiguration",
240
"org.eclipse.jetty.ee10.webapp.MetaInfConfiguration",
241
"org.eclipse.jetty.ee10.webapp.FragmentConfiguration",
242
"org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration"
243
});
244
245
// Load additional properties from file
246
contextProvider.loadPropertiesFromString("config/webapp.properties");
247
248
// Add to deployment manager
249
deploymentManager.addAppProvider(contextProvider);
250
251
// Multiple providers for different directories
252
ContextProvider devProvider = new ContextProvider();
253
devProvider.setMonitoredDirName("dev-webapps");
254
devProvider.setEnvironmentName("development");
255
256
ContextProvider prodProvider = new ContextProvider();
257
prodProvider.setMonitoredDirName("prod-webapps");
258
prodProvider.setEnvironmentName("production");
259
prodProvider.setExtractWars(false); // Keep WARs compressed in production
260
261
deploymentManager.addAppProvider(devProvider);
262
deploymentManager.addAppProvider(prodProvider);
263
```
264
265
### ContextProvider.Filter
266
267
Nested filename filter class for filtering files during directory scanning. Implements sophisticated filtering logic to determine which files and directories should be considered for deployment.
268
269
```java { .api }
270
/**
271
* Filename filter for determining which files should be considered for deployment.
272
* Accepts WAR files, XML descriptors, and directories while excluding hidden files,
273
* source control directories, and directories with sibling WAR/XML files.
274
*/
275
public class ContextProvider.Filter implements FilenameFilter {
276
/**
277
* Filters files for deployment consideration based on comprehensive rules
278
* @param dir The directory being scanned
279
* @param name The filename being considered
280
* @return true if the file should be considered for deployment
281
*/
282
public boolean accept(File dir, String name);
283
}
284
```
285
286
**Filter Rules:**
287
- **Accepts**: WAR files (*.war), XML context descriptors (*.xml), deployable directories
288
- **Rejects**: Hidden files/directories (starting with .), config directories (*.d), source control directories (cvs, cvsroot), directories with sibling WAR/XML files (prevents duplicate deployment)
289
- **Ignores**: Non-directory files that aren't WAR or XML, monitored resource directories
290
291
**Usage Examples:**
292
293
```java
294
// The default ContextProvider uses this filter automatically
295
ContextProvider provider = new ContextProvider();
296
// Filter is set automatically in constructor: setFilenameFilter(new Filter());
297
298
// Custom filter extending the default behavior
299
ContextProvider customProvider = new ContextProvider() {
300
{
301
setFilenameFilter(new FilenameFilter() {
302
private Filter defaultFilter = new Filter();
303
304
@Override
305
public boolean accept(File dir, String name) {
306
// Apply default filter first
307
if (!defaultFilter.accept(dir, name)) {
308
return false;
309
}
310
311
// Additional custom filtering
312
if (name.startsWith("temp-")) {
313
return false; // Exclude temporary deployments
314
}
315
316
return true;
317
}
318
});
319
}
320
};
321
322
// Examples of what the filter accepts/rejects:
323
// Accepts: "myapp.war", "myapp.xml", "myapp/" (directory)
324
// Rejects: ".hidden", "temp.d", "cvs", "myapp/" (if myapp.war exists)
325
```