From 8774ccaa0fb04d2b72fa3c9ba573791c6e6e0c66 Mon Sep 17 00:00:00 2001
From: Simone Bordet
Date: Thu, 10 Jun 2021 18:30:18 +0200
Subject: [PATCH] Merged branch 'jetty-10.0.x' into 'jetty-11.0.x'.
Signed-off-by: Simone Bordet
---
demos/demo-jetty-webapp/pom.xml | 9 -
.../src/main/java/com/acme/ChatServlet.java | 21 +-
.../src/main/java/com/acme/Dump.java | 8 +-
.../main/java/com/acme/SecureModeServlet.java | 7 +-
.../src/main/java/com/acme/TestFilter.java | 6 +-
jetty-alpn/jetty-alpn-client/pom.xml | 2 +-
.../jetty-alpn-conscrypt-client/pom.xml | 2 +-
.../jetty-alpn-conscrypt-server/pom.xml | 2 +-
jetty-annotations/pom.xml | 2 +-
jetty-jndi/pom.xml | 2 +-
jetty-osgi/jetty-osgi-boot-jsp/pom.xml | 2 +-
jetty-osgi/jetty-osgi-boot/pom.xml | 46 ++--
jetty-osgi/test-jetty-osgi-context/pom.xml | 23 +-
jetty-osgi/test-jetty-osgi-server/pom.xml | 25 +-
jetty-osgi/test-jetty-osgi/pom.xml | 12 +
.../eclipse/jetty/osgi/test/TestOSGiUtil.java | 37 ++-
.../test/resources/simplelogger.properties | 1 +
jetty-plus/pom.xml | 2 +-
.../jetty/websocket/api/RemoteEndpoint.java | 1 +
.../api/annotations/OnWebSocketMessage.java | 35 ++-
.../JettyWebSocketFrameHandlerFactory.java | 96 ++++---
.../common/JettyWebSocketRemoteEndpoint.java | 1 +
.../tests/AnnotatedPartialListenerTest.java | 240 ++++++++++++++++++
pom.xml | 5 +-
24 files changed, 437 insertions(+), 150 deletions(-)
create mode 100644 jetty-osgi/test-jetty-osgi/src/test/resources/simplelogger.properties
create mode 100644 jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnotatedPartialListenerTest.java
diff --git a/demos/demo-jetty-webapp/pom.xml b/demos/demo-jetty-webapp/pom.xml
index 89b66bc9b6d..73757d77ac6 100644
--- a/demos/demo-jetty-webapp/pom.xml
+++ b/demos/demo-jetty-webapp/pom.xml
@@ -126,15 +126,6 @@
-
- org.slf4j
- slf4j-api
-
-
- org.eclipse.jetty
- jetty-slf4j-impl
- compile
-
org.eclipse.jetty
jetty-servlets
diff --git a/demos/demo-jetty-webapp/src/main/java/com/acme/ChatServlet.java b/demos/demo-jetty-webapp/src/main/java/com/acme/ChatServlet.java
index 372f1b334b4..7ae78ea184b 100644
--- a/demos/demo-jetty-webapp/src/main/java/com/acme/ChatServlet.java
+++ b/demos/demo-jetty-webapp/src/main/java/com/acme/ChatServlet.java
@@ -27,8 +27,6 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.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
@@ -36,8 +34,6 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("serial")
public class ChatServlet extends HttpServlet
{
- private static final Logger LOG = LoggerFactory.getLogger(ChatServlet.class);
-
private long asyncTimeout = 10000;
@Override
@@ -63,7 +59,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 +98,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 +121,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 +143,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 +155,7 @@ public class ChatServlet extends HttpServlet
Map 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 +188,6 @@ public class ChatServlet extends HttpServlet
private void sendMessageToAllMembers(String message, String username, Map room)
{
- LOG.debug("Sending message: {} from: {}", message, username);
for (Member m : room.values())
{
synchronized (m)
@@ -202,10 +197,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();
}
}
diff --git a/demos/demo-jetty-webapp/src/main/java/com/acme/Dump.java b/demos/demo-jetty-webapp/src/main/java/com/acme/Dump.java
index d6af60ade1e..927520fb693 100644
--- a/demos/demo-jetty-webapp/src/main/java/com/acme/Dump.java
+++ b/demos/demo-jetty-webapp/src/main/java/com/acme/Dump.java
@@ -51,8 +51,6 @@ import jakarta.servlet.http.HttpServletRequestWrapper;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpServletResponseWrapper;
import jakarta.servlet.http.Part;
-import org.slf4j.LoggerFactory;
-
/**
* Dump Servlet Request.
@@ -117,7 +115,7 @@ public class Dump extends HttpServlet
}
catch (ServletException e)
{
- getServletContext().log(e.toString());
+ getServletContext().log("Login fail", e);
}
}
@@ -342,12 +340,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;
}
diff --git a/demos/demo-jetty-webapp/src/main/java/com/acme/SecureModeServlet.java b/demos/demo-jetty-webapp/src/main/java/com/acme/SecureModeServlet.java
index f1e097ef4a4..77444287d8f 100644
--- a/demos/demo-jetty-webapp/src/main/java/com/acme/SecureModeServlet.java
+++ b/demos/demo-jetty-webapp/src/main/java/com/acme/SecureModeServlet.java
@@ -27,9 +27,6 @@ import jakarta.servlet.ServletOutputStream;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Dump Servlet Request.
@@ -37,8 +34,6 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("serial")
public class SecureModeServlet extends HttpServlet
{
- private static final Logger LOG = LoggerFactory.getLogger(SecureModeServlet.class);
-
@Override
public void init(ServletConfig config) throws ServletException
{
@@ -117,7 +112,7 @@ public class SecureModeServlet extends HttpServlet
try
{
out.println("check ability to log
");
- LOG.info("testing logging");
+ getServletContext().log("testing logging");
out.println("status: SUCCESS - expected
");
}
catch (SecurityException e)
diff --git a/demos/demo-jetty-webapp/src/main/java/com/acme/TestFilter.java b/demos/demo-jetty-webapp/src/main/java/com/acme/TestFilter.java
index 3df4b6b7b44..b809c6b8b87 100644
--- a/demos/demo-jetty-webapp/src/main/java/com/acme/TestFilter.java
+++ b/demos/demo-jetty-webapp/src/main/java/com/acme/TestFilter.java
@@ -27,8 +27,6 @@ import jakarta.servlet.ServletRequestWrapper;
import jakarta.servlet.ServletResponse;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletRequestWrapper;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/**
* TestFilter.
@@ -39,8 +37,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 _allowed = new HashSet();
@@ -54,7 +50,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
diff --git a/jetty-alpn/jetty-alpn-client/pom.xml b/jetty-alpn/jetty-alpn-client/pom.xml
index 8da76ffdc8d..eb9d694e687 100644
--- a/jetty-alpn/jetty-alpn-client/pom.xml
+++ b/jetty-alpn/jetty-alpn-client/pom.xml
@@ -24,7 +24,7 @@
- org.eclipse.jetty.alpn;resolution:=optional,*
+ ${osgi.slf4j.import.packages},org.eclipse.jetty.alpn;resolution:=optional,*
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
diff --git a/jetty-alpn/jetty-alpn-conscrypt-client/pom.xml b/jetty-alpn/jetty-alpn-conscrypt-client/pom.xml
index 6e9c6d27ab3..ead8b9b703f 100644
--- a/jetty-alpn/jetty-alpn-conscrypt-client/pom.xml
+++ b/jetty-alpn/jetty-alpn-conscrypt-client/pom.xml
@@ -52,7 +52,7 @@
Conscrypt Client ALPN
- org.conscrypt;version="${conscrypt.version}",*
+ ${osgi.slf4j.import.packages},org.conscrypt;version="${conscrypt.version}",*
*
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional
osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Client
diff --git a/jetty-alpn/jetty-alpn-conscrypt-server/pom.xml b/jetty-alpn/jetty-alpn-conscrypt-server/pom.xml
index f1e1cbcb18d..fd164859545 100644
--- a/jetty-alpn/jetty-alpn-conscrypt-server/pom.xml
+++ b/jetty-alpn/jetty-alpn-conscrypt-server/pom.xml
@@ -80,7 +80,7 @@
Conscrypt ALPN
- org.conscrypt;version="${conscrypt.version}",*
+ ${osgi.slf4j.import.packages},org.conscrypt;version="${conscrypt.version}",*
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional
osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Server
<_nouses>true
diff --git a/jetty-annotations/pom.xml b/jetty-annotations/pom.xml
index b09fe35c12e..6efa1686438 100644
--- a/jetty-annotations/pom.xml
+++ b/jetty-annotations/pom.xml
@@ -30,7 +30,7 @@
true
- org.objectweb.asm;version="5",*
+ ${osgi.slf4j.import.packages},org.objectweb.asm;version="5",*
osgi.serviceloader; filter:="(osgi.serviceloader=jakarta.servlet.ServletContainerInitializer)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional
diff --git a/jetty-jndi/pom.xml b/jetty-jndi/pom.xml
index 77e0676a5e3..62896d5ec4d 100644
--- a/jetty-jndi/pom.xml
+++ b/jetty-jndi/pom.xml
@@ -23,7 +23,7 @@
true
- jakarta.mail.*;resolution:=optional,*
+ ${osgi.slf4j.import.packages},jakarta.mail.*;resolution:=optional,*
diff --git a/jetty-osgi/jetty-osgi-boot-jsp/pom.xml b/jetty-osgi/jetty-osgi-boot-jsp/pom.xml
index 8099813b49c..3f7d0df3d62 100644
--- a/jetty-osgi/jetty-osgi-boot-jsp/pom.xml
+++ b/jetty-osgi/jetty-osgi-boot-jsp/pom.xml
@@ -76,6 +76,7 @@
org.eclipse.jetty.osgi.boot
!org.eclipse.jetty.osgi.boot.*
+ ${osgi.slf4j.import.packages},
org.eclipse.jdt.*;resolution:=optional,
org.eclipse.jdt.core.compiler.*;resolution:=optional,
com.sun.el;resolution:=optional,
@@ -132,7 +133,6 @@
org.apache.taglibs.standard.tlv;version="2.0";resolution:=optional,
org.apache.tomcat;version="[10,11)";resolution:=optional,
org.eclipse.jetty.jsp;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))";resolution:=optional,
- org.slf4j.*,
org.osgi.*,
org.xml.*;resolution:=optional,
org.xml.sax.*;resolution:=optional,
diff --git a/jetty-osgi/jetty-osgi-boot/pom.xml b/jetty-osgi/jetty-osgi-boot/pom.xml
index 6056c7e8f85..09d75b29b39 100644
--- a/jetty-osgi/jetty-osgi-boot/pom.xml
+++ b/jetty-osgi/jetty-osgi-boot/pom.xml
@@ -72,30 +72,28 @@
org.eclipse.jetty.osgi.boot.JettyBootstrapActivator
org.eclipse.jetty.*;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))"
- jakarta.mail;version="2.0";resolution:=optional,
- jakarta.mail.event;version="2.0";resolution:=optional,
- jakarta.mail.internet;version="2.0";resolution:=optional,
- jakarta.mail.search;version="2.0";resolution:=optional,
- jakarta.mail.util;version="2.0";resolution:=optional,
- jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- jakarta.servlet.http;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- jakarta.transaction;version="2.0.0";resolution:=optional,
- jakarta.transaction.xa;version="2.0.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,
- *
+ ${osgi.slf4j.import.packages},
+ jakarta.mail;version="2.0";resolution:=optional,
+ jakarta.mail.event;version="2.0";resolution:=optional,
+ jakarta.mail.internet;version="2.0";resolution:=optional,
+ jakarta.mail.search;version="2.0";resolution:=optional,
+ jakarta.mail.util;version="2.0";resolution:=optional,
+ jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ jakarta.servlet.http;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ jakarta.transaction;version="2.0.0";resolution:=optional,
+ jakarta.transaction.xa;version="2.0.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,
+ *
osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)"
diff --git a/jetty-osgi/test-jetty-osgi-context/pom.xml b/jetty-osgi/test-jetty-osgi-context/pom.xml
index 55152e87c11..6edeb938550 100644
--- a/jetty-osgi/test-jetty-osgi-context/pom.xml
+++ b/jetty-osgi/test-jetty-osgi-context/pom.xml
@@ -74,17 +74,18 @@
compilation time. -->
<_nouses>true
- jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- jakarta.servlet.resources;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- 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},
+ jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ jakarta.servlet.resources;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ 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,
+ *
org.eclipse.jetty.*;version="[$(version;==;${parsedVersion.osgiVersion}),$(version;+;${parsedVersion.osgiVersion}))"
diff --git a/jetty-osgi/test-jetty-osgi-server/pom.xml b/jetty-osgi/test-jetty-osgi-server/pom.xml
index f8e9a81adf4..b29a78f2fe4 100644
--- a/jetty-osgi/test-jetty-osgi-server/pom.xml
+++ b/jetty-osgi/test-jetty-osgi-server/pom.xml
@@ -66,19 +66,18 @@
compilation time. -->
<_nouses>true
- jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- jakarta.servlet.resources;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
- 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},
+ jakarta.servlet;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ jakarta.servlet.resources;version="[$(version;==;${servlet.api.version}),$(version;+;${servlet.api.version}))",
+ 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,
+ *
org.eclipse.jetty.*;version="[$(version;==;${parsedVersion.osgiVersion}),$(version;+;${parsedVersion.osgiVersion}))"
diff --git a/jetty-osgi/test-jetty-osgi/pom.xml b/jetty-osgi/test-jetty-osgi/pom.xml
index 0bac891f81d..33c9176dfc0 100644
--- a/jetty-osgi/test-jetty-osgi/pom.xml
+++ b/jetty-osgi/test-jetty-osgi/pom.xml
@@ -142,6 +142,18 @@
+
+ org.slf4j
+ slf4j-api
+ 1.7.30
+ test
+
+
+ org.slf4j
+ slf4j-simple
+ 1.7.30
+ test
+
org.eclipse.jetty
jetty-slf4j-impl
diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
index 3ef462bd502..b4ea2b3d117 100644
--- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
+++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java
@@ -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-jakarta-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());
@@ -159,19 +182,13 @@ public class TestOSGiUtil
res.add(mavenBundle().groupId("org.ow2.asm").artifactId("asm-util").versionAsInProject().start());
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());
-
+
//remove unused imports and exports from jakarta.transaction-api manifest
res.add(wrappedBundle(mavenBundle().groupId("jakarta.transaction").artifactId("jakarta.transaction-api").versionAsInProject())
.instructions("Import-Package=javax.transaction.xa&Export-Package=jakarta.transaction.*;version=\"2.0.0\"")
.overwriteManifest(OverwriteMode.MERGE)
.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());
@@ -206,7 +223,7 @@ public class TestOSGiUtil
{
List
+ *
* @param lookupClass the desired lookup class for the new lookup object.
* @return a lookup object to be used to find methods on the lookupClass.
*/
diff --git a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java
index bfb14b678b4..04e3ca4e814 100644
--- a/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java
+++ b/jetty-websocket/websocket-jetty-common/src/main/java/org/eclipse/jetty/websocket/common/JettyWebSocketRemoteEndpoint.java
@@ -156,6 +156,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
}
+ // FIXME: Remove the throws IOException from API for this method in the next major release.
@Override
public void sendPartialString(String fragment, boolean isLast, WriteCallback callback)
{
diff --git a/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnotatedPartialListenerTest.java b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnotatedPartialListenerTest.java
new file mode 100644
index 00000000000..ef3909bc6e3
--- /dev/null
+++ b/jetty-websocket/websocket-jetty-tests/src/test/java/org/eclipse/jetty/websocket/tests/AnnotatedPartialListenerTest.java
@@ -0,0 +1,240 @@
+//
+// ========================================================================
+// Copyright (c) 1995-2021 Mort Bay Consulting Pty Ltd and others.
+//
+// This program and the accompanying materials are made available under the
+// terms of the Eclipse Public License v. 2.0 which is available at
+// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
+// which is available at https://www.apache.org/licenses/LICENSE-2.0.
+//
+// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
+// ========================================================================
+//
+
+package org.eclipse.jetty.websocket.tests;
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.ByteBuffer;
+import java.util.Objects;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.util.BufferUtil;
+import org.eclipse.jetty.websocket.api.Session;
+import org.eclipse.jetty.websocket.api.WebSocketPartialListener;
+import org.eclipse.jetty.websocket.api.WriteCallback;
+import org.eclipse.jetty.websocket.api.annotations.OnWebSocketMessage;
+import org.eclipse.jetty.websocket.api.annotations.WebSocket;
+import org.eclipse.jetty.websocket.api.exceptions.InvalidWebSocketException;
+import org.eclipse.jetty.websocket.client.WebSocketClient;
+import org.eclipse.jetty.websocket.server.config.JettyWebSocketServletContainerInitializer;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+public class AnnotatedPartialListenerTest
+{
+ public static class PartialEchoSocket implements WebSocketPartialListener
+ {
+ private Session session;
+
+ @Override
+ public void onWebSocketConnect(Session session)
+ {
+ this.session = session;
+ }
+
+ @Override
+ public void onWebSocketPartialBinary(ByteBuffer payload, boolean fin)
+ {
+ session.getRemote().sendPartialBytes(payload, fin, WriteCallback.NOOP);
+ }
+
+ @Override
+ public void onWebSocketPartialText(String payload, boolean fin)
+ {
+ try
+ {
+ session.getRemote().sendPartialString(payload, fin, WriteCallback.NOOP);
+ }
+ catch (IOException e)
+ {
+ throw new IllegalStateException(e);
+ }
+ }
+ }
+
+ @WebSocket
+ public static class PartialStringListener
+ {
+ public BlockingQueue messages = new LinkedBlockingQueue<>();
+
+ public static class MessageSegment
+ {
+ public String message;
+ public boolean last;
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(String message, boolean last)
+ {
+ MessageSegment messageSegment = new MessageSegment();
+ messageSegment.message = message;
+ messageSegment.last = last;
+ messages.add(messageSegment);
+ }
+ }
+
+ @WebSocket
+ public static class PartialByteBufferListener
+ {
+ public BlockingQueue messages = new LinkedBlockingQueue<>();
+
+ public static class MessageSegment
+ {
+ public ByteBuffer buffer;
+ public boolean last;
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(ByteBuffer buffer, boolean last)
+ {
+ MessageSegment messageSegment = new MessageSegment();
+ messageSegment.buffer = BufferUtil.copy(buffer);
+ messageSegment.last = last;
+ messages.add(messageSegment);
+ }
+ }
+
+ @WebSocket
+ public static class InvalidDoubleBinaryListener
+ {
+ @OnWebSocketMessage
+ public void onMessage(ByteBuffer bytes, boolean last)
+ {
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(ByteBuffer bytes)
+ {
+ }
+ }
+
+ @WebSocket
+ public static class InvalidDoubleTextListener
+ {
+ @OnWebSocketMessage
+ public void onMessage(String content, boolean last)
+ {
+ }
+
+ @OnWebSocketMessage
+ public void onMessage(String content)
+ {
+ }
+ }
+
+ private Server server;
+ private URI serverUri;
+ private WebSocketClient client;
+
+ @BeforeEach
+ public void before() throws Exception
+ {
+ server = new Server();
+ ServerConnector connector = new ServerConnector(server);
+ server.addConnector(connector);
+ ServletContextHandler contextHandler = new ServletContextHandler();
+ contextHandler.setContextPath("/");
+ server.setHandler(contextHandler);
+ JettyWebSocketServletContainerInitializer.configure(contextHandler, ((servletContext, container) ->
+ {
+ container.setAutoFragment(false);
+ container.addMapping("/", PartialEchoSocket.class);
+ }));
+ server.start();
+ serverUri = URI.create("ws://localhost:" + connector.getLocalPort() + "/");
+
+ client = new WebSocketClient();
+ client.setAutoFragment(false);
+ client.start();
+ }
+
+ @AfterEach
+ public void after() throws Exception
+ {
+ client.stop();
+ server.stop();
+ }
+
+ @Test
+ public void testAnnotatedPartialString() throws Exception
+ {
+ PartialStringListener endpoint = new PartialStringListener();
+ try (Session session = client.connect(endpoint, serverUri).get(5, TimeUnit.SECONDS))
+ {
+ session.getRemote().sendPartialString("hell", false);
+ session.getRemote().sendPartialString("o w", false);
+ session.getRemote().sendPartialString("orld", true);
+ }
+
+ PartialStringListener.MessageSegment segment;
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.message, is("hell"));
+ assertThat(segment.last, is(false));
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.message, is("o w"));
+ assertThat(segment.last, is(false));
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.message, is("orld"));
+ assertThat(segment.last, is(true));
+ }
+
+ @Test
+ public void testAnnotatedPartialByteBuffer() throws Exception
+ {
+ PartialByteBufferListener endpoint = new PartialByteBufferListener();
+ try (Session session = client.connect(endpoint, serverUri).get(5, TimeUnit.SECONDS))
+ {
+ session.getRemote().sendPartialBytes(BufferUtil.toBuffer("hell"), false);
+ session.getRemote().sendPartialBytes(BufferUtil.toBuffer("o w"), false);
+ session.getRemote().sendPartialBytes(BufferUtil.toBuffer("orld"), true);
+ }
+
+ PartialByteBufferListener.MessageSegment segment;
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.buffer, is(BufferUtil.toBuffer("hell")));
+ assertThat(segment.last, is(false));
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.buffer, is(BufferUtil.toBuffer("o w")));
+ assertThat(segment.last, is(false));
+
+ segment = Objects.requireNonNull(endpoint.messages.poll(5, TimeUnit.SECONDS));
+ assertThat(segment.buffer, is(BufferUtil.toBuffer("orld")));
+ assertThat(segment.last, is(true));
+ }
+
+ @Test
+ public void testDoubleOnMessageAnnotation()
+ {
+ InvalidDoubleBinaryListener doubleBinaryListener = new InvalidDoubleBinaryListener();
+ assertThrows(InvalidWebSocketException.class, () -> client.connect(doubleBinaryListener, serverUri));
+
+ InvalidDoubleTextListener doubleTextListener = new InvalidDoubleTextListener();
+ assertThrows(InvalidWebSocketException.class, () -> client.connect(doubleTextListener, serverUri));
+ }
+}
diff --git a/pom.xml b/pom.xml
index 901a5ea91d9..22a2ba55ab0 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,6 +52,9 @@
1.0.6
1.10.9
+
+ 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)"
+
false
-Dfile.encoding=UTF-8 -Duser.language=en -Duser.region=US -showversion -Xmx4g -Xms2g -Xlog:gc:stderr:time,level,tags
@@ -755,7 +758,7 @@
.
Copyright (c) 2008-2021 Mort Bay Consulting Pty Ltd and others.
- org.slf4j.*;version="[1.7,3.0)",
+ ${osgi.slf4j.import.packages},
*
<_provider-policy>]]>