java.lang.Object
net.i2p.router.web.WebAppStarter
Add, start or stop a webapp. Add to the webapp classpath if specified in
webapps.config. Sadly, setting Class-Path in MANIFEST.MF doesn't work for jetty wars. See WebAppConfiguration for more information. but let's just do it in webapps.config.
No, wac.addClassPath() does not work.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static LogThe log for the webapp starter.The names of the built-in webapps.private static final StringClass checked for annotation support.private static final StringClass checked for lifecycle callbacks, from jetty-plus.jar.private static final StringClass checked for asm support, from asm.jar.private static final StringClass checked for the run as annotation, from the annotations api jar.private static final StringClass checked for the webxml configuration.private static final booleanTrue when the annotation classes are present.Init parameters for webapps.(package private) static final StringPlugin name parameter.The webapp file times, by name.Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescription(package private) static WebAppContextaddWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath, File tmpdir) Add but don't start This is used only byRouterConsoleRunner, which adds all the webapps first and then starts all at once.static ContextHandlerCollectionSee comments in ConfigClientsHandlerprivate static ContextHandlerCollectionThe console's handler collection.(package private) static ContextHandlergetWebApp(I2PAppContext ctx, String appName) Warning, this will NOT work during shutdown, because the console is already unregistered.private static ContextHandlergetWebApp(ContextHandlerCollection server, String appName) The handler for the named webapp, if deployed.(package private) static ContextHandlerFind a webapp by name.static booleanisWebAppRunning(I2PAppContext ctx, String appName) Determine if a webapp is running.(package private) static booleanisWebAppRunning(Server s, String appName) Determine if a webapp is running.(package private) static voidsetWebAppConfiguration(WebAppContext wac, boolean scanAnnotations) Choose the Jetty configuration classes, adding annotation scanning only when asked.static voidstartWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath) Adds and starts.static voidstartWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath, String pluginName) Adds and starts.static voidstopWebApp(RouterContext ctx, String appName) Stop it and remove the context.(package private) static voidstopWebApp(RouterContext ctx, Server s, String appName) Stop it and remove the context.
Field Details
warModTimes
INIT_PARAMS
PARAM_PLUGIN_NAME
CLASS_ANNOT
Class checked for annotation support.- See Also:
CLASS_ANNOT2
Class checked for lifecycle callbacks, from jetty-plus.jar.- See Also:
CLASS_ANNOT3
Class checked for asm support, from asm.jar.- See Also:
CLASS_ANNOT4
Class checked for the run as annotation, from the annotations api jar.- See Also:
CLASS_CONFIG
Class checked for the webxml configuration.- See Also:
HAS_ANNOTATION_CLASSES
private static final boolean HAS_ANNOTATION_CLASSESTrue when the annotation classes are present.BUILTINS
_log
The log for the webapp starter.
Constructor Details
WebAppStarter
public WebAppStarter()All methods are static; the ctor exists only for javadoc.
Method Details
startWebApp
public static void startWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath) throws Exception Adds and starts. Prior to 0.9.28, was not guaranteed to throw on failure. Not forrouterconsole.war, it's started in RouterConsoleRunner. Not for plugins, use 5-arg method.As of 0.9.34, the appName will be registered with the PortMapper.
- Parameters:
ctx- router context supplying the temp dir, logging and PortMapperserver- the running console webapp collection to add the context toappName- context path and registered service name, e.g. "i2psnark"warPath- path to the war file- Throws:
Exception- just about anything, caller would be wise to catch Throwable
startWebApp
public static void startWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath, String pluginName) throws Exception Adds and starts. Not forrouterconsole.war, it's started in RouterConsoleRunner.The appName will be registered with the PortMapper.
- Parameters:
ctx- router context supplying the temp dir, logging and PortMapperserver- the running console webapp collection to add the context toappName- context path and registered service name, e.g. "i2psnark"warPath- path to the war filepluginName- may be null, will look for console/webapps.config in that plugin- Throws:
Exception- just about anything, caller would be wise to catch Throwable
addWebApp
static WebAppContext addWebApp(RouterContext ctx, ContextHandlerCollection server, String appName, String warPath, File tmpdir) throws IOException Add but don't start This is used only byRouterConsoleRunner, which adds all the webapps first and then starts all at once.- Parameters:
ctx- router context supplying the temp dir, logging and PortMapperserver- the running console webapp collection to add the context toappName- context path, e.g. "i2psnark"warPath- path to the war file, replaced by a fresh temp copy if the war was modifiedtmpdir- jetty work directory for this context, created if it does not exist- Returns:
- the added but unstarted context
- Throws:
IOException- if the war is missing or cannot be copied for reloading
setWebAppConfiguration
Choose the Jetty configuration classes, adding annotation scanning only when asked. WebAppConfiguration is always added last so the console passwords are read.- Parameters:
wac- the context to configurescanAnnotations- Should we check for Servlet 3.0 annotations? The war MUST be set to extract (due to Jetty bug), and annotation classes MUST be available
stopWebApp
Stop it and remove the context. Throws just about anything, caller would be wise to catch ThrowableWarning, this will NOT work during shutdown, because the console is already unregistered.
- Parameters:
ctx- router context supplying the PortMapperappName- context path, e.g. "i2psnark"
stopWebApp
Stop it and remove the context. Throws just about anything, caller would be wise to catch Throwable.- Parameters:
ctx- router context supplying the PortMappers- the Jetty server holding the console contexts, so this also works during shutdown after the console has been unregisteredappName- context path, e.g. "i2psnark"
isWebAppRunning
Determine if a webapp is running. Warning, this will NOT work during shutdown, because the console is already unregistered.As of 0.9.34, the appName will be registered with the PortMapper, and
PortMapper.isRegistered(String)will be more efficient than this.- Parameters:
ctx- router context used to locate the console serverappName- context path, e.g. "i2psnark"- Returns:
- whether web app running
isWebAppRunning
getWebApp
Warning, this will NOT work during shutdown, because the console is already unregistered.- Parameters:
ctx- router context used to locate the console serverappName- context path, e.g. "i2psnark"- Returns:
- the context, or null if the console server or the webapp is not found
getWebApp
Find a webapp by name.- Parameters:
s- the Jetty server holding the console contextsappName- context path, e.g. "i2psnark"- Returns:
- the context, or null if the console server or the webapp is not found
getWebApp
The handler for the named webapp, if deployed.- Parameters:
server- the handler collection holding the deployed web appsappName- the web app name, matched against the context path /appName- Returns:
- the web app
getConsoleServer
See comments in ConfigClientsHandlerWarning, this will NOT work during shutdown, because the console is already unregistered.
- Parameters:
ctx- router context used to locate the console server- Returns:
- the console server
getConsoleServer
The console's handler collection.- Parameters:
s- the console server to search for the handler collection- Returns:
- the console server