Class InternalWebServer

  • All Implemented Interfaces:
    org.osgi.framework.BundleActivator

    public class InternalWebServer
    extends org.eclipse.ui.plugin.AbstractUIPlugin
    The activator class controls the plug-in life cycle for the Internal Web Server using Jetty.
    Author:
    Christopher Mindus
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String PLUGIN_ID
      The plug-in ID.
      • Fields inherited from class org.eclipse.core.runtime.Plugin

        PLUGIN_PREFERENCE_SCOPE, PREFERENCES_DEFAULT_OVERRIDE_BASE_NAME, PREFERENCES_DEFAULT_OVERRIDE_FILE_NAME
    • Constructor Summary

      Constructors 
      Constructor Description
      InternalWebServer()
      The constructor
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.String getFileUrl​(java.lang.String fileName)
      Gets the URL string for a file in the root using the File protocol.
      java.lang.String getHTTPFileUrl​(java.lang.String fileName)
      Gets the URL string for a file in the root using the HTTP protocol.
      static InternalWebServer getInstance()
      Returns the shared instance.
      int getSecureWebServerPort()
      Gets the started secure (HTTPS) web server port.
      IntegratedWebServer getServer()
      Gets the Integrated Jetty Server instance.
      java.io.File getWebServerMapping​(java.lang.String mappedFile)
      Gets the map of web server mappings for files.
      int getWebServerPort()
      Gets the started web server port.
      void start​(org.osgi.framework.BundleContext context)  
      int startWebServer​(IExternalBrowserPages extPages, IWSFileProviderServer fileProvider, WebSocketAcceptor acceptor)
      Starts the web server.
      void stop​(org.osgi.framework.BundleContext context)  
      boolean stopWebServer​(long maxTime)
      Stops the web server.
      • Methods inherited from class org.eclipse.ui.plugin.AbstractUIPlugin

        createImageRegistry, getDialogSettings, getImageRegistry, getPreferenceStore, getWorkbench, imageDescriptorFromPlugin, initializeDefaultPluginPreferences, initializeDefaultPreferences, initializeImageRegistry, loadDialogSettings, loadPreferenceStore, refreshPluginActions, saveDialogSettings, savePreferenceStore, shutdown, startup
      • Methods inherited from class org.eclipse.core.runtime.Plugin

        find, find, getBundle, getLog, getPluginPreferences, getStateLocation, internalInitializeDefaultPluginPreferences, isDebugging, openStream, openStream, savePluginPreferences, setDebugging, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • PLUGIN_ID

        public static final java.lang.String PLUGIN_ID
        The plug-in ID.
        See Also:
        Constant Field Values
    • Constructor Detail

      • InternalWebServer

        public InternalWebServer()
        The constructor
    • Method Detail

      • start

        public void start​(org.osgi.framework.BundleContext context)
                   throws java.lang.Exception
        Specified by:
        start in interface org.osgi.framework.BundleActivator
        Overrides:
        start in class org.eclipse.ui.plugin.AbstractUIPlugin
        Throws:
        java.lang.Exception
      • getInstance

        public static InternalWebServer getInstance()
        Returns the shared instance.
        Returns:
        the shared instance.
      • startWebServer

        public int startWebServer​(IExternalBrowserPages extPages,
                                  IWSFileProviderServer fileProvider,
                                  WebSocketAcceptor acceptor)
        Starts the web server.
        Parameters:
        extPages - External pages implementor, null for none.
        fileProvider - File provider interface.
        acceptor - The acceptor for engine requests.
        Returns:
        The port used, 0 for failure.
      • stopWebServer

        public boolean stopWebServer​(long maxTime)
        Stops the web server.
        Parameters:
        maxTime - Max time to wait for server to stop, <=0 is forever.
        Returns:
        true for success, false for timeout.
      • getWebServerPort

        public int getWebServerPort()
        Gets the started web server port.
        Returns:
        The port number, zero for not started.
      • getSecureWebServerPort

        public int getSecureWebServerPort()
        Gets the started secure (HTTPS) web server port.
        Returns:
        The port number, zero for not started.
      • stop

        public void stop​(org.osgi.framework.BundleContext context)
                  throws java.lang.Exception
        Specified by:
        stop in interface org.osgi.framework.BundleActivator
        Overrides:
        stop in class org.eclipse.ui.plugin.AbstractUIPlugin
        Throws:
        java.lang.Exception
      • getHTTPFileUrl

        public java.lang.String getHTTPFileUrl​(java.lang.String fileName)
        Gets the URL string for a file in the root using the HTTP protocol.
        Parameters:
        fileName - File name relative the root.
        Returns:
        A String like "http://127.0.0.1:port/name".
      • getFileUrl

        public java.lang.String getFileUrl​(java.lang.String fileName)
        Gets the URL string for a file in the root using the File protocol.
        Parameters:
        fileName - File name relative the root.
        Returns:
        A String like "file:...";
      • getServer

        public IntegratedWebServer getServer()
        Gets the Integrated Jetty Server instance.
      • getWebServerMapping

        public java.io.File getWebServerMapping​(java.lang.String mappedFile)
        Gets the map of web server mappings for files.
        Parameters:
        mappedFile - The file to map.
        Returns:
        The mapping from String (such as "dojo.root" or "iiziRun.root") to File Returns null if not found.