Issue #6354 - OSGI manifest for slf4j-api packages lower limit should be 1.7 (#6381)

Issue #6354 - OSGI manifest for slf4j-api packages lower limit should be 1.7

* Fixed OSGi manifest in all jars.
* Make osgi tests work with slf4j < 2.0.0. 
This required to remove the dependency on SLF4J from the demos.

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
Co-authored-by: Jan Bartel <janb@webtide.com>
This commit is contained in:
Joakim Erdfelt 2021-06-10 09:04:50 -05:00 committed by GitHub
parent 33c1b14ada
commit d997a1171b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 108 additions and 81 deletions

View File

@ -126,15 +126,6 @@
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>

View File

@ -27,17 +27,12 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Simple asynchronous Chat room.
// This does not handle duplicate usernames or multiple frames/tabs from the same browser
// Some code is duplicated for clarity.
@SuppressWarnings("serial")
public class ChatServlet extends HttpServlet
{
private static final Logger LOG = LoggerFactory.getLogger(ChatServlet.class);
private long asyncTimeout = 10000;
@Override
@ -63,7 +58,7 @@ public class ChatServlet extends HttpServlet
@Override
public void onTimeout(AsyncEvent event) throws IOException
{
LOG.debug("resume request");
getServletContext().log("resume request");
AsyncContext async = _async.get();
if (async != null && _async.compareAndSet(async, null))
{
@ -102,10 +97,10 @@ public class ChatServlet extends HttpServlet
String message = request.getParameter("message");
String username = request.getParameter("user");
LOG.debug("doPost called. join={},message={},username={}", join, message, username);
getServletContext().log("doPost called. join=" + join + " message=" + message + " username=" + username);
if (username == null)
{
LOG.debug("no parameter user set, sending 503");
getServletContext().log("no parameter user set, sending 503");
response.sendError(503, "user==null");
return;
}
@ -125,14 +120,14 @@ public class ChatServlet extends HttpServlet
{
synchronized (member)
{
LOG.debug("Queue size: {}", member._queue.size());
getServletContext().log("Queue size: " + member._queue.size());
if (!member._queue.isEmpty())
{
sendSingleMessage(response, member);
}
else
{
LOG.debug("starting async");
getServletContext().log("starting async");
AsyncContext async = request.startAsync();
async.setTimeout(asyncTimeout);
async.addListener(member);
@ -147,7 +142,7 @@ public class ChatServlet extends HttpServlet
Member member = room.get(username);
if (member == null)
{
LOG.debug("user: {} in room: {} doesn't exist. Creating new user.", username, room);
getServletContext().log("user: " + username + " in room: " + room + " doesn't exist. Creating new user.");
member = new Member(username);
room.put(username, member);
}
@ -159,7 +154,7 @@ public class ChatServlet extends HttpServlet
Map<String, Member> room = _rooms.get(path);
if (room == null)
{
LOG.debug("room: {} doesn't exist. Creating new room.", path);
getServletContext().log("room: " + path + " doesn't exist. Creating new room.");
room = new HashMap<>();
_rooms.put(path, room);
}
@ -192,7 +187,6 @@ public class ChatServlet extends HttpServlet
private void sendMessageToAllMembers(String message, String username, Map<String, Member> room)
{
LOG.debug("Sending message: {} from: {}", message, username);
for (Member m : room.values())
{
synchronized (m)
@ -202,10 +196,8 @@ public class ChatServlet extends HttpServlet
// wakeup member if polling
AsyncContext async = m._async.get();
LOG.debug("Async found: {}", async);
if (async != null & m._async.compareAndSet(async, null))
{
LOG.debug("dispatch");
async.dispatch();
}
}

View File

@ -51,8 +51,6 @@ import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;
import javax.servlet.http.Part;
import org.slf4j.LoggerFactory;
/**
* Dump Servlet Request.
*/
@ -116,7 +114,7 @@ public class Dump extends HttpServlet
}
catch (ServletException e)
{
getServletContext().log(e.toString());
getServletContext().log("Login fail", e);
}
}
@ -341,12 +339,12 @@ public class Dump extends HttpServlet
}
catch (IOException e2)
{
LoggerFactory.getLogger(Dump.class).trace("IGNORED", e2);
getServletContext().log("Write fail", e2);
}
}
catch (IOException e)
{
LoggerFactory.getLogger(Dump.class).trace("IGNORED", e);
getServletContext().log("Output fail", e);
}
return;
}

View File

@ -27,17 +27,12 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Dump Servlet Request.
*/
@SuppressWarnings("serial")
public class SecureModeServlet extends HttpServlet
{
private static final Logger LOG = LoggerFactory.getLogger(SecureModeServlet.class);
@Override
public void init(ServletConfig config) throws ServletException
{
@ -116,7 +111,7 @@ public class SecureModeServlet extends HttpServlet
try
{
out.println("check ability to log<br/>");
LOG.info("testing logging");
getServletContext().log("testing logging");
out.println("status: <b>SUCCESS - expected</b><br/>");
}
catch (SecurityException e)

View File

@ -27,9 +27,6 @@ import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* TestFilter.
*
@ -39,8 +36,6 @@ import org.slf4j.LoggerFactory;
*/
public class TestFilter implements Filter
{
private static final Logger LOG = LoggerFactory.getLogger(TestFilter.class);
private boolean _remote;
private ServletContext _context;
private final Set<String> _allowed = new HashSet<String>();
@ -54,7 +49,7 @@ public class TestFilter implements Filter
_allowed.add("/jetty_banner.gif");
_allowed.add("/remote.html");
LOG.debug("TestFilter#remote=" + _remote);
filterConfig.getServletContext().log("TestFilter#remote=" + _remote);
}
@Override

View File

@ -24,7 +24,7 @@
</goals>
<configuration>
<instructions>
<Import-Package>org.eclipse.jetty.alpn;resolution:=optional,*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},org.eclipse.jetty.alpn;resolution:=optional,*</Import-Package>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional, osgi.serviceloader; filter:="(osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Client)";resolution:=optional;cardinality:=multiple</Require-Capability>
</instructions>
</configuration>

View File

@ -52,7 +52,7 @@
<configuration>
<instructions>
<Bundle-Description>Conscrypt Client ALPN</Bundle-Description>
<Import-Package>org.conscrypt;version="${conscrypt.version}",*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},org.conscrypt;version="${conscrypt.version}",*</Import-Package>
<Export-Package>*</Export-Package>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability>
<Provide-Capability>osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Client</Provide-Capability>

View File

@ -80,7 +80,7 @@
<configuration>
<instructions>
<Bundle-Description>Conscrypt ALPN</Bundle-Description>
<Import-Package>org.conscrypt;version="${conscrypt.version}",*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},org.conscrypt;version="${conscrypt.version}",*</Import-Package>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability>
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Server</Provide-Capability>
<_nouses>true</_nouses>

View File

@ -30,7 +30,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>org.objectweb.asm;version="5",*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},org.objectweb.asm;version="5",*</Import-Package>
<Require-Capability>osgi.serviceloader; filter:="(osgi.serviceloader=javax.servlet.ServletContainerInitializer)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional
</Require-Capability>
</instructions>

