From 3f80840e1a242c163d970592fc5669f2a82f6056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BB=D0=B5=D0=BA=D1=81=D0=B0=D0=BD=D0=B4=D1=8A?= =?UTF-8?q?=D1=80=20=D0=9A=D1=83=D1=80=D1=82=D0=B0=D0=BA=D0=BE=D0=B2?= Date: Fri, 29 Sep 2023 14:46:27 +0300 Subject: [PATCH] Port o.e.equinox.http.jetty to Jetty 12 Port is straightforward except for logging as EquinoxStdErrLog had to be removed as this org.eclipse.jetty.util.log api is totally gone and has been deprecated since Jetty 10.x. According to https://eclipse.dev/jetty/documentation/jetty-12/operations-guide/index.html#og-server-logging there is no longer programatic way to configure logging. --- .../META-INF/MANIFEST.MF | 20 +- .../http/jetty/internal/Activator.java | 12 +- .../http/jetty/internal/EquinoxStdErrLog.java | 201 ------------------ .../jetty/internal/HttpServerManager.java | 22 +- 4 files changed, 33 insertions(+), 222 deletions(-) delete mode 100644 bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/EquinoxStdErrLog.java diff --git a/bundles/org.eclipse.equinox.http.jetty/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.http.jetty/META-INF/MANIFEST.MF index 5aa53afd3b6..caed00e9e15 100644 --- a/bundles/org.eclipse.equinox.http.jetty/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.equinox.http.jetty/META-INF/MANIFEST.MF @@ -9,16 +9,16 @@ Bundle-Activator: org.eclipse.equinox.http.jetty.internal.Activator Import-Package: javax.servlet;version="[3.1.0,5.0.0)", javax.servlet.http;version="[3.1.0,5.0.0)", org.eclipse.equinox.http.servlet;version="[1.2.0,2.0.0)", - org.eclipse.jetty.http;version="[10.0.2,11.0.0)", - org.eclipse.jetty.server;version="[10.0.2,11.0.0)", - org.eclipse.jetty.server.handler;version="[10.0.2,11.0.0)", - org.eclipse.jetty.server.session;version="[10.0.2,11.0.0)", - org.eclipse.jetty.servlet;version="[10.0.2,11.0.0)", - org.eclipse.jetty.util;version="[10.0.2,11.0.0)", - org.eclipse.jetty.util.component;version="[10.0.2,11.0.0)", - org.eclipse.jetty.util.log;version="[10.0.2,11.0.0)", - org.eclipse.jetty.util.ssl;version="[10.0.2,11.0.0)", - org.eclipse.jetty.util.thread;version="[10.0.2,11.0.0)", + org.eclipse.jetty.http;version="[12.0.1,13.0.0)", + org.eclipse.jetty.server;version="[12.0.1,13.0.0)", + org.eclipse.jetty.server.handler;version="[12.0.1,13.0.0)", + org.eclipse.jetty.session;version="[12.0.1,13.0.0)", + org.eclipse.jetty.ee8.servlet;version="[12.0.1,13.0.0)", + org.eclipse.jetty.ee8.nested;version="[12.0.1,13.0.0)", + org.eclipse.jetty.util;version="[12.0.1,13.0.0)", + org.eclipse.jetty.util.component;version="[12.0.1,13.0.0)", + org.eclipse.jetty.util.ssl;version="[12.0.1,13.0.0)", + org.eclipse.jetty.util.thread;version="[12.0.1,13.0.0)", org.osgi.framework;version="1.3.0", org.osgi.framework.startlevel;version="1.0.0", org.osgi.framework.wiring;version="1.2.0", diff --git a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/Activator.java b/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/Activator.java index 4089cb6e6d8..66324e97d5d 100644 --- a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/Activator.java +++ b/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/Activator.java @@ -17,9 +17,15 @@ package org.eclipse.equinox.http.jetty.internal; import java.io.File; -import java.util.*; +import java.util.Dictionary; +import java.util.Hashtable; +import java.util.List; + import org.eclipse.equinox.http.jetty.JettyConstants; -import org.osgi.framework.*; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.Constants; +import org.osgi.framework.ServiceRegistration; import org.osgi.framework.startlevel.BundleStartLevel; import org.osgi.framework.wiring.BundleCapability; import org.osgi.framework.wiring.BundleRevision; @@ -48,7 +54,6 @@ public class Activator implements BundleActivator { // Valid values are in increasing threshold: "debug", "info", "warn", "error", // and "off" // (default threshold is "warn") - private static final String LOG_STDERR_THRESHOLD = "org.eclipse.equinox.http.jetty.log.stderr.threshold"; //$NON-NLS-1$ // The staticServerManager is use by the start and stopServer methods and must // be accessed in a static synchronized block @@ -62,7 +67,6 @@ public class Activator implements BundleActivator { public void start(BundleContext context) throws Exception { File jettyWorkDir = new File(context.getDataFile(""), JETTY_WORK_DIR); //$NON-NLS-1$ jettyWorkDir.mkdir(); - EquinoxStdErrLog.setThresholdLogger(context.getProperty(LOG_STDERR_THRESHOLD)); httpServerManager = new HttpServerManager(jettyWorkDir); boolean autostart = Details.getBoolean(context, AUTOSTART, false); diff --git a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/EquinoxStdErrLog.java b/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/EquinoxStdErrLog.java deleted file mode 100644 index c49bbe59e5a..00000000000 --- a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/EquinoxStdErrLog.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2011, 2017 IBM Corporation and others - * - * This program and the accompanying materials - * are made available under the terms of the Eclipse Public License 2.0 - * which accompanies this distribution, and is available at - * https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.equinox.http.jetty.internal; - -import org.eclipse.jetty.util.log.Log; -import org.eclipse.jetty.util.log.Logger; - -// NOTE: This class simply allows us to override the StdErrLog built into jetty -public class EquinoxStdErrLog implements Logger { - - private static int DEBUG = 0; - private static int INFO = 1; - private static int WARN = 2; - private static int ERROR = 3; - private static int OFF = 4; - - private static volatile int threshold = WARN; - private static EquinoxStdErrLog root; - - private final Logger realLogger; - private final String localName; - - public static synchronized EquinoxStdErrLog getRootLogger() { - if (root != null) - return root; - - root = new EquinoxStdErrLog(null, null); - return root; - } - - public static void setThresholdLogger(String property) { - threshold = parseThresholdProperty(property); - // this is a hack to make sure the built-in jetty StdErrLog is not being used - org.eclipse.jetty.util.log.Logger rootLogger = Log.getRootLogger(); - if (rootLogger == null || (rootLogger instanceof Log)) { - // The built-in jetty StdErrLog is be used; replace with ours. - Log.setLog(getRootLogger()); - } - - } - - private static int parseThresholdProperty(String property) { - if (property == null) - return WARN; - - if (property.equals("debug")) //$NON-NLS-1$ - return DEBUG; - - if (property.equals("info")) //$NON-NLS-1$ - return INFO; - - if (property.equals("warn")) //$NON-NLS-1$ - return WARN; - - if (property.equals("error")) //$NON-NLS-1$ - return ERROR; - - if (property.equals("none")) //$NON-NLS-1$ - return OFF; - - return WARN; - } - - public EquinoxStdErrLog(String name, Logger realLogger) { - this.localName = name; - this.realLogger = realLogger; - if (threshold == DEBUG) - this.realLogger.setDebugEnabled(true); - } - - @Override - public org.eclipse.jetty.util.log.Logger getLogger(String name) { - if ((name == null && this.localName == null) || (name != null && name.equals(this.localName))) - return this; - return new EquinoxStdErrLog(name, realLogger.getLogger(name)); - } - - // debugSOO = slf4j.getMethod("debug", new Class[]{String.class,Object.class,Object.class}); - @Override - public void debug(String msg, Object... arg0) { - if (threshold > DEBUG) - return; - - realLogger.debug(msg, arg0); - } - - // debugST = slf4j.getMethod("debug", new Class[]{String.class,Throwable.class}); - @Override - public void debug(String msg, Throwable th) { - if (threshold > DEBUG) - return; - - realLogger.debug(msg, th); - } - - // infoSOO = slf4j.getMethod("info", new Class[]{String.class,Object.class,Object.class}); - @Override - public void info(String msg, Object... arg0) { - if (threshold > INFO) - return; - - realLogger.info(msg, arg0); - } - - // warnSOO = slf4j.getMethod("warn", new Class[]{String.class,Object.class,Object.class}); - @Override - public void warn(String msg, Object... arg0) { - if (threshold > WARN) - return; - - realLogger.warn(msg, arg0); - } - - // warnST = slf4j.getMethod("warn", new Class[]{String.class,Throwable.class}); - @Override - public void warn(String msg, Throwable th) { - if (threshold > WARN) - return; - - // we treat RuntimeException and Error as an error - if (th instanceof RuntimeException || th instanceof Error) - realLogger.warn("ERROR: " + msg, th); //$NON-NLS-1$ - else if (threshold != ERROR) - realLogger.warn(msg, th); - } - - // errorST = slf4j.getMethod("error", new Class[]{String.class,Throwable.class}); - public void error(String msg, Throwable th) { - if (threshold > ERROR) - return; - - realLogger.warn("ERROR: " + msg, th); //$NON-NLS-1$ - } - - @Override - public String getName() { - return realLogger.getName(); - } - - @Override - public void warn(Throwable thrown) { - if (threshold > WARN) - return; - realLogger.warn(thrown); - } - - @Override - public void info(Throwable thrown) { - if (threshold > INFO) - return; - realLogger.info(thrown); - } - - @Override - public void info(String msg, Throwable thrown) { - if (threshold > INFO) - return; - realLogger.info(msg, thrown); - } - - @Override - public boolean isDebugEnabled() { - return threshold == DEBUG; - } - - @Override - public void setDebugEnabled(boolean enabled) { - threshold = DEBUG; - } - - @Override - public void debug(Throwable thrown) { - if (threshold > DEBUG) - return; - realLogger.debug(thrown); - } - - @Override - public void ignore(Throwable ignored) { - // Just post this to debug - debug(ignored); - } - - @Override - public void debug(String msg, long value) { - if (threshold > DEBUG) - return; - realLogger.debug(msg, value); - } -} diff --git a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/HttpServerManager.java b/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/HttpServerManager.java index fae1972de39..666e4ad050f 100644 --- a/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/HttpServerManager.java +++ b/bundles/org.eclipse.equinox.http.jetty/src/org/eclipse/equinox/http/jetty/internal/HttpServerManager.java @@ -37,6 +37,9 @@ import org.eclipse.equinox.http.jetty.JettyConstants; import org.eclipse.equinox.http.jetty.JettyCustomizer; import org.eclipse.equinox.http.servlet.HttpServiceServlet; +import org.eclipse.jetty.ee8.nested.SessionHandler; +import org.eclipse.jetty.ee8.servlet.ServletContextHandler; +import org.eclipse.jetty.ee8.servlet.ServletHolder; import org.eclipse.jetty.http.UriCompliance; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -44,10 +47,8 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.SslConnectionFactory; -import org.eclipse.jetty.server.session.HouseKeeper; -import org.eclipse.jetty.server.session.SessionHandler; -import org.eclipse.jetty.servlet.ServletContextHandler; -import org.eclipse.jetty.servlet.ServletHolder; +import org.eclipse.jetty.session.DefaultSessionIdManager; +import org.eclipse.jetty.session.HouseKeeper; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.osgi.framework.Constants; @@ -169,12 +170,19 @@ public synchronized void updated(String pid, Dictionary dictionary) t httpContext = (ServletContextHandler) customizer.customizeContext(httpContext, dictionary); try { + DefaultSessionIdManager idMgr = new DefaultSessionIdManager(server); + server.addBean(idMgr, true); + + HouseKeeper houseKeeper = new HouseKeeper(); + houseKeeper.setSessionIdManager(idMgr); + // set the frequency of scavenge cycles + houseKeeper.setIntervalSec( + Details.getLong(dictionary, JettyConstants.HOUSEKEEPER_INTERVAL, houseKeeper.getIntervalSec())); + idMgr.setSessionHouseKeeper(houseKeeper); server.start(); SessionHandler sessionManager = httpContext.getSessionHandler(); sessionManager.addEventListener((HttpSessionIdListener) holder.getServlet()); - HouseKeeper houseKeeper = server.getSessionIdManager().getSessionHouseKeeper(); - houseKeeper.setIntervalSec( - Details.getLong(dictionary, JettyConstants.HOUSEKEEPER_INTERVAL, houseKeeper.getIntervalSec())); + } catch (Exception e) { throw new ConfigurationException(pid, e.getMessage(), e); }