This is an automated email from the ASF dual-hosted git repository.
cziegeler pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/felix-dev.git
The following commit(s) were added to refs/heads/master by this push:
new 227a755771 FELIX-6651 : Use slf4j for logging
227a755771 is described below
commit 227a755771f161d9983abca1ea645b850ee9bdc0
Author: Carsten Ziegeler <[email protected]>
AuthorDate: Sat Sep 9 14:07:29 2023 +0200
FELIX-6651 : Use slf4j for logging
---
webconsole/pom.xml | 6 +
.../felix/webconsole/AbstractWebConsolePlugin.java | 80 +++----------
.../apache/felix/webconsole/WebConsoleUtil.java | 2 -
.../org/apache/felix/webconsole/internal/Util.java | 12 +-
.../internal/configuration/ConfigJsonSupport.java | 9 +-
.../internal/core/BaseUpdateInstallHelper.java | 17 +--
.../webconsole/internal/core/BundlesServlet.java | 25 ++--
.../webconsole/internal/core/ServicesServlet.java | 4 +-
.../webconsole/internal/core/UpdateHelper.java | 92 ++++++---------
.../internal/legacy/LegacyServicesTracker.java | 14 +--
.../webconsole/internal/misc/ServletSupport.java | 13 ---
.../servlet/AbstractOsgiManagerPlugin.java | 71 -----------
.../internal/servlet/AbstractPluginAdapter.java | 88 --------------
.../servlet/ConfigurationMetatypeSupport.java | 18 ---
.../internal/servlet/ConfigurationSupport.java | 12 +-
.../webconsole/internal/servlet/OsgiManager.java | 130 ++++-----------------
.../webconsole/internal/servlet/PluginHolder.java | 14 +--
.../webconsole/internal/system/VMStatPlugin.java | 5 +-
18 files changed, 132 insertions(+), 480 deletions(-)
diff --git a/webconsole/pom.xml b/webconsole/pom.xml
index 0762efa603..cda4ce8e59 100644
--- a/webconsole/pom.xml
+++ b/webconsole/pom.xml
@@ -352,6 +352,12 @@
</profiles>
<dependencies>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.36</version>
+ <scope>provided</scope>
+ </dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.annotation.versioning</artifactId>
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
index 7d58ac7d5d..e66125b517 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/AbstractWebConsolePlugin.java
@@ -37,14 +37,13 @@ import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
-import javax.servlet.ServletConfig;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.osgi.framework.Bundle;
@@ -140,8 +139,6 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet {
private static volatile BrandingPlugin BRANDING_PLUGIN =
DefaultBrandingPlugin.getInstance();
- private static volatile int LOGLEVEL;
-
//---------- HttpServlet Overwrites
----------------------------------------
@@ -432,76 +429,35 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet {
return getResourceMethod;
}
-
/**
- * Calls the <code>ServletContext.log(String)</code> method if the
- * configured log level is less than or equal to the given
<code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String)</code> method is called or not. The
- * actual implementation of the <code>GenericServlet.log</code> method is
- * outside of the control of this method.
- * <p>
- * If the servlet has not been initialized yet or has already been
destroyed
- * the message is printed to stderr.
+ * Logs the message in the level
*
* @param level The log level at which to log the message
* @param message The message to log
*/
- public void log( int level, String message )
- {
- if ( LOGLEVEL >= level )
- {
- ServletConfig config = getServletConfig();
- if ( config != null )
- {
- ServletContext context = config.getServletContext();
- if ( context != null )
- {
- context.log( message );
- return;
- }
- }
-
- System.err.println( message );
- }
+ public void log(final int level, final String message ) {
+ log(level, message, null);
}
-
/**
- * Calls the <code>ServletContext.log(String, Throwable)</code> method if
- * the configured log level is less than or equal to the given
- * <code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String, Throwable)</code> method is called
- * or not. The actual implementation of the <code>GenericServlet.log</code>
- * method is outside of the control of this method.
+ * Logs the message in the level
*
* @param level The log level at which to log the message
* @param message The message to log
* @param t The <code>Throwable</code> to log with the message
*/
- public void log( int level, String message, Throwable t )
- {
- if ( LOGLEVEL >= level )
- {
- ServletConfig config = getServletConfig();
- if ( config != null )
- {
- ServletContext context = config.getServletContext();
- if ( context != null )
- {
- context.log( message, t );
- return;
- }
- }
-
- System.err.println( message );
- if ( t != null )
- {
- t.printStackTrace( System.err );
- }
+ public void log(final int level, final String message, final Throwable t )
{
+ final String text = "[".concat(this.getTitle()).concat("]
").concat(message);
+ switch(level) {
+ case LogService.LOG_DEBUG: Util.LOGGER.debug(text, t);
+ break;
+ case LogService.LOG_INFO: Util.LOGGER.info(text, t);
+ break;
+ case LogService.LOG_WARNING: Util.LOGGER.warn(text, t);
+ break;
+ case LogService.LOG_ERROR: Util.LOGGER.error(text, t);
+ break;
+ default: Util.LOGGER.debug(message, t);
}
}
@@ -884,7 +840,7 @@ public abstract class AbstractWebConsolePlugin extends
HttpServlet {
* lower level it will not be forwarded to the logger.
*/
public static final void setLogLevel( final int logLevel ) {
- AbstractWebConsolePlugin.LOGLEVEL = logLevel;
+ // nothing to do
}
private final String getHeader() {
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
index 7b95414f16..aac06f6e69 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/WebConsoleUtil.java
@@ -21,8 +21,6 @@ package org.apache.felix.webconsole;
import java.io.File;
import java.io.IOException;
-import java.io.UnsupportedEncodingException;
-import java.lang.reflect.Array;
import java.net.URLDecoder;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
index 7ed3ea62ef..4a7d9db1eb 100644
--- a/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
+++ b/webconsole/src/main/java/org/apache/felix/webconsole/internal/Util.java
@@ -29,6 +29,8 @@ import org.osgi.framework.Bundle;
import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.Version;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
@@ -332,5 +334,13 @@ public class Util {
} else {
return value.toString();
}
- }
+ }
+
+ public static String toString(final ServiceReference<?> ref) {
+ return "Service " + ref.getProperty(Constants.SERVICE_ID) + "(" + ref
+ ") from bundle " +
+ ref.getBundle().getSymbolicName() + ":" +
ref.getBundle().getVersion() + "(" + ref.getBundle().getBundleId() + ")";
+ }
+
+ /** Logger for the webconsole */
+ public static final Logger LOGGER =
LoggerFactory.getLogger("org.apache.felix.webconsole");
}
\ No newline at end of file
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
index aedcbd63bc..bc556741d8 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/configuration/ConfigJsonSupport.java
@@ -53,7 +53,6 @@ import org.osgi.service.cm.Configuration;
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.cm.ManagedService;
import org.osgi.service.cm.ManagedServiceFactory;
-import org.osgi.service.log.LogService;
import org.osgi.service.metatype.AttributeDefinition;
import org.osgi.service.metatype.ObjectClassDefinition;
@@ -89,7 +88,7 @@ class ConfigJsonSupport {
this.configForm( result, pid, config, pidFilter, locale );
result.endObject();
} catch ( final Exception e ) {
- this.servletSupport.log( LogService.LOG_ERROR, "Error reading
configuration PID " + pid, e );
+ Util.LOGGER.error("Error reading configuration PID {}", pid, e
);
}
}
@@ -286,7 +285,7 @@ class ConfigJsonSupport {
serviceLocation = refs[0].getBundle().getLocation();
}
} catch (final Throwable t) {
- this.servletSupport.log( LogService.LOG_ERROR, "Error getting
service associated with configuration " + pid, t );
+ Util.LOGGER.error("Error getting service associated with
configuration {}", pid, t );
}
json.key( "bundle_location" );
json.value ( bundleLocation );
@@ -391,7 +390,7 @@ class ConfigJsonSupport {
}
jw.endArray();
} catch (final Exception e) {
- this.servletSupport.log( LogService.LOG_ERROR,
"listConfigurations: Unexpected problem encountered", e);
+ Util.LOGGER.error("listConfigurations: Unexpected problem
encountered", e);
}
return hasConfigurations;
}
@@ -523,7 +522,7 @@ class ConfigJsonSupport {
}
jw.endArray();
} catch (final Exception e) {
- this.servletSupport.log( LogService.LOG_ERROR,
"listFactoryConfigurations: Unexpected problem encountered", e);
+ Util.LOGGER.error("listFactoryConfigurations: Unexpected problem
encountered", e);
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
index ebd03ed163..00c082186a 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BaseUpdateInstallHelper.java
@@ -28,6 +28,7 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
+import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.misc.ServletSupport;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
@@ -38,7 +39,6 @@ import org.osgi.framework.FrameworkListener;
import org.osgi.framework.startlevel.BundleStartLevel;
import org.osgi.framework.startlevel.FrameworkStartLevel;
import org.osgi.framework.wiring.FrameworkWiring;
-import org.osgi.service.log.LogService;
abstract class BaseUpdateInstallHelper implements Runnable
@@ -72,19 +72,12 @@ abstract class BaseUpdateInstallHelper implements Runnable
protected abstract Bundle doRun( InputStream bundleStream ) throws
BundleException;
- protected final Object getService( String serviceName )
- {
+ protected final Object getService( String serviceName ) {
return plugin.getService( serviceName );
}
- protected final ServletSupport getLog()
- {
- return plugin;
- }
-
- protected Bundle getTargetBundle()
- {
+ protected Bundle getTargetBundle() {
return null;
}
@@ -183,7 +176,7 @@ abstract class BaseUpdateInstallHelper implements Runnable
throw ex;
} else {
try{
- getLog().log( LogService.LOG_ERROR, "Cannot
restart bundle: " + bundle + " after exception during update!", ex);
+ Util.LOGGER.error("Cannot restart bundle: {}
after exception during update!", bundle, ex);
} catch ( Exception secondary ) {
// at the time this exception happens the log
used might have
// been destroyed and is not available to use
any longer. So
@@ -198,7 +191,7 @@ abstract class BaseUpdateInstallHelper implements Runnable
}
} catch ( Exception e ) {
try {
- getLog().log( LogService.LOG_ERROR, "Cannot install or update
bundle from " + bundleFile, e );
+ Util.LOGGER.error("Cannot install or update bundle from {}",
bundleFile, e );
} catch ( Exception secondary ) {
// at the time this exception happens the log used might have
// been destroyed and is not available to use any longer. So
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
index a684347baf..78e5f7bb07 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/BundlesServlet.java
@@ -74,7 +74,6 @@ import org.osgi.framework.startlevel.FrameworkStartLevel;
import org.osgi.framework.wiring.BundleRevision;
import org.osgi.framework.wiring.FrameworkWiring;
import org.osgi.service.cm.ConfigurationAdmin;
-import org.osgi.service.log.LogService;
import org.osgi.service.packageadmin.ExportedPackage;
import org.osgi.service.packageadmin.PackageAdmin;
import org.osgi.util.tracker.ServiceTracker;
@@ -91,6 +90,7 @@ import jakarta.servlet.http.Part;
* the list of bundles, installed on the framework. It also adds ability to
control
* the lifecycle of the bundles, like start, stop, uninstall, install.
*/
+@SuppressWarnings("deprecation")
public class BundlesServlet extends AbstractOsgiManagerPlugin implements
InventoryPrinter {
/** the label of the bundles plugin - used by other plugins to reference
to plugin details */
@@ -314,7 +314,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
}
catch ( Exception e )
{
- log( "Problem rendering Bundle details for configuration status",
e );
+ Util.LOGGER.error( "Problem rendering Bundle details for
configuration status", e );
}
}
@@ -393,7 +393,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
bundle.start();
} catch ( BundleException be ) {
bundleException = be;
- log( "Cannot start", be );
+ Util.LOGGER.error( "Cannot start", be );
}
} else if ( "stop".equals( action ) ) {
// stop bundle
@@ -401,7 +401,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
bundle.stop();
} catch ( BundleException be ) {
bundleException = be;
- log( "Cannot stop", be );
+ Util.LOGGER.error( "Cannot stop", be );
}
} else if ( "refresh".equals( action ) ) {
// refresh bundle wiring and give at most 5 seconds to
finish
@@ -416,7 +416,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
bundle.uninstall();
} catch ( BundleException be ) {
bundleException = be;
- log( "Cannot uninstall", be );
+ Util.LOGGER.error( "Cannot uninstall", be );
}
}
@@ -1035,8 +1035,8 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
Object[] val;
if ( imports.size() > 0 )
{
- final List importList = new ArrayList();
- for ( Iterator ii = imports.values().iterator();
ii.hasNext(); )
+ final List<StringBuilder> importList = new ArrayList<>();
+ for ( Iterator<Clause> ii = imports.values().iterator();
ii.hasNext(); )
{
Clause r4Import = ( Clause ) ii.next();
ExportedPackage ep = ( ExportedPackage )
candidates.get( r4Import.getName() );
@@ -1239,14 +1239,14 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
}
- private Object collectImport(String name, Version version, boolean
optional,
+ private StringBuilder collectImport(String name, Version version, boolean
optional,
ExportedPackage export, final String pluginRoot )
{
return collectImport( name, ( version == null ) ? null :
version.toString(), optional, export, pluginRoot );
}
- private Object collectImport( String name, String version, boolean
optional, ExportedPackage export,
+ private StringBuilder collectImport( String name, String version, boolean
optional, ExportedPackage export,
final String pluginRoot )
{
StringBuilder val = new StringBuilder();
@@ -1484,8 +1484,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
try {
startLevel = Integer.parseInt( startLevelItem );
} catch ( NumberFormatException nfe ) {
- log( LogService.LOG_INFO, "Cannot parse start level parameter
" + startLevelItem
- + " to a number, not setting start level" );
+ Util.LOGGER.info("Cannot parse start level parameter {} to a
number, not setting start level", startLevelItem );
}
}
@@ -1503,7 +1502,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
IOUtils.copy(bundleStream, out);
}
} catch ( final Exception e ) {
- log( LogService.LOG_ERROR, "Problem accessing uploaded bundle
file: " + part.getSubmittedFileName(), e );
+ Util.LOGGER.error("Problem accessing uploaded bundle file:
{}", part.getSubmittedFileName(), e );
// remove the tmporary file
if ( tmpFile != null && tmpFile.exists()) {
@@ -1594,7 +1593,7 @@ public class BundlesServlet extends
AbstractOsgiManagerPlugin implements Invento
return new AbstractMap.SimpleImmutableEntry<>(sn, v);
}
} catch ( final IOException ioe ) {
- log( LogService.LOG_WARNING, "Cannot extract symbolic name and
version of bundle file " + bundleFile, ioe );
+ Util.LOGGER.warn("Cannot extract symbolic name and version of
bundle file {}", bundleFile, ioe );
} finally {
if ( jar != null ) {
try {
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
index 48c00e41fd..3b8a89b5a6 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/ServicesServlet.java
@@ -176,7 +176,7 @@ public class ServicesServlet extends
AbstractOsgiManagerPlugin
}
catch ( InvalidSyntaxException e )
{
- log( "Unable to search for services using filter " + filterStr, e
);
+ Util.LOGGER.error( "Unable to search for services using filter
{}", filterStr, e );
// this shouldn't happen
return null;
}
@@ -199,7 +199,7 @@ public class ServicesServlet extends
AbstractOsgiManagerPlugin
}
catch ( InvalidSyntaxException e )
{
- log( "Unable to access service reference list.", e );
+ Util.LOGGER.error( "Unable to access service reference list.", e );
}
// no services or invalid filter syntax (unlikely)
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
index fdfe178d3a..e1bc127da4 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/core/UpdateHelper.java
@@ -23,11 +23,11 @@ import java.io.File;
import java.io.InputStream;
import org.apache.felix.bundlerepository.Reason;
+import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.misc.ServletSupport;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleException;
import org.osgi.framework.Constants;
-import org.osgi.service.log.LogService;
import org.osgi.service.obr.RepositoryAdmin;
import org.osgi.service.obr.Requirement;
import org.osgi.service.obr.Resolver;
@@ -102,20 +102,16 @@ class UpdateHelper extends BaseUpdateInstallHelper
return null;
}
- private boolean updateFromBundleLocation()
- {
- getLog().log( LogService.LOG_DEBUG, "Trying to update with
Bundle.update()" );
+ private boolean updateFromBundleLocation() {
+ Util.LOGGER.debug("Trying to update with Bundle.update()" );
- try
- {
+ try {
bundle.update();
- getLog().log( LogService.LOG_INFO, "Bundle updated from bundle
provided (update) location" );
+ Util.LOGGER.info("Bundle updated from bundle provided (update)
location" );
return true;
- }
- catch ( Throwable ioe )
- {
+ } catch ( Throwable ioe ) {
// BundleException, IllegalStateException or SecurityException?
lets use OBR then
- getLog().log( LogService.LOG_DEBUG, "Update failure using
Bundle.update()", ioe );
+ Util.LOGGER.debug("Update failure using Bundle.update()", ioe );
}
// not installed from the bundle location
@@ -128,7 +124,7 @@ class UpdateHelper extends BaseUpdateInstallHelper
org.apache.felix.bundlerepository.RepositoryAdmin ra = (
org.apache.felix.bundlerepository.RepositoryAdmin ) getService(
"org.apache.felix.bundlerepository.RepositoryAdmin" );
if ( ra != null )
{
- getLog().log( LogService.LOG_DEBUG, "Trying to update from OSGi
Bundle Repository (Apache Felix API)" );
+ Util.LOGGER.debug("Trying to update from OSGi Bundle Repository
(Apache Felix API)" );
final org.apache.felix.bundlerepository.Resolver resolver =
ra.resolver();
@@ -162,20 +158,17 @@ class UpdateHelper extends BaseUpdateInstallHelper
// deploy the resolved bundles and ensure they are started
resolver.deploy(
org.apache.felix.bundlerepository.Resolver.START );
- getLog().log( LogService.LOG_INFO, "Bundle updated from
OSGi Bundle Repository" );
+ Util.LOGGER.info("Bundle updated from OSGi Bundle
Repository" );
return true;
}
}
else
{
- getLog().log( LogService.LOG_INFO,
- "Nothing to update, OSGi Bundle Repository does not provide
more recent version" );
+ Util.LOGGER.info("Nothing to update, OSGi Bundle Repository
does not provide more recent version" );
}
- }
- else
- {
- getLog().log( LogService.LOG_DEBUG, "Cannot updated from OSGi
Bundle Repository: Service not available" );
+ } else {
+ Util.LOGGER.debug("Cannot updated from OSGi Bundle Repository:
Service not available" );
}
// fallback to false, nothing done
@@ -187,7 +180,7 @@ class UpdateHelper extends BaseUpdateInstallHelper
RepositoryAdmin ra = ( RepositoryAdmin ) getService(
"org.osgi.service.obr.RepositoryAdmin" );
if ( ra != null )
{
- getLog().log( LogService.LOG_DEBUG, "Trying to update from OSGi
Bundle Repository (OSGi API)" );
+ Util.LOGGER.debug("Trying to update from OSGi Bundle Repository
(OSGi API)" );
final Resolver resolver = ra.resolver();
@@ -201,37 +194,28 @@ class UpdateHelper extends BaseUpdateInstallHelper
final Resource[] resources = ra.discoverResources( filter );
final Resource resource = selectHighestVersion( resources );
- if ( resource != null )
- {
+ if ( resource != null ) {
resolver.add( resource );
- if ( !resolver.resolve() )
- {
+ if ( !resolver.resolve() ) {
logRequirements( "Cannot updated bundle from OBR due to
unsatisfied requirements", resolver
.getUnsatisfiedRequirements() );
- }
- else
- {
+ } else {
logResource( "Installing Requested Resources",
resolver.getAddedResources() );
logResource( "Installing Required Resources",
resolver.getRequiredResources() );
logResource( "Installing Optional Resources",
resolver.getOptionalResources() );
// deploy the resolved bundles and ensure they are started
resolver.deploy( true );
- getLog().log( LogService.LOG_INFO, "Bundle updated from
OSGi Bundle Repository" );
+ Util.LOGGER.info("Bundle updated from OSGi Bundle
Repository" );
return true;
}
+ } else {
+ Util.LOGGER.info("Nothing to update, OSGi Bundle Repository
does not provide more recent version" );
}
- else
- {
- getLog().log( LogService.LOG_INFO,
- "Nothing to update, OSGi Bundle Repository does not
provide more recent version" );
- }
- }
- else
- {
- getLog().log( LogService.LOG_DEBUG, "Cannot updated from OSGi
Bundle Repository: Service not available" );
+ } else {
+ Util.LOGGER.debug("Cannot updated from OSGi Bundle Repository:
Service not available" );
}
// fallback to false, nothing done
@@ -272,11 +256,9 @@ class UpdateHelper extends BaseUpdateInstallHelper
{
if ( res != null && res.length > 0 )
{
- getLog().log( LogService.LOG_INFO, message );
- for ( int i = 0; i < res.length; i++ )
- {
- getLog().log( LogService.LOG_INFO,
- " " + i + ": " + res[i].getSymbolicName() + ", " +
res[i].getVersion() );
+ Util.LOGGER.info(message );
+ for ( int i = 0; i < res.length; i++ ) {
+ Util.LOGGER.info(" " + i + ": " + res[i].getSymbolicName() +
", " + res[i].getVersion() );
}
}
}
@@ -284,7 +266,7 @@ class UpdateHelper extends BaseUpdateInstallHelper
private void logRequirements( String message, Reason[] reasons )
{
- getLog().log( LogService.LOG_ERROR, message );
+ Util.LOGGER.error( message );
for ( int i = 0; reasons != null && i < reasons.length; i++ )
{
String moreInfo = reasons[i].getRequirement().getComment();
@@ -292,8 +274,7 @@ class UpdateHelper extends BaseUpdateInstallHelper
{
moreInfo = reasons[i].getRequirement().getFilter().toString();
}
- getLog().log( LogService.LOG_ERROR,
- " " + i + ": " + reasons[i].getRequirement().getName() + " ("
+ moreInfo + ")" );
+ Util.LOGGER.error(" " + i + ": " +
reasons[i].getRequirement().getName() + " (" + moreInfo + ")" );
}
}
@@ -326,23 +307,18 @@ class UpdateHelper extends BaseUpdateInstallHelper
}
- private void logResource( String message, Resource[] res )
- {
- if ( res != null && res.length > 0 )
- {
- getLog().log( LogService.LOG_INFO, message );
- for ( int i = 0; i < res.length; i++ )
- {
- getLog().log( LogService.LOG_INFO,
- " " + i + ": " + res[i].getSymbolicName() + ", " +
res[i].getVersion() );
+ private void logResource( String message, Resource[] res ) {
+ if ( res != null && res.length > 0 ) {
+ Util.LOGGER.info( message );
+ for ( int i = 0; i < res.length; i++ ) {
+ Util.LOGGER.info(" " + i + ": " + res[i].getSymbolicName() +
", " + res[i].getVersion() );
}
}
}
- private void logRequirements( String message, Requirement[] reasons )
- {
- getLog().log( LogService.LOG_ERROR, message );
+ private void logRequirements( String message, Requirement[] reasons ) {
+ Util.LOGGER.error( message );
for ( int i = 0; reasons != null && i < reasons.length; i++ )
{
String moreInfo = reasons[i].getComment();
@@ -350,7 +326,7 @@ class UpdateHelper extends BaseUpdateInstallHelper
{
moreInfo = reasons[i].getFilter().toString();
}
- getLog().log( LogService.LOG_ERROR, " " + i + ": " +
reasons[i].getName() + " (" + moreInfo + ")" );
+ Util.LOGGER.error( " " + i + ": " + reasons[i].getName() + " (" +
moreInfo + ")" );
}
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/legacy/LegacyServicesTracker.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/legacy/LegacyServicesTracker.java
index e8850ab089..e9c091fb23 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/legacy/LegacyServicesTracker.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/legacy/LegacyServicesTracker.java
@@ -44,7 +44,6 @@ import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -74,7 +73,7 @@ public class LegacyServicesTracker implements Closeable,
ServiceTrackerCustomize
}
this.servletTracker = new ServiceTracker<>(context, filter, this);
servletTracker.open();
- this.securityProviderTracker = new
LegacySecurityProviderTracker(pluginHolder, context);
+ this.securityProviderTracker = new
LegacySecurityProviderTracker(context);
}
@Override
@@ -87,8 +86,7 @@ public class LegacyServicesTracker implements Closeable,
ServiceTrackerCustomize
public LegacyServletPlugin addingService( final ServiceReference<Servlet>
reference ) {
final String label = Util.getStringProperty( reference,
ServletConstants.PLUGIN_LABEL );
if ( label != null ) {
- this.pluginHolder.getOsgiManager().log(LogService.LOG_WARNING,
- "Legacy webconsole plugin found. Update this to the Jakarta
Servlet API: " + reference);
+ Util.LOGGER.warn("Legacy webconsole plugin found. Update this to
the Jakarta Servlet API: {}", Util.toString(reference));
final LegacyServletPlugin plugin = new
LegacyServletPlugin(this.pluginHolder, reference, label);
pluginHolder.addPlugin(plugin);
@@ -142,11 +140,8 @@ public class LegacyServicesTracker implements Closeable,
ServiceTrackerCustomize
private final BundleContext bundleContext;
- private final PluginHolder pluginHolder;
-
- public LegacySecurityProviderTracker(final PluginHolder holder, final
BundleContext context ) {
+ public LegacySecurityProviderTracker(final BundleContext context ) {
this.bundleContext = context;
- this.pluginHolder = holder;
this.tracker = new ServiceTracker<>(context,
WebConsoleSecurityProvider.class, this);
tracker.open();
}
@@ -157,8 +152,7 @@ public class LegacyServicesTracker implements Closeable,
ServiceTrackerCustomize
@Override
public ServiceRegistration<SecurityProvider> addingService( final
ServiceReference<WebConsoleSecurityProvider> reference ) {
- this.pluginHolder.getOsgiManager().log(LogService.LOG_WARNING,
- "Legacy webconsole plugin found. Update this to the Jakarta
Servlet API: " + reference);
+ Util.LOGGER.warn("Legacy webconsole plugin found. Update this to
the Jakarta Servlet API: {}", Util.toString(reference));
final WebConsoleSecurityProvider provider =
this.bundleContext.getService(reference);
if ( provider != null ) {
final SecurityProvider wrapper = provider instanceof
WebConsoleSecurityProvider2
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ServletSupport.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ServletSupport.java
index 5f735d8c5f..70cb783a4a 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ServletSupport.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/misc/ServletSupport.java
@@ -22,19 +22,6 @@ import org.osgi.framework.BundleContext;
public interface ServletSupport {
- /**
- * Log the message
- * @param msg a log message
- */
- void log(int level, String msg);
-
- /**
- * Log the message
- * @param message a log message
- * @param t a throwable
- */
- void log(int level, String message, Throwable t);
-
/**
* Get the bundle context
* @return The bundle contect
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractOsgiManagerPlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractOsgiManagerPlugin.java
index af665f3f8a..67b0983ba0 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractOsgiManagerPlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractOsgiManagerPlugin.java
@@ -32,8 +32,6 @@ import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletContext;
import jakarta.servlet.http.HttpServletRequest;
public abstract class AbstractOsgiManagerPlugin extends AbstractServlet
implements OsgiManagerPlugin, ServletSupport {
@@ -46,11 +44,6 @@ public abstract class AbstractOsgiManagerPlugin extends
AbstractServlet implemen
*/
public static final String ATTR_LABEL_MAP = "felix.webconsole.labelMap";
- /**
- * Log level to be used by the web console
- */
- public static volatile int LOGLEVEL;
-
// used to obtain services. Structure is: service name -> ServiceTracker
private final Map<String, ServiceTracker<?, ?>> services = new HashMap<>();
@@ -159,70 +152,6 @@ public abstract class AbstractOsgiManagerPlugin extends
AbstractServlet implemen
return ret;
}
- /**
- * Calls the <code>ServletContext.log(String)</code> method if the
- * configured log level is less than or equal to the given
<code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String)</code> method is called or not. The
- * actual implementation of the <code>GenericServlet.log</code> method is
- * outside of the control of this method.
- * <p>
- * If the servlet has not been initialized yet or has already been
destroyed
- * the message is printed to stderr.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- */
- public void log( int level, String message ) {
- if ( LOGLEVEL >= level ) {
- ServletConfig config = getServletConfig();
- if ( config != null ) {
- ServletContext context = config.getServletContext();
- if ( context != null ) {
- context.log( message );
- return;
- }
- }
-
- System.err.println( message );
- }
- }
-
-
- /**
- * Calls the <code>ServletContext.log(String, Throwable)</code> method if
- * the configured log level is less than or equal to the given
- * <code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String, Throwable)</code> method is called
- * or not. The actual implementation of the <code>GenericServlet.log</code>
- * method is outside of the control of this method.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- * @param t The <code>Throwable</code> to log with the message
- */
- public void log( int level, String message, Throwable t ) {
- if ( LOGLEVEL >= level ) {
- ServletConfig config = getServletConfig();
- if ( config != null ) {
- ServletContext context = config.getServletContext();
- if ( context != null ) {
- context.log( message, t );
- return;
- }
- }
-
- System.err.println( message );
- if ( t != null ) {
- t.printStackTrace( System.err );
- }
- }
- }
-
-
@Override
public BundleContext getBundleContext() {
return this.bundleContext;
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractPluginAdapter.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractPluginAdapter.java
index 063ca244fb..205921759c 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractPluginAdapter.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/AbstractPluginAdapter.java
@@ -33,10 +33,7 @@ import java.util.TreeMap;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
import org.apache.felix.webconsole.servlet.ServletConstants;
import org.apache.felix.webconsole.spi.BrandingPlugin;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.ServletRequest;
import jakarta.servlet.http.HttpServlet;
@@ -66,8 +63,6 @@ public abstract class AbstractPluginAdapter extends
HttpServlet {
private static volatile BrandingPlugin BRANDING_PLUGIN = new
BrandingPluginImpl();
- private static volatile int LOGLEVEL;
-
private volatile BundleContext bundleContext;
private final String title;
@@ -199,75 +194,6 @@ public abstract class AbstractPluginAdapter extends
HttpServlet {
return bundleContext;
}
- /**
- * Returns the <code>Bundle</code> pertaining to the
- * {@link #getBundleContext() bundle context} with which this plugin has
- * been activated. If the plugin has not be activated by calling the
- * {@link #activate(BundleContext)} method, this method returns
- * <code>null</code>.
- *
- * @return the bundle or <code>null</code> if the plugin is not activated.
- */
- private final Bundle getBundle() {
- final BundleContext bundleContext = getBundleContext();
- return ( bundleContext != null ) ? bundleContext.getBundle() : null;
- }
-
- /**
- * Calls the <code>ServletContext.log(String)</code> method if the
- * configured log level is less than or equal to the given
<code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String)</code> method is called or not. The
- * actual implementation of the <code>GenericServlet.log</code> method is
- * outside of the control of this method.
- * <p>
- * If the servlet has not been initialized yet or has already been
destroyed
- * the message is printed to stderr.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- */
- public void log(final int level, final String message ) {
- this.log(level, message, null);
- }
-
- /**
- * Calls the <code>ServletContext.log(String, Throwable)</code> method if
- * the configured log level is less than or equal to the given
- * <code>level</code>.
- * <p>
- * Note, that the <code>level</code> paramter is only used to decide
whether
- * the <code>GenericServlet.log(String, Throwable)</code> method is called
- * or not. The actual implementation of the <code>GenericServlet.log</code>
- * method is outside of the control of this method.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- * @param t The <code>Throwable</code> to log with the message
- */
- public void log(final int level, final String message, final Throwable t )
{
- if ( LOGLEVEL >= level ) {
- final ServletConfig config = getServletConfig();
- if ( config != null ) {
- final ServletContext context = config.getServletContext();
- if ( context != null ) {
- if ( t != null ) {
- context.log( message, t );
- } else {
- context.log( message );
- }
- return;
- }
- }
-
- System.err.println( message );
- if ( t != null ) {
- t.printStackTrace( System.err );
- }
- }
- }
-
/**
* Spool the resource
* @throws IOException If an error occurs accessing or spooling the
resource.
@@ -496,20 +422,6 @@ public abstract class AbstractPluginAdapter extends
HttpServlet {
}
}
- /**
- * Sets the log level to be applied for calls to the {@link #log(int,
String)}
- * and {@link #log(int, String, Throwable)} methods.
- * <p>
- * Note: This method is intended to be used internally by the Web Console
- * to update the log level according to the Web Console configuration.
- *
- * @param logLevel the maximum allowed log level. If message is logged with
- * lower level it will not be forwarded to the logger.
- */
- public static final void setLogLevel( final int logLevel ) {
- AbstractPluginAdapter.LOGLEVEL = logLevel;
- }
-
private static final String readTemplateFile( final String templateFile) {
try(final InputStream templateStream =
AbstractPluginAdapter.class.getResourceAsStream( templateFile )) {
if ( templateStream != null ) {
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationMetatypeSupport.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationMetatypeSupport.java
index bb22249947..afa2f1333c 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationMetatypeSupport.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationMetatypeSupport.java
@@ -111,24 +111,6 @@ class ConfigurationMetatypeSupport extends
ConfigurationSupport implements MetaT
adList.add( new AttributeDefinitionImpl( propKey, getString( rb,
"metadata." + propKey + ".name", propKey ),
getString( rb, "metadata." + propKey + ".description", propKey
), OsgiManager.DEFAULT_ENABLE_SECRET_HEURISTIC ) );
- // log level is select - so no simple default value; requires
localized option labels
- adList.add( new AttributeDefinitionImpl( OsgiManager.PROP_LOG_LEVEL,
getString( rb,
- "metadata.loglevel.name", OsgiManager.PROP_LOG_LEVEL ),
- getString( rb, "metadata.loglevel.description",
OsgiManager.PROP_LOG_LEVEL ),
- AttributeDefinition.INTEGER, // type
- new String[]
- { String.valueOf( ConfigurationUtil.getProperty(
defaultConfig, OsgiManager.PROP_LOG_LEVEL,
- OsgiManager.DEFAULT_LOG_LEVEL ) ) }, // default values
- 0, // cardinality
- new String[]
- { // option labels
- getString( rb, "log.level.debug", "Debug" ),
- getString( rb, "log.level.info", "Information" ),
- getString( rb, "log.level.warn", "Warn" ),
- getString( rb, "log.level.error", "Error" ),
- }, new String[]
- { "4", "3", "2", "1" } ) );
-
// list plugins - requires localized plugin titles
final TreeMap<String, String> namesByClassName = new TreeMap<>();
final String[] defaultPluginsClasses = PluginHolder.PLUGIN_MAP;
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationSupport.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationSupport.java
index 444eeb6591..3453ad250a 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationSupport.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/ConfigurationSupport.java
@@ -45,13 +45,13 @@ class ConfigurationSupport implements ManagedService
//---------- ManagedService
- public void updated( final Dictionary config ) throws
ConfigurationException
+ public void updated( final Dictionary<String, ?> config ) throws
ConfigurationException
{
if (null != System.getSecurityManager())
{
try
{
- AccessController.doPrivileged(new PrivilegedExceptionAction()
+ AccessController.doPrivileged(new PrivilegedExceptionAction<>()
{
public Object run() throws Exception
{
@@ -79,7 +79,7 @@ class ConfigurationSupport implements ManagedService
}
}
- void updated0( Dictionary config ) throws ConfigurationException
+ void updated0( Dictionary<String, ?> config ) throws ConfigurationException
{
// validate hashed password
if ( isPasswordHashed( config ) )
@@ -91,7 +91,7 @@ class ConfigurationSupport implements ManagedService
// hash the password, update config and wait for the
// updated configuration to be supplied later
final BundleContext bc = this.osgiManager.getBundleContext();
- final ServiceReference ref = bc.getServiceReference(
ConfigurationAdmin.class.getName() );
+ final ServiceReference<?> ref = bc.getServiceReference(
ConfigurationAdmin.class.getName() );
if ( ref != null )
{
final ConfigurationAdmin ca = ( ConfigurationAdmin )
bc.getService( ref );
@@ -100,7 +100,7 @@ class ConfigurationSupport implements ManagedService
try
{
Configuration cfg = ca.getConfiguration(
this.osgiManager.getConfigurationPid() );
- Dictionary newConfig = cfg.getProperties();
+ Dictionary<String, Object> newConfig =
cfg.getProperties();
if ( newConfig != null )
{
String pwd = ( String ) config.get(
OsgiManager.PROP_PASSWORD );
@@ -129,7 +129,7 @@ class ConfigurationSupport implements ManagedService
}
- private boolean isPasswordHashed( final Dictionary config )
+ private boolean isPasswordHashed( final Dictionary<String, ?> config )
{
// assume hashed (default) password if no config
if ( config == null )
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
index bf48602cde..845d4d0e52 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/OsgiManager.java
@@ -57,15 +57,12 @@ import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceFactory;
import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
-import org.osgi.service.log.LogService;
import org.osgi.service.servlet.context.ServletContextHelper;
import org.osgi.service.servlet.whiteboard.HttpWhiteboardConstants;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
import jakarta.servlet.Servlet;
-import jakarta.servlet.ServletConfig;
-import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.Cookie;
import jakarta.servlet.http.HttpServlet;
@@ -133,8 +130,6 @@ public class OsgiManager extends HttpServlet {
private static final String FRAMEWORK_PROP_PASSWORD =
"felix.webconsole.password";
- private static final String FRAMEWORK_PROP_LOG_LEVEL =
"felix.webconsole.loglevel";
-
private static final String FRAMEWORK_PROP_LOCALE =
"felix.webconsole.locale";
private static final String FRAMEWORK_SHUTDOWN_TIMEOUT =
"felix.webconsole.shutdown.timeout";
@@ -157,8 +152,6 @@ public class OsgiManager extends HttpServlet {
static final String PROP_ENABLED_PLUGINS = "plugins";
- static final String PROP_LOG_LEVEL = "loglevel";
-
static final String PROP_LOCALE = "locale";
static final String PROP_ENABLE_SECRET_HEURISTIC =
"secret.heuristic.enabled";
@@ -171,8 +164,6 @@ public class OsgiManager extends HttpServlet {
/** The timeout for VMStat plugin page reload */
public static final String PROP_RELOAD_TIMEOUT = "reload.timeout";
- public static final int DEFAULT_LOG_LEVEL = LogService.LOG_WARNING;
-
static final String DEFAULT_PAGE = BundlesServlet.NAME;
static final String DEFAULT_REALM = "OSGi Management Console";
@@ -226,6 +217,7 @@ public class OsgiManager extends HttpServlet {
private ServiceTracker<SecurityProvider, SecurityProvider>
securityProviderTracker;
+ @SuppressWarnings("rawtypes")
private ServiceRegistration configurationListener;
// list of OsgiManagerPlugin instances activated during init. All these
@@ -258,10 +250,9 @@ public class OsgiManager extends HttpServlet {
final ResourceBundleManager resourceBundleManager;
- private volatile int logLevel = DEFAULT_LOG_LEVEL;
-
private volatile String defaultCategory = DEFAULT_CATEGORY;
+ @SuppressWarnings("rawtypes")
public OsgiManager(BundleContext bundleContext) {
this.bundleContext = bundleContext;
this.holder = new PluginHolder(this, bundleContext);
@@ -302,8 +293,6 @@ public class OsgiManager extends HttpServlet {
ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_USER_NAME, DEFAULT_USER_NAME ) );
this.defaultConfiguration.put( PROP_PASSWORD,
ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_PASSWORD, DEFAULT_PASSWORD ) );
- this.defaultConfiguration.put( PROP_LOG_LEVEL,
- ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_LOG_LEVEL, DEFAULT_LOG_LEVEL ) );
this.defaultConfiguration.put( PROP_LOCALE,
ConfigurationUtil.getProperty( bundleContext,
FRAMEWORK_PROP_LOCALE, null ) );
this.defaultConfiguration.put( PROP_SHUTDOWN_TIMEOUT,
@@ -375,9 +364,9 @@ public class OsgiManager extends HttpServlet {
// message is just a class name, try to be more descriptive
message = "Class " + message + " missing";
}
- this.log(LogService.LOG_INFO, pluginClassName + " not enabled.
Reason: " + message);
+ Util.LOGGER.info("{} not enabled. Reason: {}", pluginClassName,
message);
} catch (final Throwable t) {
- this.log(LogService.LOG_INFO, "Failed to instantiate plugin " +
pluginClassName + ". Reason: " + t);
+ Util.LOGGER.info("Failed to instantiate plugin: {}. Reason: {}",
pluginClassName, t.getMessage(), t);
}
return null;
}
@@ -387,8 +376,8 @@ public class OsgiManager extends HttpServlet {
// register servlet context helper, servlet, resources
this.registerHttpWhiteboardServices();
} else {
- log(LogService.LOG_INFO, "Not all requirements met for the Web
Console. Required security providers: "
- + this.registeredSecurityProviders + " Registered security
providers: " + this.registeredSecurityProviders);
+ Util.LOGGER.info("Not all requirements met for the Web Console.
Required security providers: {}."
+ + " Registered security providers: {}",
this.registeredSecurityProviders, this.registeredSecurityProviders);
// Not all requirements met, unregister services
this.unregisterHttpWhiteboardServices();
}
@@ -402,8 +391,7 @@ public class OsgiManager extends HttpServlet {
resourceBundleManager.dispose();
// stop listening for brandings
- if (brandingTracker != null)
- {
+ if (brandingTracker != null) {
brandingTracker.close();
brandingTracker = null;
}
@@ -422,15 +410,13 @@ public class OsgiManager extends HttpServlet {
this.unregisterHttpWhiteboardServices();
// stop listening for configuration
- if (configurationListener != null)
- {
+ if (configurationListener != null) {
configurationListener.unregister();
configurationListener = null;
}
// stop tracking security provider
- if (securityProviderTracker != null)
- {
+ if (securityProviderTracker != null) {
securityProviderTracker.close();
securityProviderTracker = null;
}
@@ -449,13 +435,10 @@ public class OsgiManager extends HttpServlet {
public void service(final HttpServletRequest req, final
HttpServletResponse res)
throws ServletException, IOException {
// don't really expect to be called within a non-HTTP environment
- try
- {
- AccessController.doPrivileged(new
PrivilegedExceptionAction<Object>()
- {
+ try {
+ AccessController.doPrivileged(new
PrivilegedExceptionAction<Object>() {
@Override
- public Object run() throws Exception
- {
+ public Object run() throws Exception {
final HttpServletRequest wrapper = new
HttpServletRequestWrapper((HttpServletRequest) req) {
@Override
public String getServletPath() {
@@ -471,20 +454,13 @@ public class OsgiManager extends HttpServlet {
return null;
}
});
- }
- catch (PrivilegedActionException e)
- {
+ } catch (PrivilegedActionException e) {
Exception x = e.getException();
- if (x instanceof IOException)
- {
+ if (x instanceof IOException) {
throw (IOException) x;
- }
- else if (x instanceof ServletException)
- {
+ } else if (x instanceof ServletException) {
throw (ServletException) x;
- }
- else
- {
+ } else {
throw new IOException(x.toString());
}
}
@@ -568,6 +544,7 @@ public class OsgiManager extends HttpServlet {
plugin.getConsolePlugin().service(request, response);
}
+ @SuppressWarnings("deprecation")
private void initRequest(final HttpServletRequest request, final String
postfix, final Locale locale) {
@SuppressWarnings("rawtypes")
final Map labelMap = holder.getLocalizedLabelMap(
resourceBundleManager, locale, this.defaultCategory );
@@ -586,13 +563,13 @@ public class OsgiManager extends HttpServlet {
request.setAttribute(ATTR_LABEL_MAP_OLD, flatLabelMap);
request.setAttribute(ATTR_APP_ROOT_OLD, appRoot);
- @SuppressWarnings("deprecation")
final RequestVariableResolver resolver = new
org.apache.felix.webconsole.DefaultVariableResolver();
request.setAttribute(RequestVariableResolver.REQUEST_ATTRIBUTE,
resolver);
resolver.put( RequestVariableResolver.KEY_APP_ROOT, (String)
request.getAttribute( ServletConstants.ATTR_APP_ROOT ) );
resolver.put( RequestVariableResolver.KEY_PLUGIN_ROOT, (String)
request.getAttribute( ServletConstants.ATTR_PLUGIN_ROOT ) );
}
+ @SuppressWarnings("deprecation")
private final void logout(final HttpServletRequest request, final
HttpServletResponse response) throws IOException {
final SecurityProvider securityProvider =
securityProviderTracker.getService();
securityProvider.logout(request, response);
@@ -708,70 +685,10 @@ public class OsgiManager extends HttpServlet {
* Returns the Service PID used to retrieve configuration and to describe
* the configuration properties.
*/
- String getConfigurationPid()
- {
+ String getConfigurationPid() {
return getClass().getName();
}
-
- /**
- * Calls the <code>ServletContext.log(String)</code> method if the
- * configured log level is less than or equal to the given
<code>level</code>.
- * <p>
- * Note, that the <code>level</code> parameter is only used to decide
whether
- * the <code>GenericServlet.log(String)</code> method is called or not. The
- * actual implementation of the <code>GenericServlet.log</code> method is
- * outside of the control of this method.
- * <p>
- * If the servlet has not been initialized yet or has already been
destroyed
- * the message is printed to stderr.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- */
- public void log(final int level, final String message) {
- this.log(level, message, null);
- }
-
- /**
- * Calls the <code>ServletContext.log(String, Throwable)</code> method if
- * the configured log level is less than or equal to the given
- * <code>level</code>.
- * <p>
- * Note, that the <code>level</code> parameter is only used to decide
whether
- * the <code>GenericServlet.log(String, Throwable)</code> method is called
- * or not. The actual implementation of the <code>GenericServlet.log</code>
- * method is outside of the control of this method.
- * <p>
- * If the servlet has not been initialized yet or has already been
destroyed
- * the message is printed to stderr.
- *
- * @param level The log level at which to log the message
- * @param message The message to log
- * @param t The <code>Throwable</code> to log with the message
- */
- public void log(final int level, final String message, final Throwable t) {
- if (logLevel >= level) {
- final ServletConfig config = getServletConfig();
- if ( config != null ) {
- final ServletContext context = config.getServletContext();
- if ( context != null ) {
- if (t != null) {
- context.log( message, t );
- } else {
- context.log( message );
- }
- return;
- }
- }
-
- System.err.println( message );
- if ( t != null ) {
- t.printStackTrace( System.err );
- }
- }
- }
-
private HttpServletRequest wrapRequest(final HttpServletRequest request,
final Locale locale) {
return new HttpServletRequestWrapper(request) {
@Override
@@ -939,7 +856,7 @@ public class OsgiManager extends HttpServlet {
this.servletRegistration =
getBundleContext().registerService(Servlet.class, this, props);
}
} catch (final Exception e) {
- log(LogService.LOG_ERROR, "registerHttpWhiteboardServices: Problem
setting up", e);
+ Util.LOGGER.error("registerHttpWhiteboardServices: Problem setting
up", e);
this.unregisterHttpWhiteboardServices();
}
}
@@ -981,7 +898,7 @@ public class OsgiManager extends HttpServlet {
return defaultConfiguration;
}
- synchronized void updateConfiguration( final Dictionary<String, Object>
osgiConfig) {
+ synchronized void updateConfiguration( final Dictionary<String, ?>
osgiConfig) {
final Map<String, Object> config = new HashMap<String, Object>(
this.defaultConfiguration );
if ( osgiConfig != null ) {
@@ -996,11 +913,6 @@ public class OsgiManager extends HttpServlet {
final Object locale = config.get(PROP_LOCALE);
this.configuredLocale = locale == null ||
locale.toString().trim().length() == 0 ? null :
Util.parseLocaleString(locale.toString().trim());
- this.logLevel = ConfigurationUtil.getProperty(config, PROP_LOG_LEVEL,
DEFAULT_LOG_LEVEL);
- AbstractOsgiManagerPlugin.LOGLEVEL = logLevel;
-
org.apache.felix.webconsole.AbstractWebConsolePlugin.setLogLevel(logLevel);
- AbstractPluginAdapter.setLogLevel(logLevel);
-
// default plugin page configuration
holder.setDefaultPluginLabel(ConfigurationUtil.getProperty(config,
PROP_DEFAULT_RENDER, DEFAULT_PAGE));
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
index f6779bc543..fe12e62a74 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/servlet/PluginHolder.java
@@ -39,7 +39,6 @@ import org.osgi.framework.Constants;
import org.osgi.framework.Filter;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
-import org.osgi.service.log.LogService;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -135,10 +134,10 @@ public class PluginHolder implements
ServiceTrackerCustomizer<Servlet, Plugin> {
this.servletTracker.open();
try {
this.legacyTracker = new LegacyServicesTracker(this,
this.getBundleContext());
- this.osgiManager.log(LogService.LOG_INFO, "Servlet 3 bridge
enabled");
+ Util.LOGGER.info("Servlet 3 bridge enabled");
} catch ( final Throwable t) {
// ignore
- this.osgiManager.log(LogService.LOG_INFO, "Servlet 3 bridge not
enabled");
+ Util.LOGGER.info("Servlet 3 bridge not enabled");
}
}
@@ -382,15 +381,14 @@ public class PluginHolder implements
ServiceTrackerCustomizer<Servlet, Plugin> {
if (!first.init()) {
list.remove(plugin);
} else if (oldPlugin != null) {
- osgiManager.log(LogService.LOG_WARNING, "Overwriting
existing plugin " + oldPlugin.getId()
- + " having label " + plugin.getLabel() + " with
new plugin " + plugin.getId()
- + " due to higher ranking " );
+ Util.LOGGER.warn("Overwriting existing plugin {} having
label {} with new plugin {} due to higher ranking ",
+ oldPlugin.getId(), plugin.getLabel(), plugin.getId() );
oldPlugin.dispose();
}
}
if (first == oldPlugin) {
- osgiManager.log(LogService.LOG_WARNING, "Ignoring new plugin "
+ plugin.getId()
- + " having existing label " + plugin.getLabel() + "
due to lower ranking than old plugin " + oldPlugin.getId() );
+ Util.LOGGER.warn("Ignoring new plugin {} having existing label
{} due to lower ranking than old plugin {}",
+ plugin.getId(), plugin.getLabel(), oldPlugin.getId() );
}
}
}
diff --git
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
index d49d36ab84..16a2c9af56 100644
---
a/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
+++
b/webconsole/src/main/java/org/apache/felix/webconsole/internal/system/VMStatPlugin.java
@@ -27,6 +27,7 @@ import java.util.Map;
import org.apache.felix.utils.json.JSONWriter;
+import org.apache.felix.webconsole.internal.Util;
import org.apache.felix.webconsole.internal.servlet.AbstractOsgiManagerPlugin;
import org.apache.felix.webconsole.internal.servlet.OsgiManager;
import org.apache.felix.webconsole.servlet.RequestVariableResolver;
@@ -127,7 +128,7 @@ public class VMStatPlugin extends AbstractOsgiManagerPlugin
{
// ignore
}
- log( "Shutting down server now!" );
+ Util.LOGGER.info( "Shutting down server now!" );
// stopping bundle 0 (system bundle) stops the framework
try {
@@ -137,7 +138,7 @@ public class VMStatPlugin extends AbstractOsgiManagerPlugin
{
systemBundle.stop();
}
} catch ( BundleException be ) {
- log( "Problem stopping or restarting the Framework",
be );
+ Util.LOGGER.error( "Problem stopping or restarting the
Framework", be );
}
}
};