View File

@ -31,7 +31,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>javax.mail.*;resolution:=optional,*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},javax.mail.*;resolution:=optional,*</Import-Package>
</instructions>
</configuration>
</plugin>

View File

@ -71,30 +71,29 @@
<Bundle-SymbolicName>org.eclipse.jetty.osgi.boot;singleton:=true</Bundle-SymbolicName>
<Bundle-Activator>org.eclipse.jetty.osgi.boot.JettyBootstrapActivator</Bundle-Activator>
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
<Import-Package>javax.mail;version="1.4.0";resolution:=optional,
javax.mail.event;version="1.4.0";resolution:=optional,
javax.mail.internet;version="1.4.0";resolution:=optional,
javax.mail.search;version="1.4.0";resolution:=optional,
javax.mail.util;version="1.4.0";resolution:=optional,
javax.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
javax.servlet.http;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
javax.transaction;version="1.1.0";resolution:=optional,
javax.transaction.xa;version="1.1.0";resolution:=optional,
org.objectweb.asm;version="$(version;=;${asm.version})";resolution:=optional,
org.osgi.framework,
org.osgi.service.cm;version="1.4.0",
org.osgi.service.event;version="1.4.0",
org.osgi.service.packageadmin,
org.osgi.service.startlevel;version="1.0.0",
org.osgi.service.url;version="1.0.0",
org.osgi.util.tracker;version="1.3.0",
org.slf4j;resolution:=optional,
org.slf4j.spi;resolution:=optional,
org.slf4j.helpers;resolution:=optional,
org.xml.sax,
org.xml.sax.helpers,
org.eclipse.jetty.annotations;resolution:=optional,
*
<Import-Package>
${osgi.slf4j.import.packages},
javax.mail;version="1.4.0";resolution:=optional,
javax.mail.event;version="1.4.0";resolution:=optional,
javax.mail.internet;version="1.4.0";resolution:=optional,
javax.mail.search;version="1.4.0";resolution:=optional,
javax.mail.util;version="1.4.0";resolution:=optional,
javax.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
javax.servlet.http;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
javax.transaction;version="1.1.0";resolution:=optional,
javax.transaction.xa;version="1.1.0";resolution:=optional,
org.objectweb.asm;version="$(version;=;${asm.version})";resolution:=optional,
org.osgi.framework,
org.osgi.service.cm;version="1.4.0",
org.osgi.service.event;version="1.4.0",
org.osgi.service.packageadmin,
org.osgi.service.startlevel;version="1.0.0",
org.osgi.service.url;version="1.0.0",
org.osgi.util.tracker;version="1.3.0",
org.xml.sax,
org.xml.sax.helpers,
org.eclipse.jetty.annotations;resolution:=optional,
*
</Import-Package>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"

