Merged branch 'jetty-10.0.x' into 'jetty-11.0.x'.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
This commit is contained in:
Simone Bordet 2021-06-10 18:30:18 +02:00
parent 61a30e381d
commit 8774ccaa0f
24 changed files with 437 additions and 150 deletions

View File

@ -126,15 +126,6 @@
</pluginManagement> </pluginManagement>
</build> </build>
<dependencies> <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> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId> <artifactId>jetty-servlets</artifactId>

View File

@ -27,8 +27,6 @@ import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpServletResponse;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
// Simple asynchronous Chat room. // Simple asynchronous Chat room.
// This does not handle duplicate usernames or multiple frames/tabs from the same browser // This does not handle duplicate usernames or multiple frames/tabs from the same browser
@ -36,8 +34,6 @@ import org.slf4j.LoggerFactory;
@SuppressWarnings("serial") @SuppressWarnings("serial")
public class ChatServlet extends HttpServlet public class ChatServlet extends HttpServlet
{ {
private static final Logger LOG = LoggerFactory.getLogger(ChatServlet.class);
private long asyncTimeout = 10000; private long asyncTimeout = 10000;
@Override @Override
@ -63,7 +59,7 @@ public class ChatServlet extends HttpServlet
@Override @Override
public void onTimeout(AsyncEvent event) throws IOException public void onTimeout(AsyncEvent event) throws IOException
{ {
LOG.debug("resume request"); getServletContext().log("resume request");
AsyncContext async = _async.get(); AsyncContext async = _async.get();
if (async != null && _async.compareAndSet(async, null)) if (async != null && _async.compareAndSet(async, null))
{ {
@ -102,10 +98,10 @@ public class ChatServlet extends HttpServlet
String message = request.getParameter("message"); String message = request.getParameter("message");
String username = request.getParameter("user"); 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) if (username == null)
{ {
LOG.debug("no parameter user set, sending 503"); getServletContext().log("no parameter user set, sending 503");
response.sendError(503, "user==null"); response.sendError(503, "user==null");
return; return;
} }
@ -125,14 +121,14 @@ public class ChatServlet extends HttpServlet
{ {
synchronized (member) synchronized (member)
{ {
LOG.debug("Queue size: {}", member._queue.size()); getServletContext().log("Queue size: " + member._queue.size());
if (!member._queue.isEmpty()) if (!member._queue.isEmpty())
{ {
sendSingleMessage(response, member); sendSingleMessage(response, member);
} }
else else
{ {
LOG.debug("starting async"); getServletContext().log("starting async");
AsyncContext async = request.startAsync(); AsyncContext async = request.startAsync();
async.setTimeout(asyncTimeout); async.setTimeout(asyncTimeout);
async.addListener(member); async.addListener(member);
@ -147,7 +143,7 @@ public class ChatServlet extends HttpServlet
Member member = room.get(username); Member member = room.get(username);
if (member == null) 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); member = new Member(username);
room.put(username, member); room.put(username, member);
} }
@ -159,7 +155,7 @@ public class ChatServlet extends HttpServlet
Map<String, Member> room = _rooms.get(path); Map<String, Member> room = _rooms.get(path);
if (room == null) 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<>(); room = new HashMap<>();
_rooms.put(path, room); _rooms.put(path, room);
} }
@ -192,7 +188,6 @@ public class ChatServlet extends HttpServlet
private void sendMessageToAllMembers(String message, String username, Map<String, Member> room) private void sendMessageToAllMembers(String message, String username, Map<String, Member> room)
{ {
LOG.debug("Sending message: {} from: {}", message, username);
for (Member m : room.values()) for (Member m : room.values())
{ {
synchronized (m) synchronized (m)
@ -202,10 +197,8 @@ public class ChatServlet extends HttpServlet
// wakeup member if polling // wakeup member if polling
AsyncContext async = m._async.get(); AsyncContext async = m._async.get();
LOG.debug("Async found: {}", async);
if (async != null & m._async.compareAndSet(async, null)) if (async != null & m._async.compareAndSet(async, null))
{ {
LOG.debug("dispatch");
async.dispatch(); async.dispatch();
} }
} }

View File

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

View File

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

View File

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

View File

@ -24,7 +24,7 @@
</goals> </goals>
<configuration> <configuration>
<instructions> <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> <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> </instructions>
</configuration> </configuration>

View File

@ -52,7 +52,7 @@
<configuration> <configuration>
<instructions> <instructions>
<Bundle-Description>Conscrypt Client ALPN</Bundle-Description> <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> <Export-Package>*</Export-Package>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability> <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> <Provide-Capability>osgi.serviceloader; osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Client</Provide-Capability>

View File

@ -80,7 +80,7 @@
<configuration> <configuration>
<instructions> <instructions>
<Bundle-Description>Conscrypt ALPN</Bundle-Description> <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> <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> <Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Server</Provide-Capability>
<_nouses>true</_nouses> <_nouses>true</_nouses>

View File

@ -30,7 +30,7 @@
<extensions>true</extensions> <extensions>true</extensions>
<configuration> <configuration>
<instructions> <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=jakarta.servlet.ServletContainerInitializer)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional <Require-Capability>osgi.serviceloader; filter:="(osgi.serviceloader=jakarta.servlet.ServletContainerInitializer)";resolution:=optional;cardinality:=multiple, osgi.extender; filter:="(osgi.extender=osgi.serviceloader.processor)";resolution:=optional
</Require-Capability> </Require-Capability>
</instructions> </instructions>

View File

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

View File

@ -76,6 +76,7 @@
<Fragment-Host>org.eclipse.jetty.osgi.boot</Fragment-Host> <Fragment-Host>org.eclipse.jetty.osgi.boot</Fragment-Host>
<Export-Package>!org.eclipse.jetty.osgi.boot.*</Export-Package> <Export-Package>!org.eclipse.jetty.osgi.boot.*</Export-Package>
<Import-Package> <Import-Package>
${osgi.slf4j.import.packages},
org.eclipse.jdt.*;resolution:=optional, org.eclipse.jdt.*;resolution:=optional,
org.eclipse.jdt.core.compiler.*;resolution:=optional, org.eclipse.jdt.core.compiler.*;resolution:=optional,
com.sun.el;resolution:=optional, com.sun.el;resolution:=optional,
@ -132,7 +133,6 @@
org.apache.taglibs.standard.tlv;version="2.0";resolution:=optional, org.apache.taglibs.standard.tlv;version="2.0";resolution:=optional,
org.apache.tomcat;version="[10,11)";resolution:=optional, org.apache.tomcat;version="[10,11)";resolution:=optional,
org.eclipse.jetty.jsp;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))";resolution:=optional, org.eclipse.jetty.jsp;version="[$(version;===;${parsedVersion.osgiVersion}),$(version;==+;${parsedVersion.osgiVersion}))";resolution:=optional,
org.slf4j.*,
org.osgi.*, org.osgi.*,
org.xml.*;resolution:=optional, org.xml.*;resolution:=optional,
org.xml.sax.*;resolution:=optional, org.xml.sax.*;resolution:=optional,

View File

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

View File

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

View File

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

View File

@ -142,6 +142,18 @@
<!-- Jetty OSGi Deps --> <!-- 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> <dependency>
<groupId>org.eclipse.jetty</groupId> <groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId> <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"))); 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(); TinyBundle loggingPropertiesBundle = TinyBundles.bundle();
loggingPropertiesBundle.add("jetty-logging.properties", ClassLoader.getSystemResource("jetty-logging.properties")); loggingPropertiesBundle.add("jetty-logging.properties", ClassLoader.getSystemResource("jetty-logging.properties"));
loggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "jetty-logging-properties"); loggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "jetty-logging-properties");
loggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "org.eclipse.jetty.logging"); loggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "org.eclipse.jetty.logging");
loggingPropertiesBundle.add(FragmentActivator.class); loggingPropertiesBundle.add(FragmentActivator.class);
res.add(CoreOptions.streamBundle(loggingPropertiesBundle.build()).noStart()); 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.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.util").versionAsInProject());
res.add(mavenBundle().groupId("org.eclipse.platform").artifactId("org.eclipse.osgi.services").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.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("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("jakarta.annotation").artifactId("jakarta.annotation-api").versionAsInProject().start());
//remove unused imports and exports from jakarta.transaction-api manifest //remove unused imports and exports from jakarta.transaction-api manifest
res.add(wrappedBundle(mavenBundle().groupId("jakarta.transaction").artifactId("jakarta.transaction-api").versionAsInProject()) 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\"") .instructions("Import-Package=javax.transaction.xa&Export-Package=jakarta.transaction.*;version=\"2.0.0\"")
.overwriteManifest(OverwriteMode.MERGE) .overwriteManifest(OverwriteMode.MERGE)
.start()); .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-util").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-deploy").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()); res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-server").versionAsInProject().start());
@ -206,7 +223,7 @@ public class TestOSGiUtil
{ {
List<Option> res = new ArrayList<>(); List<Option> res = new ArrayList<>();
//jetty jsp bundles //jetty jsp bundles
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-el").versionAsInProject().start()); res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-el").versionAsInProject().start());
res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-jsp").versionAsInProject().start()); res.add(mavenBundle().groupId("org.mortbay.jasper").artifactId("apache-jsp").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("apache-jsp").versionAsInProject().start()); res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("apache-jsp").versionAsInProject().start());
@ -309,6 +326,4 @@ public class TestOSGiUtil
{ {
assertTrue(message + "\nContains: <" + needle + ">\nIn:\n" + haystack, haystack.contains(needle)); assertTrue(message + "\nContains: <" + needle + ">\nIn:\n" + haystack, haystack.contains(needle));
} }
// }
// }
} }

