FELIX-1946: Only startup Jetty if either HTTP or HTTPS is enabled and improve messaging: If Jetty is not started, say so. If Jetty is started report ports of enabled HTTP and HTTPS services.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1056874 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
index 1637bab..14681a0 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyService.java
@@ -118,34 +118,54 @@
private void stopJetty()
{
- try {
- this.server.stop();
- } catch (Exception e) {
- SystemLogger.error("Exception while stopping Jetty.", e);
+ if (this.server != null)
+ {
+ try
+ {
+ this.server.stop();
+ this.server = null;
+ }
+ catch (Exception e)
+ {
+ SystemLogger.error("Exception while stopping Jetty.", e);
+ }
}
}
private void initializeJetty()
throws Exception
{
- HashUserRealm realm = new HashUserRealm("OSGi HTTP Service Realm");
- this.server = new Server();
- this.server.addUserRealm(realm);
+ if (this.config.isUseHttp() || this.config.isUseHttps())
+ {
+ StringBuffer message = new StringBuffer("Started jetty ").append(Server.getVersion()).append(" at port(s)");
+ HashUserRealm realm = new HashUserRealm("OSGi HTTP Service Realm");
+ this.server = new Server();
+ this.server.addUserRealm(realm);
- if (this.config.isUseHttp()) {
- initializeHttp();
+ if (this.config.isUseHttp())
+ {
+ initializeHttp();
+ message.append(" HTTP:").append(this.config.getHttpPort());
+ }
+
+ if (this.config.isUseHttps())
+ {
+ initializeHttps();
+ message.append(" HTTPS:").append(this.config.getHttpsPort());
+ }
+
+ Context context = new Context(this.server, "/", Context.SESSIONS);
+ context.addServlet(new ServletHolder(this.dispatcher), "/*");
+
+ this.server.start();
+ SystemLogger.info(message.toString());
+ }
+ else
+ {
+ SystemLogger.info("Jetty not started (HTTP and HTTPS disabled)");
}
- if (this.config.isUseHttps()) {
- initializeHttps();
- }
-
- Context context = new Context(this.server, "/", Context.SESSIONS);
- context.addServlet(new ServletHolder(this.dispatcher), "/*");
-
- this.server.start();
publishServiceProperties();
- SystemLogger.info("Started jetty " + Server.getVersion() + " at port " + this.config.getHttpPort());
}
private void initializeHttp()