View File

@ -74,7 +74,18 @@
compilation time. -->
<_nouses>true</_nouses>
<Import-Package>
javax.servlet;version="[3.1,4.1)", javax.servlet.resources;version="[3.1,4.1)", org.osgi.framework, org.osgi.service.cm;version="1.2.0", org.osgi.service.packageadmin, org.osgi.service.startlevel;version="1.0.0", org.osgi.service.url;version="1.0.0", org.osgi.util.tracker;version="1.3.0", org.slf4j;resolution:=optional, org.slf4j.spi;resolution:=optional, org.slf4j.helpers;resolution:=optional, org.xml.sax, org.xml.sax.helpers, *
${osgi.slf4j.import.packages},
javax.servlet;version="[3.1,4.1)",
javax.servlet.resources;version="[3.1,4.1)",
org.osgi.framework,
org.osgi.service.cm;version="1.2.0",
org.osgi.service.packageadmin,
org.osgi.service.startlevel;version="1.0.0",
org.osgi.service.url;version="1.0.0",
org.osgi.util.tracker;version="1.3.0",
org.xml.sax,
org.xml.sax.helpers,
*
</Import-Package>
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;==;${parsedVersion.osgiVersion}),$(version;+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
</instructions>

View File

@ -66,7 +66,18 @@
compilation time. -->
<_nouses>true</_nouses>
<Import-Package>
javax.servlet;version="[3.1,4.1)", javax.servlet.resources;version="[3.1,4.1)", org.osgi.framework, org.osgi.service.cm;version="1.2.0", org.osgi.service.packageadmin, org.osgi.service.startlevel;version="1.0.o", org.osgi.service.url;version="1.0.0", org.osgi.util.tracker;version="1.3.0", org.slf4j;resolution:=optional, org.slf4j.spi;resolution:=optional, org.slf4j.helpers;resolution:=optional, org.xml.sax, org.xml.sax.helpers, *
${osgi.slf4j.import.packages},
javax.servlet;version="[3.1,4.1)",
javax.servlet.resources;version="[3.1,4.1)",
org.osgi.framework,
org.osgi.service.cm;version="1.2.0",
org.osgi.service.packageadmin,
org.osgi.service.startlevel;version="1.0.0",
org.osgi.service.url;version="1.0.0",
org.osgi.util.tracker;version="1.3.0",
org.xml.sax,
org.xml.sax.helpers,
*
</Import-Package>
<DynamicImport-Package>org.eclipse.jetty.*;version="[$(version;==;${parsedVersion.osgiVersion}),$(version;+;${parsedVersion.osgiVersion}))"</DynamicImport-Package>
</instructions>

View File

@ -135,6 +135,18 @@
</dependency>
<!-- Jetty OSGi Deps -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.30</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>

View File

@ -142,13 +142,36 @@ public class TestOSGiUtil
res.add(systemProperty("org.ops4j.pax.url.mvn.settings").value(System.getProperty("settingsFilePath")));
}
//make src/test/resources/jetty-logging.properties visible to jetty in the osgi container
/*
* Jetty 10 uses slf4j 2.0.0 by default, however we want to test with slf4j 1.7.30 for backwards compatibility.
* To do that, we need to use slf4j-simple as the logging implementation. We make a simplelogger.properties
* file available so that jetty logging can be configured
*/
res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject().noStart());
TinyBundle simpleLoggingPropertiesBundle = TinyBundles.bundle();
simpleLoggingPropertiesBundle.add("simplelogger.properties", ClassLoader.getSystemResource("simplelogger.properties"));
simpleLoggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "simple-logger-properties");
simpleLoggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "slf4j-simple");
simpleLoggingPropertiesBundle.add(FragmentActivator.class);
res.add(CoreOptions.streamBundle(simpleLoggingPropertiesBundle.build()).noStart());
res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-simple").versionAsInProject().noStart());
/*
* NOTE: when running with slf4j >= 2.0.0, remove the slf4j simple logger above and uncomment the following lines
TinyBundle loggingPropertiesBundle = TinyBundles.bundle();
loggingPropertiesBundle.add("jetty-logging.properties", ClassLoader.getSystemResource("jetty-logging.properties"));
loggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "jetty-logging-properties");
loggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "org.eclipse.jetty.logging");
loggingPropertiesBundle.add(FragmentActivator.class);
res.add(CoreOptions.streamBundle(loggingPropertiesBundle.build()).noStart());
//Fix missing ServiceLoader in slf4j-api 2.0.0 manifest
res.add(wrappedBundle(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject()
.instructions("Require-Capability=osgi.serviceloader;filter:=\"(osgi.serviceloader=org.slf4j.spi.SLF4JServiceProvider)\",osgi.extender;filter:=\"(osgi.extender=osgi.serviceloader.processor)\"")
.overwriteManifest(OverwriteMode.MERGE)
.start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-slf4j-impl").versionAsInProject().start());
*/
res.add(mavenBundle().groupId("org.eclipse.jetty.toolchain").artifactId("jetty-servlet-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.platform").artifactId("org.eclipse.osgi.util").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.platform").artifactId("org.eclipse.osgi.services").versionAsInProject());
@ -160,12 +183,8 @@ public class TestOSGiUtil
res.add(mavenBundle().groupId("org.apache.aries.spifly").artifactId("org.apache.aries.spifly.dynamic.bundle").versionAsInProject().start());
res.add(mavenBundle().groupId("jakarta.annotation").artifactId("jakarta.annotation-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.apache.geronimo.specs").artifactId("geronimo-jta_1.1_spec").version("1.1.1").start());
//the slf4j-api jar does not have support for ServiceLoader in osgi in its manifest, so add it now
res.add(wrappedBundle(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject())
.instructions("Require-Capability=osgi.serviceloader;filter:=\"(osgi.serviceloader=org.slf4j.spi.SLF4JServiceProvider)\",osgi.extender;filter:=\"(osgi.extender=osgi.serviceloader.processor)\"")
.overwriteManifest(OverwriteMode.MERGE)
.start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-slf4j-impl").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-util").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-deploy").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-server").versionAsInProject().start());

