java.lang.Object
net.i2p.router.web.WebAppStarter

public class WebAppStarterextends Object
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 Details

    • warModTimes

      private static final Map<String,Long> warModTimes
      The webapp file times, by name.
    • INIT_PARAMS

      static final Map<String,String> INIT_PARAMS
      Init parameters for webapps.
    • PARAM_PLUGIN_NAME

      static final String PARAM_PLUGIN_NAME
      Plugin name parameter.
      See Also:
    • CLASS_ANNOT

      private static final String CLASS_ANNOT
      Class checked for annotation support.
      See Also:
    • CLASS_ANNOT2

      private static final String CLASS_ANNOT2
      Class checked for lifecycle callbacks, from jetty-plus.jar.
      See Also:
    • CLASS_ANNOT3

      private static final String CLASS_ANNOT3
      Class checked for asm support, from asm.jar.
      See Also:
    • CLASS_ANNOT4

      private static final String CLASS_ANNOT4
      Class checked for the run as annotation, from the annotations api jar.
      See Also:
    • CLASS_CONFIG

      private static final String CLASS_CONFIG
      Class checked for the webxml configuration.
      See Also:
    • HAS_ANNOTATION_CLASSES

      private static final boolean HAS_ANNOTATION_CLASSES
      True when the annotation classes are present.
    • BUILTINS

      private static final Set<String> BUILTINS
      The names of the built-in webapps.
    • _log

      private static Log _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 for routerconsole.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 PortMapper
      server - the running console webapp collection to add the context to
      appName - 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 for routerconsole.war, it's started in RouterConsoleRunner.

      The appName will be registered with the PortMapper.

      Parameters:
      ctx - router context supplying the temp dir, logging and PortMapper
      server - the running console webapp collection to add the context to
      appName - context path and registered service name, e.g. "i2psnark"
      warPath - path to the war file
      pluginName - 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 by RouterConsoleRunner, which adds all the webapps first and then starts all at once.
      Parameters:
      ctx - router context supplying the temp dir, logging and PortMapper
      server - the running console webapp collection to add the context to
      appName - context path, e.g. "i2psnark"
      warPath - path to the war file, replaced by a fresh temp copy if the war was modified
      tmpdir - 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

      static void setWebAppConfiguration(WebAppContext wac, boolean scanAnnotations)
      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 configure
      scanAnnotations - 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

      public static void stopWebApp(RouterContext ctx, String appName)
      Stop it and remove the context. Throws just about anything, caller would be wise to catch Throwable

      Warning, this will NOT work during shutdown, because the console is already unregistered.

      Parameters:
      ctx - router context supplying the PortMapper
      appName - context path, e.g. "i2psnark"
    • stopWebApp

      static void stopWebApp(RouterContext ctx, Server s, String appName)
      Stop it and remove the context. Throws just about anything, caller would be wise to catch Throwable.
      Parameters:
      ctx - router context supplying the PortMapper
      s - the Jetty server holding the console contexts, so this also works during shutdown after the console has been unregistered
      appName - context path, e.g. "i2psnark"
    • isWebAppRunning

      public static boolean isWebAppRunning(I2PAppContext ctx, String appName)
      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 server
      appName - context path, e.g. "i2psnark"
      Returns:
      whether web app running
    • isWebAppRunning

      static boolean isWebAppRunning(Server s, String appName)
      Determine if a webapp is running.
      Parameters:
      s - the Jetty server holding the console contexts
      appName - context path, e.g. "i2psnark"
      Returns:
      true if the context exists and has been started
    • getWebApp

      static ContextHandler getWebApp(I2PAppContext ctx, String appName)
      Warning, this will NOT work during shutdown, because the console is already unregistered.
      Parameters:
      ctx - router context used to locate the console server
      appName - context path, e.g. "i2psnark"
      Returns:
      the context, or null if the console server or the webapp is not found
    • getWebApp

      static ContextHandler getWebApp(Server s, String appName)
      Find a webapp by name.
      Parameters:
      s - the Jetty server holding the console contexts
      appName - context path, e.g. "i2psnark"
      Returns:
      the context, or null if the console server or the webapp is not found
    • getWebApp

      private static ContextHandler getWebApp(ContextHandlerCollection server, String appName)
      The handler for the named webapp, if deployed.
      Parameters:
      server - the handler collection holding the deployed web apps
      appName - the web app name, matched against the context path /appName
      Returns:
      the web app
    • getConsoleServer

      public static ContextHandlerCollection getConsoleServer(I2PAppContext ctx)
      See comments in ConfigClientsHandler

      Warning, 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

      private static ContextHandlerCollection getConsoleServer(Server s)
      The console's handler collection.
      Parameters:
      s - the console server to search for the handler collection
      Returns:
      the console server