Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaymond Auge2019-02-11 22:52:59 +0000
committerRaymond Auge2019-02-12 19:35:05 +0000
commit13f073a0f979c092f3b36c6487b3ce8435df8555 (patch)
treeb304989267947790abff92ce68c60e58eaf0599a
parent34f0eccb057de7717cbbd29a48253808d099a7bf (diff)
downloadrt.equinox.bundles-13f073a0f979c092f3b36c6487b3ce8435df8555.tar.gz
rt.equinox.bundles-13f073a0f979c092f3b36c6487b3ce8435df8555.tar.xz
rt.equinox.bundles-13f073a0f979c092f3b36c6487b3ce8435df8555.zip
Bug 544356 - [http whiteboard] use OSGi logging for validation instead of servletcontext
Signed-off-by: Raymond Auge <raymond.auge@liferay.com> Change-Id: Ie3563ecb3c28b1bf6fe95fd57d2b6d485420c4d3
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF1
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java57
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/PreprocessorCustomizer.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextErrorPageTrackerCustomizer.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java6
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/HttpWhiteboardFailureException.java4
-rw-r--r--bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionTracker.java6
10 files changed, 70 insertions, 26 deletions
diff --git a/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
index 38e4f6edc..1c894a968 100644
--- a/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.http.servlet/META-INF/MANIFEST.MF
@@ -27,6 +27,7 @@ Import-Package: org.apache.commons.fileupload;version="[1.2.2, 2.0.0)";resolutio
org.osgi.service.http.runtime;version="[1.1,1.2)",
org.osgi.service.http.runtime.dto;version="[1.1,1.2)",
org.osgi.service.http.whiteboard;version="[1.1,1.2)",
+ org.osgi.service.log;version="[1.4,2)",
org.osgi.util.tracker;version="[1.5,2.0)"
Comment-Header: Both Eclipse-LazyStart and Bundle-ActivationPolicy are specified for compatibility with 3.2
Eclipse-LazyStart: true
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
index cc3fcae95..f2e3f2b91 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/HttpServiceRuntimeImpl.java
@@ -44,6 +44,8 @@ import org.osgi.service.http.context.ServletContextHelper;
import org.osgi.service.http.runtime.HttpServiceRuntime;
import org.osgi.service.http.runtime.dto.*;
import org.osgi.service.http.whiteboard.Preprocessor;
+import org.osgi.service.log.Logger;
+import org.osgi.service.log.LoggerFactory;
import org.osgi.util.tracker.ServiceTracker;
import org.osgi.util.tracker.ServiceTrackerCustomizer;
@@ -75,6 +77,22 @@ public class HttpServiceRuntimeImpl
this.httpSessionTracker = new HttpSessionTracker(this);
this.invalidatorReg = trackingContext.registerService(HttpSessionInvalidator.class, this.httpSessionTracker, attributes);
+ loggerFactoryTracker = new ServiceTracker<>(consumingContext, LoggerFactory.class, new ServiceTrackerCustomizer<LoggerFactory, Logger>() {
+ @Override
+ public Logger addingService(ServiceReference<LoggerFactory> reference) {
+ return getConsumingContext().getService(reference).getLogger(HttpServiceRuntimeImpl.class);
+ }
+ @Override
+ public void modifiedService(ServiceReference<LoggerFactory> reference, Logger service) {
+ // ignore
+ }
+ @Override
+ public void removedService(ServiceReference<LoggerFactory> reference, Logger service) {
+ // ignore
+ }
+ });
+ loggerFactoryTracker.open();
+
contextServiceTracker =
new ServiceTracker<ServletContextHelper, AtomicReference<ContextController>>(
trackingContext, ServletContextHelper.class, this);
@@ -121,12 +139,12 @@ public class HttpServiceRuntimeImpl
result.set(contextController);
}
catch (HttpWhiteboardFailureException hwfe) {
- parentServletContext.log(hwfe.getMessage(), hwfe);
+ debug(hwfe.getMessage(), hwfe);
recordFailedServletContextDTO(serviceReference, 0, hwfe.getFailureReason());
}
- catch (Exception e) {
- parentServletContext.log(e.getMessage(), e);
+ catch (Throwable t) {
+ error(t.getMessage(), t);
recordFailedServletContextDTO(serviceReference, 0, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
@@ -233,6 +251,7 @@ public class HttpServiceRuntimeImpl
httpSessionTracker.clear();
registeredObjects.clear();
scheduledExecutor.shutdown();
+ loggerFactoryTracker.close();
}
public DispatchTargets getDispatchTargets(
@@ -344,12 +363,34 @@ public class HttpServiceRuntimeImpl
return null;
}
- public void log(String message) {
- parentServletContext.log(message);
+ public void debug(String message) {
+ Logger logger = loggerFactoryTracker.getService();
+ if (logger == null) {
+ parentServletContext.log(String.valueOf(message));
+ }
+ else {
+ logger.debug(String.valueOf(message));
+ }
+ }
+
+ public void debug(String message, Throwable t) {
+ Logger logger = loggerFactoryTracker.getService();
+ if (logger == null) {
+ parentServletContext.log(String.valueOf(message), t);
+ }
+ else {
+ logger.debug(String.valueOf(message), t);
+ }
}
- public void log(String message, Throwable t) {
- parentServletContext.log(message, t);
+ public void error(String message, Throwable t) {
+ Logger logger = loggerFactoryTracker.getService();
+ if (logger == null) {
+ parentServletContext.log(String.valueOf(message), t);
+ }
+ else {
+ logger.error(String.valueOf(message), t);
+ }
}
public boolean matches(ServiceReference<?> serviceReference) {
@@ -1281,7 +1322,7 @@ public class HttpServiceRuntimeImpl
new ConcurrentHashMap<ServiceReference<?>, FailedPreprocessorDTO>();
private final Set<Object> registeredObjects = Collections.newSetFromMap(new ConcurrentHashMap<Object, Boolean>());
-
+ private final ServiceTracker<LoggerFactory, Logger> loggerFactoryTracker;
private final ServiceTracker<ServletContextHelper, AtomicReference<ContextController>> contextServiceTracker;
private final ServiceTracker<Preprocessor, AtomicReference<PreprocessorRegistration>> preprocessorServiceTracker;
private final ServiceTracker<ContextPathCustomizer, ContextPathCustomizer> contextPathAdaptorTracker;
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/PreprocessorCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/PreprocessorCustomizer.java
index 20730e6a7..d23c4b96c 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/PreprocessorCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/PreprocessorCustomizer.java
@@ -56,12 +56,12 @@ public class PreprocessorCustomizer
result.set(addPreprocessorRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
catch (Exception e) {
- httpServiceRuntime.log(e.getMessage(), e);
+ httpServiceRuntime.error(e.getMessage(), e);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextErrorPageTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextErrorPageTrackerCustomizer.java
index b87ef5f9e..7b51e9da8 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextErrorPageTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextErrorPageTrackerCustomizer.java
@@ -82,12 +82,12 @@ public class ContextErrorPageTrackerCustomizer
result.set(contextController.addErrorPageRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
catch (Throwable t) {
- httpServiceRuntime.log(t.getMessage(), t);
+ httpServiceRuntime.error(t.getMessage(), t);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java
index 3ab68807b..8e003c764 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextFilterTrackerCustomizer.java
@@ -68,12 +68,12 @@ public class ContextFilterTrackerCustomizer
result.set(contextController.addFilterRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
- catch (Exception e) {
- httpServiceRuntime.log(e.getMessage(), e);
+ catch (Throwable t) {
+ httpServiceRuntime.error(t.getMessage(), t);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
index 8edc635be..10ddadb9b 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextListenerTrackerCustomizer.java
@@ -80,12 +80,12 @@ public class ContextListenerTrackerCustomizer
result.set(contextController.addListenerRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
- catch (Exception e) {
- httpServiceRuntime.log(e.getMessage(), e);
+ catch (Throwable t) {
+ httpServiceRuntime.error(t.getMessage(), t);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java
index b146baa25..a18a66107 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextResourceTrackerCustomizer.java
@@ -80,12 +80,12 @@ public class ContextResourceTrackerCustomizer
result.set(contextController.addResourceRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
catch (Throwable t) {
- httpServiceRuntime.log(t.getMessage(), t);
+ httpServiceRuntime.error(t.getMessage(), t);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java
index e6e862e16..7fdf292fd 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/customizer/ContextServletTrackerCustomizer.java
@@ -81,12 +81,12 @@ public class ContextServletTrackerCustomizer
result.set(contextController.addServletRegistration(serviceReference));
}
catch (HttpWhiteboardFailureException hwfe) {
- httpServiceRuntime.log(hwfe.getMessage(), hwfe);
+ httpServiceRuntime.debug(hwfe.getMessage(), hwfe);
recordFailed(serviceReference, hwfe.getFailureReason());
}
catch (Throwable t) {
- httpServiceRuntime.log(t.getMessage(), t);
+ httpServiceRuntime.error(t.getMessage(), t);
recordFailed(serviceReference, DTOConstants.FAILURE_REASON_EXCEPTION_ON_INIT);
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/HttpWhiteboardFailureException.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/HttpWhiteboardFailureException.java
index 9cfebdb60..95a0ce9ab 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/HttpWhiteboardFailureException.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/error/HttpWhiteboardFailureException.java
@@ -14,6 +14,8 @@
package org.eclipse.equinox.http.servlet.internal.error;
+import java.util.Objects;
+
/**
* @author Raymond Augé
*/
@@ -22,7 +24,7 @@ public class HttpWhiteboardFailureException extends IllegalArgumentException {
private static final long serialVersionUID = 1944632136470074075L;
public HttpWhiteboardFailureException(String message, int failureReason) {
- super(message);
+ super(Objects.requireNonNull(message));
this.failureReason = failureReason;
}
diff --git a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionTracker.java b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionTracker.java
index 2e1ef9e9b..2dd3df725 100644
--- a/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionTracker.java
+++ b/bundles/org.eclipse.equinox.http.servlet/src/org/eclipse/equinox/http/servlet/internal/servlet/HttpSessionTracker.java
@@ -54,8 +54,8 @@ public class HttpSessionTracker implements HttpSessionInvalidator {
parentSession.invalidate();
}
catch (IllegalStateException ise) {
- httpServiceRuntime.log(
- "Session was already invalidated!", ise); //$NON-NLS-1$
+ httpServiceRuntime.debug(
+ "Session was already invalidated: " + parentSession.getId(), ise); //$NON-NLS-1$
}
}
}
@@ -86,7 +86,7 @@ public class HttpSessionTracker implements HttpSessionInvalidator {
// At this point there should be no left over sessions. If
// there are we'll log it because there's some kind of leak.
if (!httpSessionAdaptorsMap.isEmpty()) {
- httpServiceRuntime.log(
+ httpServiceRuntime.debug(
"There are HttpSessionAdaptors left over. There might be a context or session leak!"); //$NON-NLS-1$
}
}

Back to the top