View File

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

View File

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

View File

@ -103,6 +103,7 @@ public interface RemoteEndpoint
* @param fragment the text being sent * @param fragment the text being sent
* @param isLast true if this is the last piece of the partial bytes * @param isLast true if this is the last piece of the partial bytes
* @param callback callback to notify of success or failure of the write operation * @param callback callback to notify of success or failure of the write operation
* @throws IOException this never throws IOException, it was a mistake to have this in the signature.
*/ */
void sendPartialString(String fragment, boolean isLast, WriteCallback callback) throws IOException; void sendPartialString(String fragment, boolean isLast, WriteCallback callback) throws IOException;

View File

@ -21,6 +21,7 @@ import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
import org.eclipse.jetty.websocket.api.Session; import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.WebSocketPartialListener;
/** /**
* Annotation for tagging methods to receive Binary or Text Message events. * Annotation for tagging methods to receive Binary or Text Message events.
@ -30,23 +31,31 @@ import org.eclipse.jetty.websocket.api.Session;
* <p> * <p>
* <u>Text Message Versions</u> * <u>Text Message Versions</u>
* <ol> * <ol>
* <li><code>public void methodName(String text)</code></li> * <li>{@code public void methodName(String text)}</li>
* <li><code>public void methodName({@link Session} session, String text)</code></li> * <li>{@code public void methodName(Session session, String text)}</li>
* <li><code>public void methodName(Reader reader)</code></li> * <li>{@code public void methodName(Reader reader)}</li>
* <li><code>public void methodName({@link Session} session, Reader reader)</code></li> * <li>{@code public void methodName(Session session, Reader reader)}</li>
* </ol> * </ol>
* Note: that the {@link Reader} in this case will always use UTF-8 encoding/charset (this is dictated by the RFC 6455 spec for Text Messages. If you need to * <p>Note: that the {@link Reader} in this case will always use UTF-8 encoding/charset (this is dictated by the RFC 6455 spec for Text Messages. If you need to
* use a non-UTF-8 encoding/charset, you are instructed to use the binary messaging techniques. * use a non-UTF-8 encoding/charset, you are instructed to use the binary messaging techniques.</p>
* <p>
* <u>Binary Message Versions</u> * <u>Binary Message Versions</u>
* <ol> * <ol>
* <li><code>public void methodName(ByteBuffer message)</code></li> * <li>{@code public void methodName(ByteBuffer message)}</li>
* <li><code>public void methodName({@link Session} session, ByteBuffer message)</code></li> * <li>{@code public void methodName(Session session, ByteBuffer message)}</li>
* <li><code>public void methodName(byte buf[], int offset, int length)</code></li> * <li>{@code public void methodName(byte[] buf, int offset, int length)}</li>
* <li><code>public void methodName({@link Session} session, byte buf[], int offset, int length)</code></li> * <li>{@code public void methodName(Session session, byte[] buf, int offset, int length)}</li>
* <li><code>public void methodName(InputStream stream)</code></li> * <li>{@code public void methodName(InputStream stream)}</li>
* <li><code>public void methodName({@link Session} session, InputStream stream)</code></li> * <li>{@code public void methodName(Session session, InputStream stream)}</li>
* </ol> * </ol>
* <u>Partial Message Variations</u>
* <p>These are used to receive partial messages without aggregating them into a complete WebSocket message. Instead the a boolean
* argument is supplied to indicate whether this is the last segment of data of the message. See {@link WebSocketPartialListener}
* interface for more details on partial messages.</p>
* <ol>
* <li>{@code public void methodName(ByteBuffer payload, boolean last)}</li>
* <li>{@code public void methodName(String payload, boolean last)}</li>
* </ol>
* <p>Note: Similar to the signatures above these can all be used with an optional first {@link Session} parameter.</p>
*/ */
@Documented @Documented
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)

