Added more robust logging.
git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@818555 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
index 503825a..ec919fd 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractActivator.java
@@ -18,38 +18,26 @@
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
-import org.apache.felix.http.base.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+import org.apache.felix.http.base.internal.logger.LogServiceLogger;
public abstract class AbstractActivator
implements BundleActivator
{
private BundleContext context;
- private DispatcherServlet dispatcher;
- private HttpServiceController controller;
+ private LogServiceLogger logger;
protected final BundleContext getBundleContext()
{
return this.context;
}
- protected final DispatcherServlet getDispatcherServlet()
- {
- return this.dispatcher;
- }
-
- protected final HttpServiceController getHttpServiceController()
- {
- return this.controller;
- }
-
public final void start(BundleContext context)
throws Exception
{
this.context = context;
- this.controller = new HttpServiceController(this.context);
- this.dispatcher = new DispatcherServlet(this.controller);
-
- SystemLogger.get().open(context);
+ this.logger = new LogServiceLogger(context);
+ SystemLogger.setLogService(this.logger);
doStart();
}
@@ -57,10 +45,7 @@
throws Exception
{
doStop();
-
- this.controller.unregister();
- this.dispatcher.destroy();
- SystemLogger.get().close();
+ this.logger.close();
}
protected abstract void doStart()
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
new file mode 100644
index 0000000..c045700
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/AbstractHttpActivator.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.felix.http.base.internal;
+
+public abstract class AbstractHttpActivator
+ extends AbstractActivator
+{
+ private DispatcherServlet dispatcher;
+ private HttpServiceController controller;
+
+ protected final DispatcherServlet getDispatcherServlet()
+ {
+ return this.dispatcher;
+ }
+
+ protected final HttpServiceController getHttpServiceController()
+ {
+ return this.controller;
+ }
+
+ protected void doStart()
+ throws Exception
+ {
+ this.controller = new HttpServiceController(getBundleContext());
+ this.dispatcher = new DispatcherServlet(this.controller);
+ }
+
+ protected void doStop()
+ throws Exception
+ {
+ this.controller.unregister();
+ this.dispatcher.destroy();
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
index 51ed942..34e07a6 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextImpl.java
@@ -19,7 +19,7 @@
import org.osgi.service.http.HttpContext;
import org.osgi.framework.Bundle;
import org.apache.felix.http.base.internal.util.MimeTypes;
-import org.apache.felix.http.base.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import javax.servlet.ServletContext;
import javax.servlet.RequestDispatcher;
@@ -178,17 +178,17 @@
public void log(String message)
{
- SystemLogger.get().info(message);
+ SystemLogger.info(message);
}
public void log(Exception cause, String message)
{
- SystemLogger.get().error(message, cause);
+ SystemLogger.error(message, cause);
}
public void log(String message, Throwable cause)
{
- SystemLogger.get().error(message, cause);
+ SystemLogger.error(message, cause);
}
public String getServletContextName()
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java
index c461b0f..2fc3810 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/context/ServletContextManager.java
@@ -18,7 +18,6 @@
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
-
import javax.servlet.ServletContext;
import java.util.Map;
import java.util.HashMap;
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/AbstractLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/AbstractLogger.java
new file mode 100644
index 0000000..a1d2b7b
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/AbstractLogger.java
@@ -0,0 +1,23 @@
+package org.apache.felix.http.base.internal.logger;
+
+import org.osgi.service.log.LogService;
+import org.osgi.framework.ServiceReference;
+
+public abstract class AbstractLogger
+ implements LogService
+{
+ public final void log(int level, String message)
+ {
+ log(null, level, message, null);
+ }
+
+ public final void log(int level, String message, Throwable cause)
+ {
+ log(null, level, message, cause);
+ }
+
+ public final void log(ServiceReference ref, int level, String message)
+ {
+ log(ref, level, message, null);
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java
new file mode 100644
index 0000000..d7d2c68
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/ConsoleLogger.java
@@ -0,0 +1,49 @@
+package org.apache.felix.http.base.internal.logger;
+
+import org.osgi.framework.ServiceReference;
+import java.io.PrintStream;
+
+public final class ConsoleLogger
+ extends AbstractLogger
+{
+ private final PrintStream out;
+
+ public ConsoleLogger()
+ {
+ this(System.out);
+ }
+
+ public ConsoleLogger(PrintStream out)
+ {
+ this.out = out;
+ }
+
+ public void log(ServiceReference ref, int level, String message, Throwable cause)
+ {
+ StringBuffer str = new StringBuffer();
+ switch (level) {
+ case LOG_DEBUG:
+ str.append("[DEBUG] ");
+ break;
+ case LOG_INFO:
+ str.append("[INFO] ");
+ break;
+ case LOG_WARNING:
+ str.append("[WARNING] ");
+ break;
+ case LOG_ERROR:
+ str.append("[ERROR] ");
+ break;
+ }
+
+ if (ref != null) {
+ str.append("(").append(ref.toString()).append(") ");
+ }
+
+ str.append(message);
+ this.out.println(str.toString());
+ if (cause != null) {
+ cause.printStackTrace(this.out);
+ }
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceLogger.java
new file mode 100644
index 0000000..cdab153
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/LogServiceLogger.java
@@ -0,0 +1,35 @@
+package org.apache.felix.http.base.internal.logger;
+
+import org.osgi.util.tracker.ServiceTracker;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.ServiceReference;
+import org.osgi.service.log.LogService;
+
+public final class LogServiceLogger
+ extends AbstractLogger
+{
+ private final ConsoleLogger consoleLogger;
+ private final ServiceTracker tracker;
+
+ public LogServiceLogger(BundleContext context)
+ {
+ this.consoleLogger = new ConsoleLogger();
+ this.tracker = new ServiceTracker(context, LogService.class.getName(), null);
+ this.tracker.open();
+ }
+
+ public void close()
+ {
+ this.tracker.close();
+ }
+
+ public void log(ServiceReference ref, int level, String message, Throwable cause)
+ {
+ LogService log = (LogService)this.tracker.getService();
+ if (log != null) {
+ log.log(ref, level, message, cause);
+ } else {
+ this.consoleLogger.log(ref, level, message, cause);
+ }
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/NopLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/NopLogger.java
new file mode 100644
index 0000000..171eb60
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/NopLogger.java
@@ -0,0 +1,12 @@
+package org.apache.felix.http.base.internal.logger;
+
+import org.osgi.framework.ServiceReference;
+
+public final class NopLogger
+ extends AbstractLogger
+{
+ public void log(ServiceReference ref, int level, String message, Throwable cause)
+ {
+ // Do nothing
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
new file mode 100644
index 0000000..ef9c7f2
--- /dev/null
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/logger/SystemLogger.java
@@ -0,0 +1,41 @@
+package org.apache.felix.http.base.internal.logger;
+
+import org.osgi.service.log.LogService;
+
+public final class SystemLogger
+{
+ private final static LogService NOP = new NopLogger();
+ private static LogService LOGGER;
+
+ public static void setLogService(LogService service)
+ {
+ if (LOGGER == null) {
+ LOGGER = service;
+ }
+ }
+
+ private static LogService getLogger()
+ {
+ return LOGGER != null ? LOGGER : NOP;
+ }
+
+ public static void debug(String message)
+ {
+ getLogger().log(LogService.LOG_DEBUG, message);
+ }
+
+ public static void info(String message)
+ {
+ getLogger().log(LogService.LOG_INFO, message);
+ }
+
+ public static void warning(String message, Throwable cause)
+ {
+ getLogger().log(LogService.LOG_WARNING, message, cause);
+ }
+
+ public static void error(String message, Throwable cause)
+ {
+ getLogger().log(LogService.LOG_ERROR, message, cause);
+ }
+}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
index 45961d5..2dd1c3a 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceFactory.java
@@ -20,7 +20,6 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.ServiceRegistration;
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
-
import javax.servlet.ServletContext;
public final class HttpServiceFactory
@@ -37,7 +36,7 @@
public Object getService(Bundle bundle, ServiceRegistration reg)
{
- return new HttpServiceImpl(this.context, this.handlerRegistry, bundle);
+ return new HttpServiceImpl(bundle, this.context, this.handlerRegistry);
}
public void ungetService(Bundle bundle, ServiceRegistration reg, Object service)
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
index e972967..c08f1f5 100644
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
+++ b/http/base/src/main/java/org/apache/felix/http/base/internal/service/HttpServiceImpl.java
@@ -22,7 +22,7 @@
import org.apache.felix.http.base.internal.handler.HandlerRegistry;
import org.apache.felix.http.base.internal.handler.FilterHandler;
import org.apache.felix.http.base.internal.handler.ServletHandler;
-import org.apache.felix.http.base.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import org.osgi.service.http.HttpContext;
import org.osgi.service.http.NamespaceException;
import org.osgi.framework.Bundle;
@@ -42,13 +42,13 @@
private final HashSet<Filter> localFilters;
private final ServletContextManager contextManager;
- public HttpServiceImpl(ServletContext context, HandlerRegistry handlerRegistry, Bundle bundle)
+ public HttpServiceImpl(Bundle bundle, ServletContext context, HandlerRegistry handlerRegistry)
{
this.bundle = bundle;
this.handlerRegistry = handlerRegistry;
this.localServlets = new HashSet<Servlet>();
this.localFilters = new HashSet<Filter>();
- this.contextManager = new ServletContextManager(bundle, context);
+ this.contextManager = new ServletContextManager(this.bundle, context);
}
private ExtServletContext getServletContext(HttpContext context)
@@ -109,7 +109,7 @@
Servlet servlet = new ResourceServlet(name);
registerServlet(alias, servlet, null, context);
} catch (ServletException e) {
- SystemLogger.get().error("Failed to register resources", e);
+ SystemLogger.error("Failed to register resources", e);
}
}
diff --git a/http/base/src/main/java/org/apache/felix/http/base/internal/util/SystemLogger.java b/http/base/src/main/java/org/apache/felix/http/base/internal/util/SystemLogger.java
deleted file mode 100644
index 484c027..0000000
--- a/http/base/src/main/java/org/apache/felix/http/base/internal/util/SystemLogger.java
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.http.base.internal.util;
-
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-public final class SystemLogger
-{
- private final static SystemLogger INSTANCE =
- new SystemLogger();
-
- private ServiceTracker tracker;
-
- private SystemLogger()
- {
- }
-
- public void open(BundleContext context)
- {
- if (this.tracker != null) {
- return;
- }
-
- this.tracker = new ServiceTracker(context, LogService.class.getName(), null);
- this.tracker.open();
- }
-
- public void close()
- {
- this.tracker.close();
- this.tracker = null;
- }
-
- public void debug(String message)
- {
- log(LogService.LOG_DEBUG, message, null);
- }
-
- public void info(String message)
- {
- log(LogService.LOG_INFO, message, null);
- }
-
- public void warning(String message, Throwable cause)
- {
- log(LogService.LOG_WARNING, message, cause);
- }
-
- public void error(String message, Throwable cause)
- {
- log(LogService.LOG_ERROR, message, cause);
- }
-
- private void log(int level, String message, Throwable cause)
- {
- LogService log = (LogService)this.tracker.getService();
- if (log != null) {
- log.log(level, message, cause);
- } else {
- System.out.println(message);
- if (cause != null) {
- cause.printStackTrace(System.out);
- }
- }
- }
-
- public static SystemLogger get()
- {
- return INSTANCE;
- }
-}
\ No newline at end of file
diff --git a/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java b/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
index 08dc565..888dbe3 100644
--- a/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
+++ b/http/bridge/src/main/java/org/apache/felix/http/bridge/internal/BridgeActivator.java
@@ -18,24 +18,20 @@
import javax.servlet.http.HttpServlet;
import java.util.Hashtable;
-import org.apache.felix.http.base.internal.AbstractActivator;
+import org.apache.felix.http.base.internal.AbstractHttpActivator;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
public final class BridgeActivator
- extends AbstractActivator
+ extends AbstractHttpActivator
{
@Override
protected void doStart()
throws Exception
{
+ super.doStart();
Hashtable<String, Object> props = new Hashtable<String, Object>();
props.put("http.felix.dispatcher", getDispatcherServlet().getClass().getName());
getBundleContext().registerService(HttpServlet.class.getName(), getDispatcherServlet(), props);
- }
-
- @Override
- protected void doStop()
- throws Exception
- {
- // Do nothing
+ SystemLogger.info("Started bridged http service");
}
}
diff --git a/http/bundle/pom.xml b/http/bundle/pom.xml
index a2f2325..8d75432 100644
--- a/http/bundle/pom.xml
+++ b/http/bundle/pom.xml
@@ -27,7 +27,7 @@
<relativePath>../pom.xml</relativePath>
</parent>
- <name>Apache Felix Http Bridge</name>
+ <name>Apache Felix Http Bundle</name>
<artifactId>org.apache.felix.http.bundle</artifactId>
<packaging>bundle</packaging>
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
index 9549274..791045e 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyActivator.java
@@ -16,16 +16,17 @@
*/
package org.apache.felix.http.jetty.internal;
-import org.apache.felix.http.base.internal.AbstractActivator;
+import org.apache.felix.http.base.internal.AbstractHttpActivator;
public final class JettyActivator
- extends AbstractActivator
+ extends AbstractHttpActivator
{
private JettyService jetty;
protected void doStart()
throws Exception
{
+ super.doStart();
this.jetty = new JettyService(getBundleContext(), getDispatcherServlet());
this.jetty.start();
}
@@ -34,5 +35,6 @@
throws Exception
{
this.jetty.stop();
+ super.doStop();
}
}
diff --git a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyLogger.java b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyLogger.java
index 13f025c..6fd1312 100644
--- a/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyLogger.java
+++ b/http/jetty/src/main/java/org/apache/felix/http/jetty/internal/JettyLogger.java
@@ -17,8 +17,7 @@
package org.apache.felix.http.jetty.internal;
import org.mortbay.log.Logger;
-import org.apache.felix.http.base.internal.util.SystemLogger;
-
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import java.util.Map;
import java.util.HashMap;
@@ -65,27 +64,27 @@
public void debug(String msg, Throwable cause)
{
- SystemLogger.get().debug(msg);
+ SystemLogger.debug(msg);
}
public void debug(String msg, Object arg0, Object arg1)
{
- SystemLogger.get().debug(format(msg, arg0, arg1));
+ SystemLogger.debug(format(msg, arg0, arg1));
}
public void info(String msg, Object arg0, Object arg1)
{
- SystemLogger.get().info(format(msg, arg0, arg1));
+ SystemLogger.info(format(msg, arg0, arg1));
}
public void warn(String msg, Throwable cause)
{
- SystemLogger.get().warning(msg, cause);
+ SystemLogger.warning(msg, cause);
}
public void warn( String msg, Object arg0, Object arg1 )
{
- SystemLogger.get().warning(format(msg, arg0, arg1), null);
+ SystemLogger.warning(format(msg, arg0, arg1), null);
}
public String toString()
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 7cfffe9..3c42978 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
@@ -29,8 +29,9 @@
import org.mortbay.jetty.servlet.*;
import org.mortbay.log.Log;
import org.mortbay.log.StdErrLog;
-import org.apache.felix.http.base.internal.util.SystemLogger;
import org.apache.felix.http.base.internal.DispatcherServlet;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
import java.util.Properties;
import java.util.Dictionary;
@@ -99,7 +100,7 @@
try {
initializeJetty();
} catch (Exception e) {
- SystemLogger.get().error("Exception while initializing Jetty.", e);
+ SystemLogger.error("Exception while initializing Jetty.", e);
}
}
@@ -108,7 +109,7 @@
try {
this.server.stop();
} catch (Exception e) {
- SystemLogger.get().error("Exception while stopping Jetty.", e);
+ SystemLogger.error("Exception while stopping Jetty.", e);
}
}
diff --git a/http/whiteboard/pom.xml b/http/whiteboard/pom.xml
index 1b49f15..888a0cc 100644
--- a/http/whiteboard/pom.xml
+++ b/http/whiteboard/pom.xml
@@ -42,6 +42,7 @@
org.apache.felix.http.whiteboard.internal.WhiteboardActivator
</Bundle-Activator>
<Private-Package>
+ org.apache.felix.http.base.*,
org.apache.felix.http.whiteboard.*
</Private-Package>
<Import-Package>
@@ -72,6 +73,12 @@
<version>${pom.version}</version>
<scope>provided</scope>
</dependency>
+ <dependency>
+ <groupId>${pom.groupId}</groupId>
+ <artifactId>org.apache.felix.http.base</artifactId>
+ <version>${pom.version}</version>
+ <scope>provided</scope>
+ </dependency>
</dependencies>
</project>
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
index 0ffb830..43ec224 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/WhiteboardActivator.java
@@ -16,8 +16,6 @@
*/
package org.apache.felix.http.whiteboard.internal;
-import org.osgi.framework.BundleActivator;
-import org.osgi.framework.BundleContext;
import org.osgi.util.tracker.ServiceTracker;
import org.apache.felix.http.whiteboard.internal.tracker.FilterTracker;
import org.apache.felix.http.whiteboard.internal.tracker.HttpContextTracker;
@@ -25,11 +23,11 @@
import org.apache.felix.http.whiteboard.internal.tracker.HttpServiceTracker;
import org.apache.felix.http.whiteboard.internal.manager.ExtenderManagerImpl;
import org.apache.felix.http.whiteboard.internal.manager.ExtenderManager;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.AbstractActivator;
import java.util.ArrayList;
public final class WhiteboardActivator
- implements BundleActivator
+ extends AbstractActivator
{
private final ArrayList<ServiceTracker> trackers;
private ExtenderManager manager;
@@ -39,15 +37,14 @@
this.trackers = new ArrayList<ServiceTracker>();
}
- public void start(BundleContext context)
+ protected void doStart()
throws Exception
{
- SystemLogger.get().open(context);
this.manager = new ExtenderManagerImpl();
- addTracker(new HttpContextTracker(context, this.manager));
- addTracker(new FilterTracker(context, this.manager));
- addTracker(new ServletTracker(context, this.manager));
- addTracker(new HttpServiceTracker(context, this.manager));
+ addTracker(new HttpContextTracker(getBundleContext(), this.manager));
+ addTracker(new FilterTracker(getBundleContext(), this.manager));
+ addTracker(new ServletTracker(getBundleContext(), this.manager));
+ addTracker(new HttpServiceTracker(getBundleContext(), this.manager));
}
private void addTracker(ServiceTracker tracker)
@@ -56,7 +53,7 @@
tracker.open();
}
- public void stop(BundleContext context)
+ protected void doStop()
throws Exception
{
for (ServiceTracker tracker : this.trackers) {
@@ -65,6 +62,5 @@
this.trackers.clear();
this.manager.unregisterAll();
- SystemLogger.get().close();
}
}
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
index e144e1e..063116b 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ExtenderManagerImpl.java
@@ -22,7 +22,7 @@
import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import javax.servlet.Servlet;
import javax.servlet.Filter;
@@ -141,9 +141,9 @@
{
this.httpService = service;
if (this.httpService instanceof ExtHttpService) {
- SystemLogger.get().info("Detected extended HttpService. Filters enabled.");
+ SystemLogger.info("Detected extended HttpService. Filters enabled.");
} else {
- SystemLogger.get().info("Standard HttpService. Filters disabled.");
+ SystemLogger.info("Standard HttpService. Filters disabled.");
}
registerAll();
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
index bcccc0a..8ae62b4 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/FilterMapping.java
@@ -19,7 +19,8 @@
import org.osgi.service.http.HttpService;
import org.osgi.service.http.HttpContext;
import org.apache.felix.http.api.ExtHttpService;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
import javax.servlet.Filter;
public final class FilterMapping
@@ -49,7 +50,7 @@
try {
httpService.registerFilter(this.filter, this.pattern, getInitParams(), ranking, getContext());
} catch (Exception e) {
- SystemLogger.get().error("Failed to register filter", e);
+ SystemLogger.error("Failed to register filter", e);
}
}
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
index d44056e..e5f105e 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/HttpContextManager.java
@@ -18,7 +18,7 @@
import org.osgi.framework.Bundle;
import org.osgi.service.http.HttpContext;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
import java.util.HashMap;
public final class HttpContextManager
@@ -46,9 +46,9 @@
context = new DefaultHttpContext(bundle);
this.idMap.put(id, context);
this.contextMap.put(context, id);
- SystemLogger.get().debug("Added context with id [" + contextId + "]");
+ SystemLogger.debug("Added context with id [" + contextId + "]");
} else {
- SystemLogger.get().debug("Reusing context with id [" + contextId + "]");
+ SystemLogger.debug("Reusing context with id [" + contextId + "]");
}
return context;
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
index 408c58d..0a283e9 100644
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
+++ b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/manager/ServletMapping.java
@@ -18,7 +18,8 @@
import org.osgi.service.http.HttpService;
import org.osgi.service.http.HttpContext;
-import org.apache.felix.http.whiteboard.internal.util.SystemLogger;
+import org.apache.felix.http.base.internal.logger.SystemLogger;
+
import javax.servlet.Servlet;
public final class ServletMapping
@@ -39,7 +40,7 @@
try {
httpService.registerServlet(this.alias, this.servlet, getInitParams(), getContext());
} catch (Exception e) {
- SystemLogger.get().error("Failed to register servlet", e);
+ SystemLogger.error("Failed to register servlet", e);
}
}
diff --git a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java b/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
deleted file mode 100644
index df68069..0000000
--- a/http/whiteboard/src/main/java/org/apache/felix/http/whiteboard/internal/util/SystemLogger.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.felix.http.whiteboard.internal.util;
-
-import org.osgi.util.tracker.ServiceTracker;
-import org.osgi.framework.BundleContext;
-import org.osgi.service.log.LogService;
-
-public final class SystemLogger
-{
- private final static SystemLogger INSTANCE =
- new SystemLogger();
-
- private ServiceTracker tracker;
-
- private SystemLogger()
- {
- }
-
- public void open(BundleContext context)
- {
- this.tracker = new ServiceTracker(context, LogService.class.getName(), null);
- this.tracker.open();
- }
-
- public void close()
- {
- this.tracker.close();
- }
-
- public void debug(String message)
- {
- log(LogService.LOG_DEBUG, message, null);
- }
-
- public void info(String message)
- {
- log(LogService.LOG_INFO, message, null);
- }
-
- public void warning(String message, Throwable cause)
- {
- log(LogService.LOG_WARNING, message, cause);
- }
-
- public void error(String message, Throwable cause)
- {
- log(LogService.LOG_ERROR, message, cause);
- }
-
- private void log(int level, String message, Throwable cause)
- {
- LogService log = (LogService)this.tracker.getService();
- if (log != null) {
- log.log(level, message, cause);
- } else {
- System.out.println(message);
- if (cause != null) {
- cause.printStackTrace(System.out);
- }
- }
- }
-
- public static SystemLogger get()
- {
- return INSTANCE;
- }
-}
\ No newline at end of file