Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
public class Activator implements BundleActivator
{

private static Object logService;
private static LogService logService;

private ServiceTracker logServiceTracker;
private ServiceTracker<LogService, LogService> logServiceTracker;

private InventoryPrinterManagerImpl printerManager;

Expand All @@ -42,17 +42,17 @@ public class Activator implements BundleActivator
*/
public void start(final BundleContext context) throws Exception
{
this.logServiceTracker = new ServiceTracker(context, "org.osgi.service.log.LogService", null)
this.logServiceTracker = new ServiceTracker<LogService, LogService>(context, LogService.class, null)
{
@Override
public Object addingService(ServiceReference reference)
public LogService addingService(ServiceReference<LogService> reference)
{
Activator.logService = super.addingService(reference);
return Activator.logService;
}

@Override
public void removedService(ServiceReference reference, Object service)
public void removedService(ServiceReference<LogService> reference, LogService service)
{
Activator.logService = null;
super.removedService(reference, service);
Expand Down Expand Up @@ -87,12 +87,11 @@ public void stop(final BundleContext context) throws Exception
}
}

public static void log(final ServiceReference sr, final int level, final String message, final Throwable exception)
public static void log(final int level, final String message, final Throwable exception)
{
Object logService = Activator.logService;
if (logService != null)
if (Activator.logService != null)
{
((LogService) logService).log(sr, level, message, exception);
Activator.logService.log(level, message, exception);
}
else
{
Expand All @@ -116,10 +115,10 @@ public static void log(final ServiceReference sr, final int level, final String
code = "*DEBUG*";
}

System.out.println(code + " " + message);
System.err.println(code + " " + message);
if (exception != null)
{
exception.printStackTrace(System.out);
exception.printStackTrace(System.err);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package org.apache.felix.inventory.impl.webconsole;

import java.io.PrintWriter;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.net.URL;
Expand All @@ -26,7 +27,9 @@
import java.util.Set;

import org.apache.felix.inventory.Format;
import org.apache.felix.inventory.impl.Activator;
import org.osgi.framework.ServiceReference;
import org.osgi.service.log.LogService;

/**
* Helper class for a configuration printer.
Expand Down Expand Up @@ -312,9 +315,27 @@ private static Object invoke(final Object obj, final Method m, final Object[] ar
{
return m.invoke(obj, args);
}
catch (final Throwable e)
catch (InvocationTargetException ite)
{
// ignore
Activator.log(
LogService.LOG_ERROR,
String.format(
"Error invoking method '%s' on %s: %s",
m.getName(),
obj.getClass(),
ite.getTargetException().getMessage()),
ite.getTargetException());
}
catch (IllegalAccessException iae)
{
Activator.log(
LogService.LOG_ERROR,
String.format(
"Illegal access while invoking method '%s' on %s: %s",
m.getName(),
obj.getClass(),
iae.getMessage()),
iae);
}
return null;
}
Expand Down