View File

@ -78,6 +78,51 @@ import org.eclipse.jetty.websocket.core.internal.util.ReflectUtils;
*/ */
public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
{ {
private static final InvokerUtils.Arg[] textCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(String.class).required()
};
private static final InvokerUtils.Arg[] binaryBufferCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(ByteBuffer.class).required()
};
private static final InvokerUtils.Arg[] binaryArrayCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(byte[].class).required(),
new InvokerUtils.Arg(int.class), // offset
new InvokerUtils.Arg(int.class) // length
};
private static final InvokerUtils.Arg[] inputStreamCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(InputStream.class).required()
};
private static final InvokerUtils.Arg[] readerCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(Reader.class).required()
};
private static final InvokerUtils.Arg[] textPartialCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(String.class).required(),
new InvokerUtils.Arg(boolean.class).required()
};
private static final InvokerUtils.Arg[] binaryPartialBufferCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(ByteBuffer.class).required(),
new InvokerUtils.Arg(boolean.class).required()
};
private static final InvokerUtils.Arg[] binaryPartialArrayCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(byte[].class).required(),
new InvokerUtils.Arg(boolean.class).required()
};
private final WebSocketContainer container; private final WebSocketContainer container;
private final WebSocketComponents components; private final WebSocketComponents components;
private final Map<Class<?>, JettyWebSocketFrameHandlerMetadata> metadataMap = new ConcurrentHashMap<>(); private final Map<Class<?>, JettyWebSocketFrameHandlerMetadata> metadataMap = new ConcurrentHashMap<>();
@ -333,34 +378,6 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
if (onMessages != null && onMessages.length > 0) if (onMessages != null && onMessages.length > 0)
{ {
// The different kind of @OnWebSocketMessage method parameter signatures expected // The different kind of @OnWebSocketMessage method parameter signatures expected
InvokerUtils.Arg[] textCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(String.class).required()
};
InvokerUtils.Arg[] binaryBufferCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(ByteBuffer.class).required()
};
InvokerUtils.Arg[] binaryArrayCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(byte[].class).required(),
new InvokerUtils.Arg(int.class), // offset
new InvokerUtils.Arg(int.class) // length
};
InvokerUtils.Arg[] inputStreamCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(InputStream.class).required()
};
InvokerUtils.Arg[] readerCallingArgs = new InvokerUtils.Arg[]{
new InvokerUtils.Arg(Session.class),
new InvokerUtils.Arg(Reader.class).required()
};
for (Method onMsg : onMessages) for (Method onMsg : onMessages)
{ {
assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class); assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class);
@ -409,11 +426,27 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
metadata.setTextHandler(ReaderMessageSink.class, methodHandle, onMsg); metadata.setTextHandler(ReaderMessageSink.class, methodHandle, onMsg);
continue; continue;
} }
else
methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, textPartialCallingArgs);
if (methodHandle != null)
{ {
// Not a valid @OnWebSocketMessage declaration signature // Partial Text Message
throw InvalidSignatureException.build(endpointClass, OnWebSocketMessage.class, onMsg); assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class);
metadata.setTextHandler(PartialStringMessageSink.class, methodHandle, onMsg);
continue;
} }
methodHandle = InvokerUtils.optionalMutatedInvoker(lookup, endpointClass, onMsg, binaryPartialBufferCallingArgs);
if (methodHandle != null)
{
// Partial ByteBuffer Message
assertSignatureValid(endpointClass, onMsg, OnWebSocketMessage.class);
metadata.setBinaryHandle(PartialByteBufferMessageSink.class, methodHandle, onMsg);
continue;
}
// Not a valid @OnWebSocketMessage declaration signature
throw InvalidSignatureException.build(endpointClass, OnWebSocketMessage.class, onMsg);
} }
} }
@ -498,6 +531,7 @@ public class JettyWebSocketFrameHandlerFactory extends ContainerLifeCycle
* access to the lookupClasses private methods. This is possible but requires extra configuration * access to the lookupClasses private methods. This is possible but requires extra configuration
* to provide private access which is not necessary for the purpose of accessing the public methods. * to provide private access which is not necessary for the purpose of accessing the public methods.
* </p> * </p>
*
* @param lookupClass the desired lookup class for the new lookup object. * @param lookupClass the desired lookup class for the new lookup object.
* @return a lookup object to be used to find methods on the lookupClass. * @return a lookup object to be used to find methods on the lookupClass.
*/ */

