diff options
author | Chris Goldthorpe | 2008-12-02 17:25:40 +0000 |
---|---|---|
committer | Chris Goldthorpe | 2008-12-02 17:25:40 +0000 |
commit | 258d68a1318459d3d377572ae1b25709f96921c6 (patch) | |
tree | 54f543e90ae226faca4a0f517693235d74c986ac /org.eclipse.help.base | |
parent | 4b18edad7b9b4e4f4ecbabf6adb1f1169626ddfe (diff) | |
download | eclipse.platform.ua-258d68a1318459d3d377572ae1b25709f96921c6.tar.gz eclipse.platform.ua-258d68a1318459d3d377572ae1b25709f96921c6.tar.xz eclipse.platform.ua-258d68a1318459d3d377572ae1b25709f96921c6.zip |
Bug 220992 [Help] No API to plug-in a non-Jetty web server for Help sub-system
Diffstat (limited to 'org.eclipse.help.base')
6 files changed, 328 insertions, 88 deletions
diff --git a/org.eclipse.help.base/META-INF/MANIFEST.MF b/org.eclipse.help.base/META-INF/MANIFEST.MF index 80ac27209..881766237 100644 --- a/org.eclipse.help.base/META-INF/MANIFEST.MF +++ b/org.eclipse.help.base/META-INF/MANIFEST.MF @@ -34,6 +34,7 @@ Export-Package: org.apache.lucene.demo.html;x-internal:=true, org.eclipse.ui.intro, org.eclipse.help.webapp", org.eclipse.help.search, + org.eclipse.help.server, org.eclipse.help.standalone Require-Bundle: org.apache.lucene;bundle-version="[1.9.1,2.0.0)";visibility:=reexport, org.apache.lucene.analysis;bundle-version="[1.9.1,2.0.0)";visibility:=reexport, diff --git a/org.eclipse.help.base/plugin.xml b/org.eclipse.help.base/plugin.xml index 5a2a7f3ca..8bb484aaa 100644 --- a/org.eclipse.help.base/plugin.xml +++ b/org.eclipse.help.base/plugin.xml @@ -7,6 +7,7 @@ <extension-point id="browser" name="%browser_extension_point_name" schema="schema/browser.exsd"/> <extension-point id="activitySupport" name="%activity_extension_point_name" schema="schema/activitySupport.exsd"/> <extension-point id="luceneSearchParticipants" name="%search_participant_extension_point_name" schema="schema/luceneSearchParticipants.exsd"/> + <extension-point id="server" name="Help Server" schema="schema/server.exsd"/> <!-- Stand-alone infocenter application --> <extension diff --git a/org.eclipse.help.base/schema/server.exsd b/org.eclipse.help.base/schema/server.exsd new file mode 100644 index 000000000..7511c1dd2 --- /dev/null +++ b/org.eclipse.help.base/schema/server.exsd @@ -0,0 +1,105 @@ +<?xml version='1.0' encoding='UTF-8'?> +<!-- Schema file written by PDE --> +<schema targetNamespace="org.eclipse.help.base" xmlns="http://www.w3.org/2001/XMLSchema"> +<annotation> + <appinfo> + <meta.schema plugin="org.eclipse.help.base" id="server" name="Help Server"/> + </appinfo> + <documentation> + Allows Eclipse to use a web server other than the Equinox server to host the help system. + </documentation> + </annotation> + + <element name="extension"> + <annotation> + <appinfo> + <meta.element /> + </appinfo> + </annotation> + <complexType> + <sequence> + <element ref="server"/> + </sequence> + <attribute name="point" type="string" use="required"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="id" type="string"> + <annotation> + <documentation> + + </documentation> + </annotation> + </attribute> + <attribute name="name" type="string"> + <annotation> + <documentation> + + </documentation> + <appinfo> + <meta.attribute translatable="true"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <element name="server"> + <complexType> + <attribute name="class" type="string" use="required"> + <annotation> + <documentation> + A class which implement start and stop methods for an application server and which is responsible for initializing the servlets and resources in the org.eclipse.help.webapp plug-in. + </documentation> + <appinfo> + <meta.attribute kind="java" basedOn="org.eclipse.help.server.HelpServer:"/> + </appinfo> + </annotation> + </attribute> + </complexType> + </element> + + <annotation> + <appinfo> + <meta.section type="since"/> + </appinfo> + <documentation> + 3.4 + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="examples"/> + </appinfo> + <documentation> + [Enter extension point usage example here.] + </documentation> + </annotation> + + <annotation> + <appinfo> + <meta.section type="apiinfo"/> + </appinfo> + <documentation> + A class which extends HelpServer must be provided which will start and stop the application server and initialize the servlets and resources in org.eclipse.help.webapp. + </documentation> + </annotation> + + + <annotation> + <appinfo> + <meta.section type="copyright"/> + </appinfo> + <documentation> + Copyright (c) 2008 IBM Corporation and others.<br> +All rights reserved. This program and the accompanying materials are made +available under the terms of the Eclipse Public License v1.0 which accompanies +this distribution, and is available at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + </documentation> + </annotation> + +</schema> diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/server/JettyHelpServer.java b/org.eclipse.help.base/src/org/eclipse/help/internal/server/JettyHelpServer.java new file mode 100644 index 000000000..34608f9e8 --- /dev/null +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/server/JettyHelpServer.java @@ -0,0 +1,123 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.help.internal.server; + +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.logging.Level; +import java.util.logging.Logger; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.Platform; +import org.eclipse.equinox.http.jetty.JettyConfigurator; +import org.eclipse.help.internal.base.HelpBasePlugin; +import org.eclipse.help.server.HelpServer; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleException; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + + +public class JettyHelpServer extends HelpServer { + + private String host; + private int port = -1; + private static final int AUTO_SELECT_JETTY_PORT = 0; + + public void start(String webappName) throws Exception { + Dictionary d = new Hashtable(); + + configurePort(); + d.put("http.port", new Integer(getPortParameter())); //$NON-NLS-1$ + + // set the base URL + d.put("context.path", "/help"); //$NON-NLS-1$ //$NON-NLS-2$ + d.put("other.info", "org.eclipse.help"); //$NON-NLS-1$ //$NON-NLS-2$ + + // suppress Jetty INFO/DEBUG messages to stderr + Logger.getLogger("org.mortbay").setLevel(Level.WARNING); //$NON-NLS-1$ + + JettyConfigurator.startServer(webappName, d); + checkBundle(); + + } + + /* + * Ensures that the bundle with the specified name and the highest available + * version is started and reads the port number + */ + private void checkBundle() throws InvalidSyntaxException, BundleException { + Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry"); //$NON-NLS-1$if (bundle != null) { + if (bundle.getState() == Bundle.RESOLVED) { + bundle.start(Bundle.START_TRANSIENT); + } + if (port == -1) { + // Jetty selected a port number for us + ServiceReference[] reference = bundle.getBundleContext().getServiceReferences("org.osgi.service.http.HttpService", "(other.info=org.eclipse.help)"); //$NON-NLS-1$ //$NON-NLS-2$ + Object assignedPort = reference[0].getProperty("http.port"); //$NON-NLS-1$ + port = Integer.parseInt((String)assignedPort); + } + } + + public void stop(String webappName) throws CoreException { + try { + JettyConfigurator.stopServer(webappName); + } + catch (Exception e) { + HelpBasePlugin.logError("An error occured while stopping the help server", e); //$NON-NLS-1$ + } + } + + public int getPort() { + return port; + } + + private void configurePort() { + if (port == -1) { + String portCommandLineOverride = HelpBasePlugin.getBundleContext().getProperty("server_port"); //$NON-NLS-1$ + if (portCommandLineOverride != null && portCommandLineOverride.trim().length() > 0) { + try { + port = Integer.parseInt(portCommandLineOverride); + } + catch (NumberFormatException e) { + String msg = "Help server port specified in VM arguments is invalid (" + portCommandLineOverride + ")"; //$NON-NLS-1$ //$NON-NLS-2$ + HelpBasePlugin.logError(msg, e); + } + } + } + } + + /* + * Get the port number which will be passed to Jetty + */ + private int getPortParameter() { + if (port == -1) { + return AUTO_SELECT_JETTY_PORT; + } + return port; + } + + public String getHost() { + if (host == null) { + String hostCommandLineOverride = HelpBasePlugin.getBundleContext().getProperty("server_host"); //$NON-NLS-1$ + if (hostCommandLineOverride != null && hostCommandLineOverride.trim().length() > 0) { + host = hostCommandLineOverride; + } + else { + host = "127.0.0.1"; //$NON-NLS-1$ + } + } + return host; + } + + +} diff --git a/org.eclipse.help.base/src/org/eclipse/help/internal/server/WebappManager.java b/org.eclipse.help.base/src/org/eclipse/help/internal/server/WebappManager.java index 23b7c3b9a..bbf737292 100644 --- a/org.eclipse.help.base/src/org/eclipse/help/internal/server/WebappManager.java +++ b/org.eclipse.help.base/src/org/eclipse/help/internal/server/WebappManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. + * Copyright (c) 2007, 2008 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -10,113 +10,67 @@ *******************************************************************************/ package org.eclipse.help.internal.server; -import java.util.Dictionary; -import java.util.Hashtable; -import java.util.logging.Level; -import java.util.logging.Logger; - import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.Platform; -import org.eclipse.equinox.http.jetty.JettyConfigurator; import org.eclipse.help.internal.base.HelpBasePlugin; -import org.osgi.framework.Bundle; -import org.osgi.framework.BundleException; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; +import org.eclipse.help.server.HelpServer; public class WebappManager { - - private static String host; - private static int port = -1; - private static final int AUTO_SELECT_JETTY_PORT = 0; - public static void start(String webappName) throws Exception { - Dictionary d = new Hashtable(); - - configurePort(); - d.put("http.port", new Integer(getPortParameter())); //$NON-NLS-1$ - - // set the base URL - d.put("context.path", "/help"); //$NON-NLS-1$ //$NON-NLS-2$ - d.put("other.info", "org.eclipse.help"); //$NON-NLS-1$ //$NON-NLS-2$ - - // suppress Jetty INFO/DEBUG messages to stderr - Logger.getLogger("org.mortbay").setLevel(Level.WARNING); //$NON-NLS-1$ + private static HelpServer server; + private static final String SERVER_EXTENSION_ID = "org.eclipse.help.base.server"; //$NON-NLS-1$ + private static final String SERVER_CLASS_ATTRIBUTE = "class"; //$NON-NLS-1$ - JettyConfigurator.startServer(webappName, d); - checkBundle(); - - } + private static HelpServer getHelpServer() { + if (server == null) { + createWebappServer(); + } + if (server == null) { + server = new JettyHelpServer(); + } + return server; + } - /* - * Ensures that the bundle with the specified name and the highest available - * version is started and reads the port number - */ - private static void checkBundle() throws InvalidSyntaxException, BundleException { - Bundle bundle = Platform.getBundle("org.eclipse.equinox.http.registry"); //$NON-NLS-1$if (bundle != null) { - if (bundle.getState() == Bundle.RESOLVED) { - bundle.start(Bundle.START_TRANSIENT); - } - if (port == -1) { - // Jetty selected a port number for us - ServiceReference[] reference = bundle.getBundleContext().getServiceReferences("org.osgi.service.http.HttpService", "(other.info=org.eclipse.help)"); //$NON-NLS-1$ //$NON-NLS-2$ - Object assignedPort = reference[0].getProperty("http.port"); //$NON-NLS-1$ - port = Integer.parseInt((String)assignedPort); - } + public static void start(String webappName) throws Exception { + getHelpServer().start(webappName); } public static void stop(String webappName) throws CoreException { - try { - JettyConfigurator.stopServer(webappName); - } - catch (Exception e) { - HelpBasePlugin.logError("An error occured while stopping the help server", e); //$NON-NLS-1$ - } + getHelpServer().stop(webappName); } public static int getPort() { - return port; + return getHelpServer().getPort(); } - private static void configurePort() { - if (port == -1) { - String portCommandLineOverride = HelpBasePlugin.getBundleContext().getProperty("server_port"); //$NON-NLS-1$ - if (portCommandLineOverride != null && portCommandLineOverride.trim().length() > 0) { - try { - port = Integer.parseInt(portCommandLineOverride); - } - catch (NumberFormatException e) { - String msg = "Help server port specified in VM arguments is invalid (" + portCommandLineOverride + ")"; //$NON-NLS-1$ //$NON-NLS-2$ - HelpBasePlugin.logError(msg, e); - } - } - } + public static String getHost() { + return getHelpServer().getHost(); } - /* - * Get the port number which will be passed to Jetty - */ - private static int getPortParameter() { - if (port == -1) { - return AUTO_SELECT_JETTY_PORT; - } - return port; - } - - public static String getHost() { - if (host == null) { - String hostCommandLineOverride = HelpBasePlugin.getBundleContext().getProperty("server_host"); //$NON-NLS-1$ - if (hostCommandLineOverride != null && hostCommandLineOverride.trim().length() > 0) { - host = hostCommandLineOverride; - } - else { - host = "127.0.0.1"; //$NON-NLS-1$ + private static void createWebappServer() { + IExtensionPoint point = Platform.getExtensionRegistry() + .getExtensionPoint(SERVER_EXTENSION_ID ); + if (point != null) { + IExtension[] extensions = point.getExtensions(); + if (extensions.length != 0) { + // We need to pick up the non-default configuration + IConfigurationElement[] elements = extensions[0] + .getConfigurationElements(); + if (elements.length == 0) + return; + IConfigurationElement serverElement = elements[0]; + // Instantiate the app server + try { + server = (HelpServer) (serverElement + .createExecutableExtension(SERVER_CLASS_ATTRIBUTE)); + } catch (CoreException e) { + HelpBasePlugin.logStatus(e.getStatus()); + } } } - return host; - } - - private WebappManager() { } } diff --git a/org.eclipse.help.base/src/org/eclipse/help/server/HelpServer.java b/org.eclipse.help.base/src/org/eclipse/help/server/HelpServer.java new file mode 100644 index 000000000..1a2c98673 --- /dev/null +++ b/org.eclipse.help.base/src/org/eclipse/help/server/HelpServer.java @@ -0,0 +1,56 @@ +/******************************************************************************* + * Copyright (c) 2008 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.help.server; +import org.eclipse.core.runtime.CoreException; + +/** + * @since 3.4 + * Abstract class representing a web server which can be used to host the Eclipse help + * system using the extension point org.eclipse.help.base.server. Classes extending this + * abstract class must be capable of launching a Web Server and + */ + +public abstract class HelpServer { + + /** + * Start a server application to host the Eclipse help system. The server is + * responsible for initializing the servlets, jsp files and other resources + * for the help system as defined by the extension points <code>org.eclipse.equinox.http.registry.resources</code> + * and <code>org.eclipse.equinox.http.registry.servlets</code> for the httpcontextId + * <code>org.eclipse.help.webapp.help</code> + * @param webappName The name of this web application + * @throws Exception + */ + public abstract void start(String webappName) throws Exception; + + /** + * Stop a server application. If an application of this name has not been started do nothing + * @param webappName the name of a running web application + * @throws CoreException + */ + public abstract void stop(String webappName) throws CoreException ; + + /** + * Returns the port number the app server listens on + * @return integer port number, 0 if server not started + */ + public abstract int getPort(); + + + /** + * Returns the host name or ip the app server runs on. + * + * @return String representation of host name of IP, null if server not + * started yet + */ + public abstract String getHost(); +} |