KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > equinox > http > jetty > JettyConfigurator


1 /*******************************************************************************
2  * Copyright (c) 2007 IBM Corporation and others
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.equinox.http.jetty;
12
13 import java.security.Permission JavaDoc;
14 import java.util.Dictionary JavaDoc;
15 import org.osgi.framework.Constants;
16 import org.osgi.service.cm.ConfigurationPermission;
17 import org.eclipse.equinox.http.jetty.internal.Activator;
18
19 /**
20  * <p>
21  * JettyConfigurator provides API level access for creating configured instances of a Jetty-based Http Service.
22  * The created instances are not persistent across re-starts of the bundle.
23  * </p>
24  * Settings: <br />
25  * <ul>
26  * <li>name="http.enabled" type="Boolean" (default: true)</li>
27  * <li>name="http.port" type="Integer" (default: 0 -- first available port)</li>
28  * <li>name="http.host" type="String" (default: 0.0.0.0 -- all network adapters)</li>
29  * <li>name="https.enabled" type="Boolean" (default: false)</li>
30  * <li>name="https.port" type="Integer" (default: 0 -- first available port)</li>
31  * <li>name="https.host" type="String" (default: 0.0.0.0 -- all network adapters)</li>
32  * <li>name="ssl.keystore" type="String"</li>
33  * <li>name="ssl.password" type="String"</li>
34  * <li>name="ssl.keypassword" type="String"</li>
35  * <li>name="ssl.needclientauth" type="Boolean"</li>
36  * <li>name="ssl.wantclientauth" type="Boolean"</li>
37  * <li>name="ssl.protocol" type="String"</li>
38  * <li>name="ssl.algorithm" type="String"</li>
39  * <li>name="ssl.keystoretype" type="String"</li>
40  * <li>name="context.path" type="String"</li>
41  * <li>name="context.sessioninactiveinterval" type="Integer"</li>
42  * <li>name="other.info" type="String"</li>
43  * </ul>
44  *
45  */

46 public class JettyConfigurator {
47     private static final String JavaDoc PID_PREFIX = "org.eclipse.equinox.http.jetty.JettyConfigurator."; //$NON-NLS-1$
48
private static Permission JavaDoc configurationPermission = new ConfigurationPermission("*", ConfigurationPermission.CONFIGURE); //$NON-NLS-1$
49

50     /**
51      * Creates an instance of Jetty parameterized with a dictionary of settings
52      * @param id The identifier for the server instance
53      * @param settings The dictionary of settings used to configure the server instance
54      * @throws Exception If the server failed to start for any reason
55      */

56     public static void startServer(String JavaDoc id, Dictionary JavaDoc settings) throws Exception JavaDoc {
57         checkConfigurationPermission();
58         String JavaDoc pid = PID_PREFIX + id;
59         settings.put(Constants.SERVICE_PID, pid);
60         Activator.startServer(pid, settings);
61     }
62
63     /**
64      * Stops a previously started instance of Jetty. If the identified instance is not started this will call will do nothing.
65      * @param id The identifier for the server instance
66      * @throws Exception If the server failed to stop for any reason.
67      */

68     public static void stopServer(String JavaDoc id) throws Exception JavaDoc {
69         checkConfigurationPermission();
70         Activator.stopServer(PID_PREFIX + id);
71     }
72
73     private static void checkConfigurationPermission() throws SecurityException JavaDoc {
74         SecurityManager JavaDoc sm = System.getSecurityManager();
75         if (sm != null)
76             sm.checkPermission(configurationPermission);
77     }
78 }
79
Popular Tags