View File

@ -0,0 +1 @@
org.slf4j.simpleLogger.defaultLogLevel=info

View File

@ -23,7 +23,7 @@
<extensions>true</extensions>
<configuration>
<instructions>
<Import-Package>javax.transaction.*;version="1.1",*</Import-Package>
<Import-Package>${osgi.slf4j.import.packages},javax.transaction.*;version="1.1",*</Import-Package>
<Require-Capability>
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
</Require-Capability>

View File

@ -45,6 +45,9 @@
<jetty.perf-helper.version>1.0.6</jetty.perf-helper.version>
<ant.version>1.10.9</ant.version>
<unix.socket.tmp></unix.socket.tmp>
<!-- OSGI import-package -->
<osgi.slf4j.import.packages>org.slf4j;version="[1.7,3.0)", org.slf4j.event;version="[1.7,3.0)", org.slf4j.helpers;version="[1.7,3.0)", org.slf4j.spi;version="[1.7,3.0)"</osgi.slf4j.import.packages>
<!-- enable or not TestTracker junit5 extension i.e log message when test method is starting -->
<jetty.testtracker.log>false</jetty.testtracker.log>
<jetty.surefire.argLine>-Dfile.encoding=UTF-8 -Duser.language=en -Duser.region=US -showversion -Xmx4g -Xms2g -Xlog:gc:stderr:time,level,tags</jetty.surefire.argLine>
@ -742,7 +745,7 @@
<Bundle-Classpath>.</Bundle-Classpath>
<Bundle-Copyright>Copyright (c) 2008-2021 Mort Bay Consulting Pty Ltd and others.</Bundle-Copyright>
<Import-Package>
org.slf4j.*;version="[1.7,3.0)",
${osgi.slf4j.import.packages},
*
</Import-Package>
<_provider-policy><![CDATA[$<range;[===,=+)>]]></_provider-policy>