View File

@ -156,6 +156,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS); b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
} }
// FIXME: Remove the throws IOException from API for this method in the next major release.
@Override @Override
public void sendPartialString(String fragment, boolean isLast, WriteCallback callback) public void sendPartialString(String fragment, boolean isLast, WriteCallback callback)
{ {

View File

@ -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<MessageSegment> 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<MessageSegment> 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));
}
}

View File

@ -52,6 +52,9 @@
<jetty.perf-helper.version>1.0.6</jetty.perf-helper.version> <jetty.perf-helper.version>1.0.6</jetty.perf-helper.version>
<ant.version>1.10.9</ant.version> <ant.version>1.10.9</ant.version>
<unix.socket.tmp></unix.socket.tmp> <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 --> <!-- enable or not TestTracker junit5 extension i.e log message when test method is starting -->
<jetty.testtracker.log>false</jetty.testtracker.log> <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> <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>
@ -755,7 +758,7 @@
<Bundle-Classpath>.</Bundle-Classpath> <Bundle-Classpath>.</Bundle-Classpath>
<Bundle-Copyright>Copyright (c) 2008-2021 Mort Bay Consulting Pty Ltd and others.</Bundle-Copyright> <Bundle-Copyright>Copyright (c) 2008-2021 Mort Bay Consulting Pty Ltd and others.</Bundle-Copyright>
<Import-Package> <Import-Package>
org.slf4j.*;version="[1.7,3.0)", ${osgi.slf4j.import.packages},
* *
</Import-Package> </Import-Package>
<_provider-policy><![CDATA[$<range;[===,=+)>]]></_provider-policy> <_provider-policy><![CDATA[$<range;[===,=+)>]]></_provider-policy>