From 07991f41d3c80f9f53040a699632b7f8237b3bd4 Mon Sep 17 00:00:00 2001 From: Ludovic Orban Date: Wed, 22 May 2024 09:28:16 +0200 Subject: [PATCH 01/11] Allow ContentListener and AsyncContentListener to throw Exception (#11825) #11800 allow ContentListener and AsyncContentListener to throw Exception Signed-off-by: Ludovic Orban --- .../org/eclipse/jetty/client/Response.java | 31 ++++++---- .../client/AsyncContentListenerTest.java | 27 ++++++++- .../jetty/client/ContentListenerTest.java | 56 +++++++++++++++++++ 3 files changed, 101 insertions(+), 13 deletions(-) create mode 100644 jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/ContentListenerTest.java diff --git a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/Response.java b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/Response.java index 10b0db2a60ea..c07188acd0fa 100644 --- a/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/Response.java +++ b/jetty-core/jetty-client/src/main/java/org/eclipse/jetty/client/Response.java @@ -147,24 +147,19 @@ interface ContentListener extends AsyncContentListener * Callback method invoked when the response content has been received, parsed and there is demand. * This method may be invoked multiple times, and the {@code content} buffer * must be consumed (or copied) before returning from this method. + * This method is also always invoked when content arrives as demand is automatically registered on return. * * @param response the response containing the response line data and the headers * @param content the content bytes received + * @throws Exception an uncaught exception will abort the response and eventually reclaim the ByteBuffer, if applicable */ - void onContent(Response response, ByteBuffer content); + void onContent(Response response, ByteBuffer content) throws Exception; @Override - default void onContent(Response response, Content.Chunk chunk, Runnable demander) + default void onContent(Response response, Content.Chunk chunk, Runnable demander) throws Exception { - try - { - onContent(response, chunk.getByteBuffer()); - demander.run(); - } - catch (Throwable x) - { - response.abort(x); - } + onContent(response, chunk.getByteBuffer()); + demander.run(); } } @@ -175,7 +170,19 @@ default void onContent(Response response, Content.Chunk chunk, Runnable demander */ interface AsyncContentListener extends ContentSourceListener { - void onContent(Response response, Content.Chunk chunk, Runnable demander); + /** + * Callback method invoked when the response content has been received, parsed and there is demand. + * The {@code chunk} must be consumed, copied, or retained before returning from this method as + * it is then automatically released. + * The {@code demander} must be run before this method may be invoked again. + * + * @param response the response containing the response line data and the headers + * @param chunk the chunk received + * @param demander the runnable to be run to demand the next chunk + * @throws Exception an uncaught exception will abort the response, release the chunk and fail the content source + * from which the chunk was read from + */ + void onContent(Response response, Content.Chunk chunk, Runnable demander) throws Exception; @Override default void onContentSource(Response response, Content.Source contentSource) diff --git a/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/AsyncContentListenerTest.java b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/AsyncContentListenerTest.java index 01d302fa4754..1f74440ade43 100644 --- a/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/AsyncContentListenerTest.java +++ b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/AsyncContentListenerTest.java @@ -33,6 +33,31 @@ public class AsyncContentListenerTest { + @Test + public void testOnContentThrowingException() + { + TestSource originalSource = new TestSource( + Content.Chunk.from(ByteBuffer.wrap(new byte[] {1}), false), + Content.Chunk.from(ByteBuffer.wrap(new byte[] {2}), false), + Content.Chunk.from(ByteBuffer.wrap(new byte[] {3}), true) + ); + Response.AsyncContentListener asyncContentListener = (response, chunk, demander) -> + { + throw new NumberFormatException(); + }; + + HttpResponse response = new HttpResponse(new HttpRequest(new HttpClient(), new HttpConversation(), URI.create("http://localhost"))); + asyncContentListener.onContentSource(response, originalSource); + + // Assert that the source was failed. + Content.Chunk lastChunk = originalSource.read(); + assertThat(Content.Chunk.isFailure(lastChunk, true), is(true)); + assertThat(lastChunk.getFailure(), instanceOf(NumberFormatException.class)); + + // Assert that the response was aborted. + assertThat(response.getRequest().getAbortCause(), instanceOf(NumberFormatException.class)); + } + @Test public void testTransientFailureBecomesTerminal() { @@ -70,7 +95,7 @@ public void testTransientFailureBecomesTerminal() originalSource.close(); } - private static class TestSource extends ChunksContentSource implements Closeable + static class TestSource extends ChunksContentSource implements Closeable { private Content.Chunk[] chunks; diff --git a/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/ContentListenerTest.java b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/ContentListenerTest.java new file mode 100644 index 000000000000..c579f7250112 --- /dev/null +++ b/jetty-core/jetty-client/src/test/java/org/eclipse/jetty/client/ContentListenerTest.java @@ -0,0 +1,56 @@ +// +// ======================================================================== +// Copyright (c) 1995 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.client; + +import java.net.URI; +import java.nio.ByteBuffer; + +import org.eclipse.jetty.client.AsyncContentListenerTest.TestSource; +import org.eclipse.jetty.client.transport.HttpConversation; +import org.eclipse.jetty.client.transport.HttpRequest; +import org.eclipse.jetty.client.transport.HttpResponse; +import org.eclipse.jetty.io.Content; +import org.junit.jupiter.api.Test; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; + +public class ContentListenerTest +{ + @Test + public void testOnContentThrowingException() + { + TestSource originalSource = new TestSource( + Content.Chunk.from(ByteBuffer.wrap(new byte[] {1}), false), + Content.Chunk.from(ByteBuffer.wrap(new byte[] {2}), false), + Content.Chunk.from(ByteBuffer.wrap(new byte[] {3}), true) + ); + Response.ContentListener contentListener = (response, content) -> + { + throw new NumberFormatException(); + }; + + HttpResponse response = new HttpResponse(new HttpRequest(new HttpClient(), new HttpConversation(), URI.create("http://localhost"))); + contentListener.onContentSource(response, originalSource); + + // Assert that the source was failed. + Content.Chunk lastChunk = originalSource.read(); + assertThat(Content.Chunk.isFailure(lastChunk, true), is(true)); + assertThat(lastChunk.getFailure(), instanceOf(NumberFormatException.class)); + + // Assert that the response was aborted. + assertThat(response.getRequest().getAbortCause(), instanceOf(NumberFormatException.class)); + } +} From 10d0898460eca84d358e5a7c451f001502e46bae Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 23 May 2024 06:42:01 +1000 Subject: [PATCH 02/11] Fix #11811 insensitive header name set (#11823) * Fix #11811 insensitive header name set Fix #11811 insensitive header name set by: + Using a EnumSet and TreeSet to ensure no duplicates in the set + Using an ArrayList to preserve the ordering (not necessary, but useful). * updates from review --- .../org/eclipse/jetty/http/HttpFields.java | 38 ++++++++++++- .../eclipse/jetty/http/HttpFieldsTest.java | 41 ++++++++++++++ .../jetty/ee10/servlet/RequestTest.java | 54 +++++++++++++++++++ 3 files changed, 132 insertions(+), 1 deletion(-) diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java index a38b1c905123..58be45a97b44 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpFields.java @@ -13,6 +13,7 @@ package org.eclipse.jetty.http; +import java.util.AbstractSet; import java.util.ArrayList; import java.util.Collections; import java.util.EnumSet; @@ -24,6 +25,7 @@ import java.util.NoSuchElementException; import java.util.Objects; import java.util.Set; +import java.util.TreeSet; import java.util.concurrent.TimeUnit; import java.util.function.BiFunction; import java.util.function.BiPredicate; @@ -596,7 +598,41 @@ default Enumeration getFieldNames() */ default Set getFieldNamesCollection() { - return stream().map(HttpField::getName).collect(Collectors.toSet()); + Set seenByHeader = EnumSet.noneOf(HttpHeader.class); + Set seenByName = null; + List list = new ArrayList<>(size()); + + for (HttpField f : this) + { + HttpHeader header = f.getHeader(); + if (header == null) + { + if (seenByName == null) + seenByName = new TreeSet<>(String::compareToIgnoreCase); + if (seenByName.add(f.getName())) + list.add(f.getName()); + } + else if (seenByHeader.add(header)) + { + list.add(f.getName()); + } + } + + // use the list to retain a rough ordering + return new AbstractSet<>() + { + @Override + public Iterator iterator() + { + return list.iterator(); + } + + @Override + public int size() + { + return list.size(); + } + }; } /** diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java index a41983543bed..f2d3c8cdd1ad 100644 --- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java +++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpFieldsTest.java @@ -335,6 +335,47 @@ public void testGet() assertThrows(NoSuchElementException.class, () -> header.getField(2)); } + @Test + public void testCaseInsensitive() + { + HttpFields header = HttpFields.build() + .add("expect", "100") + .add("RaNdOm", "value") + .add("Accept-Charset", "UTF-8") + .add("accept-charset", "UTF-16") + .add("foo-bar", "one") + .add("Foo-Bar", "two") + .asImmutable(); + + assertThat(header.get("expect"), is("100")); + assertThat(header.get("Expect"), is("100")); + assertThat(header.get("EXPECT"), is("100")); + assertThat(header.get("eXpEcT"), is("100")); + assertThat(header.get(HttpHeader.EXPECT), is("100")); + + assertThat(header.get("random"), is("value")); + assertThat(header.get("Random"), is("value")); + assertThat(header.get("RANDOM"), is("value")); + assertThat(header.get("rAnDoM"), is("value")); + assertThat(header.get("RaNdOm"), is("value")); + + assertThat(header.get("Accept-Charset"), is("UTF-8")); + assertThat(header.get("accept-charset"), is("UTF-8")); + assertThat(header.get(HttpHeader.ACCEPT_CHARSET), is("UTF-8")); + + assertThat(header.getValuesList("Accept-Charset"), contains("UTF-8", "UTF-16")); + assertThat(header.getValuesList("accept-charset"), contains("UTF-8", "UTF-16")); + assertThat(header.getValuesList(HttpHeader.ACCEPT_CHARSET), contains("UTF-8", "UTF-16")); + + assertThat(header.get("foo-bar"), is("one")); + assertThat(header.get("Foo-Bar"), is("one")); + assertThat(header.getValuesList("foo-bar"), contains("one", "two")); + assertThat(header.getValuesList("Foo-Bar"), contains("one", "two")); + + // We know the order of the set is deterministic + assertThat(header.getFieldNamesCollection(), contains("expect", "RaNdOm", "Accept-Charset", "foo-bar")); + } + @ParameterizedTest @MethodSource("mutables") public void testGetKnown(HttpFields.Mutable header) diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/RequestTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/RequestTest.java index df689870a1c1..69d820b4d523 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/RequestTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/RequestTest.java @@ -118,6 +118,60 @@ public void destroy() throws Exception LifeCycle.stop(_server); } + @Test + public void testCaseInsensitiveHeaders() throws Exception + { + final AtomicReference resultIsSecure = new AtomicReference<>(); + + startServer(new HttpServlet() + { + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse resp) + { + assertThat(request.getHeader("accept"), is("*/*")); + assertThat(request.getHeader("Accept"), is("*/*")); + assertThat(request.getHeader("ACCEPT"), is("*/*")); + assertThat(request.getHeader("AcCePt"), is("*/*")); + + assertThat(request.getHeader("random"), is("value")); + assertThat(request.getHeader("Random"), is("value")); + assertThat(request.getHeader("RANDOM"), is("value")); + assertThat(request.getHeader("rAnDoM"), is("value")); + assertThat(request.getHeader("RaNdOm"), is("value")); + + assertThat(request.getHeader("Accept-Charset"), is("UTF-8")); + assertThat(request.getHeader("accept-charset"), is("UTF-8")); + + assertThat(Collections.list(request.getHeaders("Accept-Charset")), contains("UTF-8", "UTF-16")); + assertThat(Collections.list(request.getHeaders("accept-charset")), contains("UTF-8", "UTF-16")); + + assertThat(request.getHeader("foo-bar"), is("one")); + assertThat(request.getHeader("Foo-Bar"), is("one")); + assertThat(Collections.list(request.getHeaders("foo-bar")), contains("one", "two")); + assertThat(Collections.list(request.getHeaders("Foo-Bar")), contains("one", "two")); + + assertThat(Collections.list(request.getHeaderNames()), + contains("Host", "Connection", "Accept", "RaNdOm", "Accept-Charset", "Foo-Bar")); + } + }); + + String rawResponse = _connector.getResponse( + """ + GET / HTTP/1.1 + Host: local + Connection: close + Accept: */* + RaNdOm: value + Accept-Charset: UTF-8 + accept-charset: UTF-16 + Foo-Bar: one + foo-bar: two + + """); + HttpTester.Response response = HttpTester.parseResponse(rawResponse); + assertThat(response.getStatus(), is(HttpStatus.OK_200)); + } + @Test public void testIsSecure() throws Exception { From eafa7ab0d6d3ce3361dd8e5526ae4633af25aec1 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 23 May 2024 06:45:27 +1000 Subject: [PATCH 03/11] Fix #11756 empty byte array for no content in ChunkAccumulator (#11827) Fix #11756 empty byte array for no content in ChunkAccumulator --- .../src/main/java/org/eclipse/jetty/io/ChunkAccumulator.java | 2 +- .../src/main/java/org/eclipse/jetty/util/BufferUtil.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ChunkAccumulator.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ChunkAccumulator.java index 0358f8583969..c0c37eb34111 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ChunkAccumulator.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/ChunkAccumulator.java @@ -72,7 +72,7 @@ public int length() public byte[] take() { if (_length == 0) - return BufferUtil.EMPTY_BUFFER.array(); + return BufferUtil.EMPTY_BYTES; byte[] bytes = new byte[_length]; int offset = 0; for (Chunk chunk : _chunks) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java index 3d771910596d..82d39988bcd4 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/BufferUtil.java @@ -106,7 +106,8 @@ public class BufferUtil (byte)'E', (byte)'F' }; - public static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap(new byte[0]).asReadOnlyBuffer(); + public static final byte[] EMPTY_BYTES = new byte[0]; + public static final ByteBuffer EMPTY_BUFFER = ByteBuffer.wrap(EMPTY_BYTES).asReadOnlyBuffer(); /** * Allocate ByteBuffer in flush mode. From e0066a48bad4107ee75e162ce69b14b77a9ed698 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 23 May 2024 03:34:50 +0200 Subject: [PATCH 04/11] Issue #11791 fix suffix mapping for non default DefaultServlet usage. (#11799) * Issue #11791 fix suffix mapping for non default DefaultServlet usage. Co-authored-by: Greg Wilkins --- .../jetty/ee10/servlet/DefaultServlet.java | 12 ++++++++++- .../ee10/servlet/DefaultServletTest.java | 20 +++++++++++++++++++ .../src/test/resources/suffixroot/test.js | 1 + 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 jetty-ee10/jetty-ee10-servlet/src/test/resources/suffixroot/test.js diff --git a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java index 2c350c2f4772..7b1a0969bfff 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java +++ b/jetty-ee10/jetty-ee10-servlet/src/main/java/org/eclipse/jetty/ee10/servlet/DefaultServlet.java @@ -56,6 +56,7 @@ import org.eclipse.jetty.util.Blocker; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.ExceptionUtil; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resources; @@ -555,7 +556,16 @@ protected String getEncodedPathInContext(HttpServletRequest req, String included if (includedServletPath != null) return encodePath(getIncludedPathInContext(req, includedServletPath, !isDefaultMapping(req))); else if (!isDefaultMapping(req)) - return encodePath(req.getPathInfo()); + { + //a match via an extension mapping will more than likely + //have no path info + String path = req.getPathInfo(); + if (StringUtil.isEmpty(path) && + MappingMatch.EXTENSION.equals(req.getHttpServletMapping().getMappingMatch())) + path = req.getServletPath(); + + return encodePath(path); + } else if (req instanceof ServletApiRequest apiRequest) return Context.getPathInContext(req.getContextPath(), apiRequest.getRequest().getHttpURI().getCanonicalPath()); else diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java index 554bce24f1dd..c8b3e4c889c6 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/DefaultServletTest.java @@ -3487,6 +3487,26 @@ protected void service(HttpServletRequest req, HttpServletResponse resp) throws assertThat(response.getContent(), containsString("testPathInfoOnly-OK")); } + @Test + public void testSuffixMappings() throws Exception + { + server.stop(); + + Path suffixroot = MavenTestingUtils.getTestResourcePath("suffixroot"); + ResourceFactory resourceFactory = ResourceFactory.of(context); + context.setBaseResource(resourceFactory.newResource(suffixroot.toUri())); + + ServletHolder holderAlt = new ServletHolder("static-js", DefaultServlet.class); + context.addServlet(holderAlt, "*.js"); + ServletHolder holderDef = new ServletHolder("default", DefaultServlet.class); + holderDef.setInitParameter("dirAllowed", "true"); + context.addServlet(holderDef, "/"); + + server.start(); + String rawResponse = connector.getResponse("GET /context/test.js HTTP/1.0\r\n\r\n"); + assertThat(rawResponse, containsString("Hello")); + } + @Test public void testMemoryResourceRange() throws Exception { diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/resources/suffixroot/test.js b/jetty-ee10/jetty-ee10-servlet/src/test/resources/suffixroot/test.js new file mode 100644 index 000000000000..08268dffc00a --- /dev/null +++ b/jetty-ee10/jetty-ee10-servlet/src/test/resources/suffixroot/test.js @@ -0,0 +1 @@ +document.write("Hello"); From 456fd8020a1410d31d53690234828a12208479e4 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 23 May 2024 14:48:32 +1000 Subject: [PATCH 05/11] removed unused resources (#11830) --- .../src/main/resources/jetty-dir.css | 49 ------------------ .../resources/org/eclipse/nested/favicon.ico | Bin 1150 -> 0 bytes 2 files changed, 49 deletions(-) delete mode 100644 jetty-ee9/jetty-ee9-nested/src/main/resources/jetty-dir.css delete mode 100644 jetty-ee9/jetty-ee9-nested/src/main/resources/org/eclipse/nested/favicon.ico diff --git a/jetty-ee9/jetty-ee9-nested/src/main/resources/jetty-dir.css b/jetty-ee9/jetty-ee9-nested/src/main/resources/jetty-dir.css deleted file mode 100644 index cbcc88d91ae5..000000000000 --- a/jetty-ee9/jetty-ee9-nested/src/main/resources/jetty-dir.css +++ /dev/null @@ -1,49 +0,0 @@ -body { - background-color: #FFFFFF; - margin: 10px; - padding: 5px; - font-family: sans-serif; -} - -h1.title { - text-shadow: #000000 -1px -1px 1px; - color: #FC390E; - font-weight: bold; -} - -table.listing { - border: 0px; -} - -thead a { - color: blue; -} - -thead th { - border-bottom: black 1px solid; -} - -.name, .lastmodified { - text-align: left; - padding-right: 15px; -} - -.size { - text-align: right; -} - -a { - color: #7036be; - font-weight: bold; - font-style: normal; - text-decoration: none; - font-size:inherit; -} - -td { - font-style: italic; - padding: 2px; -} - - - diff --git a/jetty-ee9/jetty-ee9-nested/src/main/resources/org/eclipse/nested/favicon.ico b/jetty-ee9/jetty-ee9-nested/src/main/resources/org/eclipse/nested/favicon.ico deleted file mode 100644 index ea9e174b48b0130d4294813a6b5d487f35b436cc..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1150 zcmbtT*-leY6um|h48jdk3$&%Q(B4i^j0|O{SS`gNpioe>$}E$@lZJ1QNB+PF^2Rq1 z-~0si(Ki_^w7s|RV6t5MRE#FRd7IU<_sLm%SZ5ziJI7yDmBxRswtPX;YBWs?5!~WV zX`jnKzth8Su;vVy6F!(zey)BLp7>CB>W4KOr0qw3w28if>`f;Q+U+p8Z%!Bx?#XHx z){FsbAqZ=}v|o5k{<>)7Pyike?g%;$(&VSpzKYFT`wR zDrX^M;CRr3qk($tMJ~gfG?=p)=1f4>OZ>eMmFKZ z{#6_645KLgIrf(Ep}0){MOd9rM%JLm7=wuWGDy2FVWh5HVfe~LjL`pd&kbuajQk^N z@{D>BMfSbkW<%5whu%d#k%;ZURdyb!Ya7ZI-%;ttJJuxJLz0cWW_*%td~zN%2=2D-ky` z(BtG2iSC_JOXHW6$^Qk_6M1L8#NWE%;LLH} zWIj0`Qp53(2ibm?;-@;O`5*Ztr|<+(CpGA+Q$34j#g!J$e~9zt#$j(AUOLK=Y~>vE zu?9lyH@sWXP4aHWYq5K$p7{f?rUNjigPh|g$c%mOb6~yGu6q2P&lSgd%&yLxlcl$% z^3Jn=&e49e4f|0W4m)dTSK~8hVtc3o?+0Ai>UUzBcl=?*!x|+Q-zjIsoMPQ_f7DOj qU^eMe?`tnuMcawfS5dwZz6;KEaVb>dF}Ls}x8hTO;ZooK`hEgZQ79q+ From 36cdc12ab7216c7cb664a60c63462afb3463a02c Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 22 May 2024 12:18:12 +0200 Subject: [PATCH 06/11] Fixed JPMS declarations. Some require transitive was missing, and has been added. In other cases, making a field private (e.g. for log instances) made the warning go away. In another case, removed explicit dependency on websocket core exception, as it was not necessary. Clean up the POMs for jetty-eeN-annotations, that had unnecessary dependencies. Signed-off-by: Simone Bordet --- .../jetty-deploy/src/main/java/module-info.java | 2 +- .../java/org/eclipse/jetty/http/CookieCache.java | 7 ++----- .../java/org/eclipse/jetty/http/CookieCutter.java | 2 +- .../java/org/eclipse/jetty/http/HttpParser.java | 2 +- .../eclipse/jetty/http/RFC6265CookieParser.java | 4 ---- .../org/eclipse/jetty/io/SelectorManager.java | 2 +- .../jetty-plus/src/main/java/module-info.java | 4 ++-- .../jetty-security/src/main/java/module-info.java | 2 +- .../eclipse/jetty/server/HttpConnectionTest.java | 6 +++--- .../jetty-session/src/main/java/module-info.java | 2 +- .../jetty-util/src/main/java/module-info.java | 2 +- .../org/eclipse/jetty/util/Utf8StringBuilder.java | 2 +- .../jetty/util/preventers/AWTLeakPreventer.java | 1 - .../util/preventers/AbstractLeakPreventer.java | 2 +- .../util/preventers/AppContextLeakPreventer.java | 1 - .../preventers/DriverManagerLeakPreventer.java | 1 - .../server/ServerWebSocketContainer.java | 4 ++-- jetty-ee10/jetty-ee10-annotations/pom.xml | 15 --------------- .../src/main/java/module-info.java | 4 ++-- .../src/main/java/module-info.java | 2 +- .../src/main/java/module-info.java | 4 ++-- .../eclipse/jetty/ee10/plus/jndi/Transaction.java | 4 ---- .../src/main/java/module-info.java | 2 +- .../src/main/java/module-info.java | 2 +- jetty-ee8/jetty-ee8-annotations/pom.xml | 5 ----- jetty-ee9/jetty-ee9-annotations/pom.xml | 5 ----- .../src/main/java/module-info.java | 4 ++-- .../jetty-ee9-jndi/src/main/java/module-info.java | 2 +- .../jetty-ee9-plus/src/main/java/module-info.java | 2 +- .../src/main/java/module-info.java | 2 +- 30 files changed, 30 insertions(+), 69 deletions(-) diff --git a/jetty-core/jetty-deploy/src/main/java/module-info.java b/jetty-core/jetty-deploy/src/main/java/module-info.java index 716c4213c236..73f5f3bb3e1b 100644 --- a/jetty-core/jetty-deploy/src/main/java/module-info.java +++ b/jetty-core/jetty-deploy/src/main/java/module-info.java @@ -15,7 +15,7 @@ { requires java.xml; requires org.eclipse.jetty.xml; - requires org.eclipse.jetty.server; + requires transitive org.eclipse.jetty.server; requires org.slf4j; // Only required if using JMX. diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCache.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCache.java index e7799d783dfb..4441d0830925 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCache.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCache.java @@ -21,8 +21,6 @@ import java.util.Map; import org.eclipse.jetty.util.StringUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Cookie parser @@ -31,9 +29,8 @@ @Deprecated (forRemoval = true) public class CookieCache implements CookieParser.Handler, ComplianceViolation.Listener { - protected static final Logger LOG = LoggerFactory.getLogger(CookieCache.class); - protected final List _rawFields = new ArrayList<>(); - protected List _cookieList; + private final List _rawFields = new ArrayList<>(); + private List _cookieList; private final CookieParser _parser; private List _violations; diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCutter.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCutter.java index b81ceef8258b..38bb55e87855 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCutter.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/CookieCutter.java @@ -33,7 +33,7 @@ @Deprecated public class CookieCutter implements CookieParser { - protected static final Logger LOG = LoggerFactory.getLogger(CookieCutter.class); + private static final Logger LOG = LoggerFactory.getLogger(CookieCutter.class); private final CookieParser.Handler _handler; private final CookieCompliance _complianceMode; diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java index ef1ba9f61da5..93be3478cb01 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/HttpParser.java @@ -92,7 +92,7 @@ */ public class HttpParser { - public static final Logger LOG = LoggerFactory.getLogger(HttpParser.class); + private static final Logger LOG = LoggerFactory.getLogger(HttpParser.class); public static final int INITIAL_URI_LENGTH = 256; private static final int MAX_CHUNK_LENGTH = Integer.MAX_VALUE / 16 - 16; private static final String UNMATCHED_VALUE = "\u0000"; diff --git a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/RFC6265CookieParser.java b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/RFC6265CookieParser.java index e64856a70233..8b54d16b0bc5 100644 --- a/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/RFC6265CookieParser.java +++ b/jetty-core/jetty-http/src/main/java/org/eclipse/jetty/http/RFC6265CookieParser.java @@ -16,8 +16,6 @@ import java.util.Locale; import org.eclipse.jetty.util.StringUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import static org.eclipse.jetty.http.CookieCompliance.Violation.ATTRIBUTES; import static org.eclipse.jetty.http.CookieCompliance.Violation.ATTRIBUTE_VALUES; @@ -34,8 +32,6 @@ */ public class RFC6265CookieParser implements CookieParser { - protected static final Logger LOG = LoggerFactory.getLogger(RFC6265CookieParser.class); - private final CookieParser.Handler _handler; private final CookieCompliance _complianceMode; private final ComplianceViolation.Listener _complianceListener; diff --git a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java index fab730916228..157cd4a3eca5 100644 --- a/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java +++ b/jetty-core/jetty-io/src/main/java/org/eclipse/jetty/io/SelectorManager.java @@ -53,7 +53,7 @@ public abstract class SelectorManager extends ContainerLifeCycle implements Dumpable { public static final int DEFAULT_CONNECT_TIMEOUT = 15000; - protected static final Logger LOG = LoggerFactory.getLogger(SelectorManager.class); + private static final Logger LOG = LoggerFactory.getLogger(SelectorManager.class); private final Executor executor; private final Scheduler scheduler; diff --git a/jetty-core/jetty-plus/src/main/java/module-info.java b/jetty-core/jetty-plus/src/main/java/module-info.java index 2d4517de1724..2f4980985c23 100644 --- a/jetty-core/jetty-plus/src/main/java/module-info.java +++ b/jetty-core/jetty-plus/src/main/java/module-info.java @@ -13,13 +13,13 @@ module org.eclipse.jetty.plus { - requires org.eclipse.jetty.security; + requires transitive org.eclipse.jetty.security; requires org.eclipse.jetty.util; requires org.slf4j; requires transitive java.naming; // Only required if using DataSourceLoginService. - requires static java.sql; + requires static transitive java.sql; exports org.eclipse.jetty.plus.annotation; exports org.eclipse.jetty.plus.jndi; diff --git a/jetty-core/jetty-security/src/main/java/module-info.java b/jetty-core/jetty-security/src/main/java/module-info.java index 196434d475ec..41c65cd694a4 100644 --- a/jetty-core/jetty-security/src/main/java/module-info.java +++ b/jetty-core/jetty-security/src/main/java/module-info.java @@ -17,7 +17,7 @@ requires transitive org.eclipse.jetty.util; requires transitive org.slf4j; requires static java.security.jgss; - requires static java.sql; + requires static transitive java.sql; exports org.eclipse.jetty.security; exports org.eclipse.jetty.security.authentication; diff --git a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index 885bc213560c..cef0156fddca 100644 --- a/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-core/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -251,7 +251,7 @@ public static Stream contentLengths() @MethodSource("contentLengths") public void testHttp11MultipleContentLength(int[] clen) throws Exception { - HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED..."); + LOG.info("badMessage: 400 Bad messages EXPECTED..."); StringBuilder request = new StringBuilder(); request.append("POST / HTTP/1.1\r\n"); request.append("Host: local\r\n"); @@ -298,7 +298,7 @@ public static Stream http11ContentLengthAndChunkedData() @MethodSource("http11ContentLengthAndChunkedData") public void testHttp11ContentLengthAndChunk(int[] contentLengths) throws Exception { - HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED..."); + LOG.info("badMessage: 400 Bad messages EXPECTED..."); StringBuilder request = new StringBuilder(); request.append("POST / HTTP/1.1\r\n"); @@ -405,7 +405,7 @@ public static Stream http11TransferEncodingInvalidChunked() @MethodSource("http11TransferEncodingInvalidChunked") public void testHttp11TransferEncodingInvalidChunked(List tokens) throws Exception { - HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED..."); + LOG.info("badMessage: 400 Bad messages EXPECTED..."); StringBuilder request = new StringBuilder(); request.append("POST / HTTP/1.1\r\n"); request.append("Host: local\r\n"); diff --git a/jetty-core/jetty-session/src/main/java/module-info.java b/jetty-core/jetty-session/src/main/java/module-info.java index 4aa53da31bbe..6fe9df07406c 100644 --- a/jetty-core/jetty-session/src/main/java/module-info.java +++ b/jetty-core/jetty-session/src/main/java/module-info.java @@ -18,7 +18,7 @@ requires transitive org.slf4j; // Only required if using DatabaseAdaptor/JDBCSessionDataStore. - requires static java.sql; + requires static transitive java.sql; requires static java.naming; exports org.eclipse.jetty.session; diff --git a/jetty-core/jetty-util/src/main/java/module-info.java b/jetty-core/jetty-util/src/main/java/module-info.java index 470d3f8394c6..f84729d200f3 100644 --- a/jetty-core/jetty-util/src/main/java/module-info.java +++ b/jetty-core/jetty-util/src/main/java/module-info.java @@ -14,7 +14,7 @@ module org.eclipse.jetty.util { // Standard Jetty Logging now. - requires org.slf4j; + requires transitive org.slf4j; // Required by SSL code (for X509). requires transitive java.naming; diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8StringBuilder.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8StringBuilder.java index 77c17b673ffe..90a0dbe17c60 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8StringBuilder.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Utf8StringBuilder.java @@ -41,7 +41,7 @@ */ public class Utf8StringBuilder implements CharsetStringBuilder { - protected static final Logger LOG = LoggerFactory.getLogger(Utf8StringBuilder.class); + private static final Logger LOG = LoggerFactory.getLogger(Utf8StringBuilder.class); public static final char REPLACEMENT = '�'; private static final int UTF8_ACCEPT = 0; private static final int UTF8_REJECT = 12; diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AWTLeakPreventer.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AWTLeakPreventer.java index 2647f30e1a2b..b35f71f8067e 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AWTLeakPreventer.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AWTLeakPreventer.java @@ -26,7 +26,6 @@ */ public class AWTLeakPreventer extends AbstractLeakPreventer { - @Override public void prevent(ClassLoader loader) { diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AbstractLeakPreventer.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AbstractLeakPreventer.java index d57f175ce2b2..38b366cc8406 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AbstractLeakPreventer.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AbstractLeakPreventer.java @@ -30,7 +30,7 @@ */ public abstract class AbstractLeakPreventer extends AbstractLifeCycle { - protected static final Logger LOG = LoggerFactory.getLogger(AbstractLeakPreventer.class); + static final Logger LOG = LoggerFactory.getLogger(AbstractLeakPreventer.class); public abstract void prevent(ClassLoader loader); diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AppContextLeakPreventer.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AppContextLeakPreventer.java index 4453c77a55da..edee3211d20a 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AppContextLeakPreventer.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/AppContextLeakPreventer.java @@ -25,7 +25,6 @@ */ public class AppContextLeakPreventer extends AbstractLeakPreventer { - @Override public void prevent(ClassLoader loader) { diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/DriverManagerLeakPreventer.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/DriverManagerLeakPreventer.java index c6d9a71ff413..6682f5748053 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/DriverManagerLeakPreventer.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/preventers/DriverManagerLeakPreventer.java @@ -24,7 +24,6 @@ */ public class DriverManagerLeakPreventer extends AbstractLeakPreventer { - @Override public void prevent(ClassLoader loader) { diff --git a/jetty-core/jetty-websocket/jetty-websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/ServerWebSocketContainer.java b/jetty-core/jetty-websocket/jetty-websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/ServerWebSocketContainer.java index 12b23489b02f..cf8a1755fad3 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/ServerWebSocketContainer.java +++ b/jetty-core/jetty-websocket/jetty-websocket-jetty-server/src/main/java/org/eclipse/jetty/websocket/server/ServerWebSocketContainer.java @@ -322,7 +322,7 @@ public void addMapping(PathSpec pathSpec, WebSocketCreator creator) * @see #upgrade(WebSocketCreator, Request, Response, Callback) */ @Override - public boolean handle(Request request, Response response, Callback callback) throws WebSocketException + public boolean handle(Request request, Response response, Callback callback) { return mappings.upgrade(request, response, callback, configuration); } @@ -346,7 +346,7 @@ public boolean handle(Request request, Response response, Callback callback) thr * @throws WebSocketException there is an error during the upgrade * @see #handle(Request, Response, Callback) */ - public boolean upgrade(WebSocketCreator creator, Request request, Response response, Callback callback) throws WebSocketException + public boolean upgrade(WebSocketCreator creator, Request request, Response response, Callback callback) { var coreCreator = newWebSocketCreator(creator); WebSocketNegotiator negotiator = WebSocketNegotiator.from(coreCreator, factory); diff --git a/jetty-ee10/jetty-ee10-annotations/pom.xml b/jetty-ee10/jetty-ee10-annotations/pom.xml index 34d5b1e214fc..1ba90c083ce0 100644 --- a/jetty-ee10/jetty-ee10-annotations/pom.xml +++ b/jetty-ee10/jetty-ee10-annotations/pom.xml @@ -44,21 +44,6 @@ org.slf4j slf4j-api - - jakarta.enterprise - jakarta.enterprise.cdi-api - test - - - jakarta.interceptor - jakarta.interceptor-api - test - - - jakarta.transaction - jakarta.transaction-api - test - org.eclipse.jetty jetty-slf4j-impl diff --git a/jetty-ee10/jetty-ee10-apache-jsp/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-apache-jsp/src/main/java/module-info.java index 0ebafec01bde..374b985e9cbd 100644 --- a/jetty-ee10/jetty-ee10-apache-jsp/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-apache-jsp/src/main/java/module-info.java @@ -14,9 +14,9 @@ module org.eclipse.jetty.ee10.apache.jsp { requires java.xml; - requires jakarta.servlet; + requires transitive jakarta.servlet; requires org.eclipse.jetty.util; - requires org.mortbay.apache.jasper; + requires transitive org.mortbay.apache.jasper; requires org.slf4j; exports org.eclipse.jetty.ee10.apache.jsp; diff --git a/jetty-ee10/jetty-ee10-jndi/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-jndi/src/main/java/module-info.java index bfeae887a918..e16b10ff709e 100644 --- a/jetty-ee10/jetty-ee10-jndi/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-jndi/src/main/java/module-info.java @@ -19,7 +19,7 @@ requires transitive java.naming; // Only required if using MailSessionReference. - requires static jakarta.mail; + requires static transitive jakarta.mail; exports org.eclipse.jetty.ee10.jndi.factories; } diff --git a/jetty-ee10/jetty-ee10-plus/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-plus/src/main/java/module-info.java index 06e2c7ddf6bf..d4fc7b583129 100644 --- a/jetty-ee10/jetty-ee10-plus/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-plus/src/main/java/module-info.java @@ -16,13 +16,13 @@ module org.eclipse.jetty.ee10.plus { - requires org.eclipse.jetty.plus; + requires transitive org.eclipse.jetty.plus; requires org.slf4j; requires transitive org.eclipse.jetty.ee10.webapp; // Only required if using Transaction. - requires static jakarta.transaction; + requires static transitive jakarta.transaction; exports org.eclipse.jetty.ee10.plus.jndi; exports org.eclipse.jetty.ee10.plus.webapp; diff --git a/jetty-ee10/jetty-ee10-plus/src/main/java/org/eclipse/jetty/ee10/plus/jndi/Transaction.java b/jetty-ee10/jetty-ee10-plus/src/main/java/org/eclipse/jetty/ee10/plus/jndi/Transaction.java index 5b1fa5a9b265..81955962de3b 100644 --- a/jetty-ee10/jetty-ee10-plus/src/main/java/org/eclipse/jetty/ee10/plus/jndi/Transaction.java +++ b/jetty-ee10/jetty-ee10-plus/src/main/java/org/eclipse/jetty/ee10/plus/jndi/Transaction.java @@ -16,8 +16,6 @@ import javax.naming.NamingException; import jakarta.transaction.UserTransaction; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; /** * Transaction @@ -26,8 +24,6 @@ */ public class Transaction extends org.eclipse.jetty.plus.jndi.Transaction { - private static final Logger LOG = LoggerFactory.getLogger(Transaction.class); - /** * @param scope the scope, usually an environment like ee9, ee10 * @param userTransaction the UserTransaction diff --git a/jetty-ee10/jetty-ee10-proxy/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-proxy/src/main/java/module-info.java index c21390fcd8cb..2daec578a0c0 100644 --- a/jetty-ee10/jetty-ee10-proxy/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-proxy/src/main/java/module-info.java @@ -13,7 +13,7 @@ module org.eclipse.jetty.ee10.proxy { - requires jakarta.servlet; + requires transitive jakarta.servlet; requires transitive org.eclipse.jetty.client; requires transitive org.eclipse.jetty.server; requires transitive org.slf4j; diff --git a/jetty-ee10/jetty-ee10-servlets/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-servlets/src/main/java/module-info.java index 2a13da07a538..4f8695470bea 100644 --- a/jetty-ee10/jetty-ee10-servlets/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-servlets/src/main/java/module-info.java @@ -26,7 +26,7 @@ requires static org.eclipse.jetty.http; requires static org.eclipse.jetty.server; // Only required if using CrossOriginFilter, DoSFilter, etc. - requires static org.eclipse.jetty.util; + requires static transitive org.eclipse.jetty.util; exports org.eclipse.jetty.ee10.servlets; } diff --git a/jetty-ee8/jetty-ee8-annotations/pom.xml b/jetty-ee8/jetty-ee8-annotations/pom.xml index 76ac2d4b8403..31538429ed1f 100644 --- a/jetty-ee8/jetty-ee8-annotations/pom.xml +++ b/jetty-ee8/jetty-ee8-annotations/pom.xml @@ -49,11 +49,6 @@ org.slf4j slf4j-api - - jakarta.transaction - jakarta.transaction-api - test - org.eclipse.jetty jetty-slf4j-impl diff --git a/jetty-ee9/jetty-ee9-annotations/pom.xml b/jetty-ee9/jetty-ee9-annotations/pom.xml index c5fb5e7d1467..ca153fab5c1c 100644 --- a/jetty-ee9/jetty-ee9-annotations/pom.xml +++ b/jetty-ee9/jetty-ee9-annotations/pom.xml @@ -48,11 +48,6 @@ org.slf4j slf4j-api - - jakarta.transaction - jakarta.transaction-api - test - org.eclipse.jetty jetty-slf4j-impl diff --git a/jetty-ee9/jetty-ee9-apache-jsp/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-apache-jsp/src/main/java/module-info.java index 30b202638e3f..12488a568d05 100644 --- a/jetty-ee9/jetty-ee9-apache-jsp/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-apache-jsp/src/main/java/module-info.java @@ -14,9 +14,9 @@ module org.eclipse.jetty.ee9.apache.jsp { requires java.xml; - requires jetty.servlet.api; + requires transitive jetty.servlet.api; requires org.eclipse.jetty.util; - requires org.mortbay.apache.jasper; + requires transitive org.mortbay.apache.jasper; requires org.slf4j; exports org.eclipse.jetty.ee9.apache.jsp; diff --git a/jetty-ee9/jetty-ee9-jndi/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-jndi/src/main/java/module-info.java index 390544350cff..994e28ce0f9b 100644 --- a/jetty-ee9/jetty-ee9-jndi/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-jndi/src/main/java/module-info.java @@ -19,7 +19,7 @@ requires transitive java.naming; // Only required if using MailSessionReference. - requires static jakarta.mail; + requires static transitive jakarta.mail; exports org.eclipse.jetty.ee9.jndi.factories; } diff --git a/jetty-ee9/jetty-ee9-plus/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-plus/src/main/java/module-info.java index 779305bf2cdb..98ddffbfac05 100644 --- a/jetty-ee9/jetty-ee9-plus/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-plus/src/main/java/module-info.java @@ -23,7 +23,7 @@ requires transitive org.eclipse.jetty.plus; // Only required if using Transaction. - requires static jakarta.transaction; + requires static transitive jakarta.transaction; exports org.eclipse.jetty.ee9.plus.jndi; exports org.eclipse.jetty.ee9.plus.webapp; diff --git a/jetty-ee9/jetty-ee9-servlets/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-servlets/src/main/java/module-info.java index 8284e687c415..c52b27b022de 100644 --- a/jetty-ee9/jetty-ee9-servlets/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-servlets/src/main/java/module-info.java @@ -26,7 +26,7 @@ requires static org.eclipse.jetty.http; requires static org.eclipse.jetty.server; // Only required if using CrossOriginFilter, DoSFilter, etc. - requires static org.eclipse.jetty.util; + requires static transitive org.eclipse.jetty.util; // Only required if using DataRateLimitedServlet requires static org.eclipse.jetty.ee9.nested; From be7491e13aba27257d3235c782bb5a1286e8831b Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 22 May 2024 17:17:46 +0200 Subject: [PATCH 07/11] Sometimes it happens that some process is listening to `connector.getLocalPort() + 1`, making this test fail. Now using a non-allocated privileged port from IANA, that nobody should listen to, so the test should not fail. It is not a 100% guarantee, but perhaps better than before, especially because now a port < 1024 is used. Signed-off-by: Simone Bordet --- .../jetty/ee10/websocket/tests/WebSocketOverHTTP2Test.java | 5 ++++- .../jetty/ee9/websocket/tests/WebSocketOverHTTP2Test.java | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee10/websocket/tests/WebSocketOverHTTP2Test.java b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee10/websocket/tests/WebSocketOverHTTP2Test.java index 755b4a1889cb..aeb66214d3d2 100644 --- a/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee10/websocket/tests/WebSocketOverHTTP2Test.java +++ b/jetty-ee10/jetty-ee10-websocket/jetty-ee10-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee10/websocket/tests/WebSocketOverHTTP2Test.java @@ -264,8 +264,11 @@ public void testWebSocketConnectPortDoesNotExist() throws Exception startServer(); startClient(clientConnector -> new ClientConnectionFactoryOverHTTP2.HTTP2(new HTTP2Client(clientConnector))); + // Port 293 is not assigned by IANA, so + // it should be impossible to connect. + int nonExistingPort = 293; EventSocket wsEndPoint = new EventSocket(); - URI uri = URI.create("ws://localhost:" + (connector.getLocalPort() + 1) + "/ws/echo"); + URI uri = URI.create("ws://localhost:" + nonExistingPort + "/ws/echo"); ExecutionException failure = Assertions.assertThrows(ExecutionException.class, () -> wsClient.connect(wsEndPoint, uri).get(5, TimeUnit.SECONDS)); diff --git a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee9/websocket/tests/WebSocketOverHTTP2Test.java b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee9/websocket/tests/WebSocketOverHTTP2Test.java index 11478c9d5cc9..dc5a00b6e7c7 100644 --- a/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee9/websocket/tests/WebSocketOverHTTP2Test.java +++ b/jetty-ee9/jetty-ee9-websocket/jetty-ee9-websocket-jetty-tests/src/test/java/org/eclipse/jetty/ee9/websocket/tests/WebSocketOverHTTP2Test.java @@ -248,8 +248,11 @@ public void testWebSocketConnectPortDoesNotExist() throws Exception startServer(); startClient(clientConnector -> new ClientConnectionFactoryOverHTTP2.HTTP2(new HTTP2Client(clientConnector))); + // Port 293 is not assigned by IANA, so + // it should be impossible to connect. + int nonExistingPort = 293; EventSocket wsEndPoint = new EventSocket(); - URI uri = URI.create("ws://localhost:" + (connector.getLocalPort() + 1) + "/ws/echo"); + URI uri = URI.create("ws://localhost:" + nonExistingPort + "/ws/echo"); ExecutionException failure = Assertions.assertThrows(ExecutionException.class, () -> wsClient.connect(wsEndPoint, uri).get(5, TimeUnit.SECONDS)); From b16460252f4c0c4d73b14787bca0704ceaedc022 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 23 May 2024 23:31:30 +0200 Subject: [PATCH 08/11] Disable cache antora as it looks to have some bugs with forking lifecycle (#11835) Signed-off-by: Olivier Lamy --- documentation/jetty/pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/documentation/jetty/pom.xml b/documentation/jetty/pom.xml index 657601753fb7..bbe60069a0ad 100644 --- a/documentation/jetty/pom.xml +++ b/documentation/jetty/pom.xml @@ -12,8 +12,8 @@ Documentation :: Content Root - - true + + false From 65a016d1aa9a78b04be2d1ab707319125ece7d57 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 24 May 2024 15:46:09 +0200 Subject: [PATCH 09/11] Fixes #11778 - jetty-http-spi does not properly provide SPI for modules. Fixed all module-info.java files that did not have a "provides" declaration but had META-INF/services files. Signed-off-by: Simone Bordet --- .../jetty-http-spi/src/main/java/module-info.java | 7 ++++++- .../src/main/java/module-info.java | 3 ++- .../org.eclipse.jetty.websocket.core.Extension | 4 ++-- .../jetty-ee10-cdi/src/main/java/module-info.java | 10 +++++++++- .../org.eclipse.jetty.ee10.webapp.Configuration | 2 +- .../src/main/java/module-info.java | 6 ++++++ .../jakarta.servlet.ServletContainerInitializer | 2 +- .../org.eclipse.jetty.ee10.webapp.Configuration | 2 +- jetty-ee9/jetty-ee9-cdi/src/main/java/module-info.java | 10 +++++++++- .../org.eclipse.jetty.ee9.webapp.Configuration | 2 +- .../src/main/java/module-info.java | 6 ++++++ .../jakarta.servlet.ServletContainerInitializer | 2 +- .../jakarta.servlet.ServletContainerInitializer | 1 - .../org.eclipse.jetty.ee9.webapp.Configuration | 2 +- 14 files changed, 46 insertions(+), 13 deletions(-) delete mode 100644 jetty-ee9/jetty-ee9-tests/jetty-ee9-test-owb-cdi-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer diff --git a/jetty-core/jetty-http-spi/src/main/java/module-info.java b/jetty-core/jetty-http-spi/src/main/java/module-info.java index 6eec599bee8c..67f042747231 100644 --- a/jetty-core/jetty-http-spi/src/main/java/module-info.java +++ b/jetty-core/jetty-http-spi/src/main/java/module-info.java @@ -11,6 +11,9 @@ // ======================================================================== // +import com.sun.net.httpserver.spi.HttpServerProvider; +import org.eclipse.jetty.http.spi.JettyHttpServerProvider; + module org.eclipse.jetty.http.spi { requires transitive jdk.httpserver; @@ -19,4 +22,6 @@ requires transitive org.eclipse.jetty.util; exports org.eclipse.jetty.http.spi; -} \ No newline at end of file + + provides HttpServerProvider with JettyHttpServerProvider; +} diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/module-info.java b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/module-info.java index 5ddbcffdb6c6..274c29030efa 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/module-info.java +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/java/module-info.java @@ -27,9 +27,10 @@ org.eclipse.jetty.util; // Export to DecoratedObjectFactory. uses org.eclipse.jetty.websocket.core.Extension; - + provides org.eclipse.jetty.websocket.core.Extension with org.eclipse.jetty.websocket.core.internal.FragmentExtension, + org.eclipse.jetty.websocket.core.internal.FrameCaptureExtension, org.eclipse.jetty.websocket.core.internal.IdentityExtension, org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension, org.eclipse.jetty.websocket.core.internal.ValidationExtension; diff --git a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.core.Extension b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.core.Extension index 1e4404b3a0db..41f688cf2de0 100644 --- a/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.core.Extension +++ b/jetty-core/jetty-websocket/jetty-websocket-core-common/src/main/resources/META-INF/services/org.eclipse.jetty.websocket.core.Extension @@ -1,5 +1,5 @@ -org.eclipse.jetty.websocket.core.internal.IdentityExtension org.eclipse.jetty.websocket.core.internal.FragmentExtension +org.eclipse.jetty.websocket.core.internal.FrameCaptureExtension +org.eclipse.jetty.websocket.core.internal.IdentityExtension org.eclipse.jetty.websocket.core.internal.PerMessageDeflateExtension org.eclipse.jetty.websocket.core.internal.ValidationExtension -org.eclipse.jetty.websocket.core.internal.FrameCaptureExtension \ No newline at end of file diff --git a/jetty-ee10/jetty-ee10-cdi/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-cdi/src/main/java/module-info.java index 83bfa59c8c47..34c4213ea824 100644 --- a/jetty-ee10/jetty-ee10-cdi/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-cdi/src/main/java/module-info.java @@ -11,6 +11,11 @@ // ======================================================================== // +import jakarta.servlet.ServletContainerInitializer; +import org.eclipse.jetty.ee10.cdi.CdiConfiguration; +import org.eclipse.jetty.ee10.cdi.CdiServletContainerInitializer; +import org.eclipse.jetty.ee10.webapp.Configuration; + module org.eclipse.jetty.ee10.cdi { requires org.eclipse.jetty.ee10.annotations; @@ -19,4 +24,7 @@ requires transitive org.eclipse.jetty.ee10.webapp; exports org.eclipse.jetty.ee10.cdi; -} + + provides ServletContainerInitializer with CdiServletContainerInitializer; + provides Configuration with CdiConfiguration; +} diff --git a/jetty-ee10/jetty-ee10-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration b/jetty-ee10/jetty-ee10-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration index c5893f79068e..9b80e44d9504 100644 --- a/jetty-ee10/jetty-ee10-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration +++ b/jetty-ee10/jetty-ee10-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration @@ -1,2 +1,2 @@ -org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration +org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration diff --git a/jetty-ee10/jetty-ee10-quickstart/src/main/java/module-info.java b/jetty-ee10/jetty-ee10-quickstart/src/main/java/module-info.java index 3082e7122e39..daf2baf981f2 100644 --- a/jetty-ee10/jetty-ee10-quickstart/src/main/java/module-info.java +++ b/jetty-ee10/jetty-ee10-quickstart/src/main/java/module-info.java @@ -11,6 +11,10 @@ // ======================================================================== // +import org.eclipse.jetty.ee10.quickstart.QuickStartConfiguration; +import org.eclipse.jetty.ee10.quickstart.QuickStartGeneratorConfiguration; +import org.eclipse.jetty.ee10.webapp.Configuration; + module org.eclipse.jetty.ee10.quickstart { requires jakarta.servlet; @@ -19,4 +23,6 @@ requires transitive org.eclipse.jetty.ee10.annotations; exports org.eclipse.jetty.ee10.quickstart; + + provides Configuration with QuickStartConfiguration, QuickStartGeneratorConfiguration; } diff --git a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-jmx/jetty-ee10-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-jmx/jetty-ee10-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer index 2e64dd7d038d..cb16405c7586 100644 --- a/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-jmx/jetty-ee10-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer +++ b/jetty-ee10/jetty-ee10-tests/jetty-ee10-test-jmx/jetty-ee10-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer @@ -1 +1 @@ -org.eclipse.jetty.test.jmx.MyContainerInitializer \ No newline at end of file +org.eclipse.jetty.ee10.test.jmx.MyContainerInitializer diff --git a/jetty-ee10/jetty-ee10-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration b/jetty-ee10/jetty-ee10-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration index ab84beb12126..da52678deb8c 100644 --- a/jetty-ee10/jetty-ee10-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration +++ b/jetty-ee10/jetty-ee10-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee10.webapp.Configuration @@ -1,7 +1,7 @@ org.eclipse.jetty.ee10.webapp.FragmentConfiguration -org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration org.eclipse.jetty.ee10.webapp.JaasConfiguration org.eclipse.jetty.ee10.webapp.JaspiConfiguration +org.eclipse.jetty.ee10.webapp.JettyWebXmlConfiguration org.eclipse.jetty.ee10.webapp.JmxConfiguration org.eclipse.jetty.ee10.webapp.JndiConfiguration org.eclipse.jetty.ee10.webapp.JspConfiguration diff --git a/jetty-ee9/jetty-ee9-cdi/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-cdi/src/main/java/module-info.java index 7aa0460d970b..af1561d44e62 100644 --- a/jetty-ee9/jetty-ee9-cdi/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-cdi/src/main/java/module-info.java @@ -11,6 +11,11 @@ // ======================================================================== // +import jakarta.servlet.ServletContainerInitializer; +import org.eclipse.jetty.ee9.cdi.CdiConfiguration; +import org.eclipse.jetty.ee9.cdi.CdiServletContainerInitializer; +import org.eclipse.jetty.ee9.webapp.Configuration; + module org.eclipse.jetty.ee9.cdi { requires org.eclipse.jetty.ee9.annotations; @@ -18,4 +23,7 @@ requires transitive org.eclipse.jetty.ee9.webapp; exports org.eclipse.jetty.ee9.cdi; -} + + provides ServletContainerInitializer with CdiServletContainerInitializer; + provides Configuration with CdiConfiguration; +} diff --git a/jetty-ee9/jetty-ee9-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration b/jetty-ee9/jetty-ee9-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration index 63e25a62acd9..66af95fc4c62 100644 --- a/jetty-ee9/jetty-ee9-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration +++ b/jetty-ee9/jetty-ee9-plus/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration @@ -1,2 +1,2 @@ -org.eclipse.jetty.ee9.plus.webapp.PlusConfiguration org.eclipse.jetty.ee9.plus.webapp.EnvConfiguration +org.eclipse.jetty.ee9.plus.webapp.PlusConfiguration diff --git a/jetty-ee9/jetty-ee9-quickstart/src/main/java/module-info.java b/jetty-ee9/jetty-ee9-quickstart/src/main/java/module-info.java index 473d170b13b6..67f1fc994711 100644 --- a/jetty-ee9/jetty-ee9-quickstart/src/main/java/module-info.java +++ b/jetty-ee9/jetty-ee9-quickstart/src/main/java/module-info.java @@ -11,6 +11,10 @@ // ======================================================================== // +import org.eclipse.jetty.ee9.quickstart.QuickStartConfiguration; +import org.eclipse.jetty.ee9.quickstart.QuickStartGeneratorConfiguration; +import org.eclipse.jetty.ee9.webapp.Configuration; + module org.eclipse.jetty.ee9.quickstart { requires jetty.servlet.api; @@ -19,4 +23,6 @@ requires transitive org.eclipse.jetty.ee9.annotations; exports org.eclipse.jetty.ee9.quickstart; + + provides Configuration with QuickStartConfiguration, QuickStartGeneratorConfiguration; } diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-jmx/jetty-ee9-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-jmx/jetty-ee9-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer index 2e64dd7d038d..7b155f99e0ea 100644 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-jmx/jetty-ee9-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer +++ b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-jmx/jetty-ee9-jmx-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer @@ -1 +1 @@ -org.eclipse.jetty.test.jmx.MyContainerInitializer \ No newline at end of file +org.eclipse.jetty.ee9.test.jmx.MyContainerInitializer diff --git a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-owb-cdi-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer b/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-owb-cdi-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer deleted file mode 100644 index f4906b1d3d97..000000000000 --- a/jetty-ee9/jetty-ee9-tests/jetty-ee9-test-owb-cdi-webapp/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.jetty.ee9.cdi.owb.OwbServletContainerInitializer \ No newline at end of file diff --git a/jetty-ee9/jetty-ee9-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration b/jetty-ee9/jetty-ee9-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration index 4bf4b020b439..937355a9e2e0 100644 --- a/jetty-ee9/jetty-ee9-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration +++ b/jetty-ee9/jetty-ee9-webapp/src/main/resources/META-INF/services/org.eclipse.jetty.ee9.webapp.Configuration @@ -1,7 +1,7 @@ org.eclipse.jetty.ee9.webapp.FragmentConfiguration -org.eclipse.jetty.ee9.webapp.JettyWebXmlConfiguration org.eclipse.jetty.ee9.webapp.JaasConfiguration org.eclipse.jetty.ee9.webapp.JaspiConfiguration +org.eclipse.jetty.ee9.webapp.JettyWebXmlConfiguration org.eclipse.jetty.ee9.webapp.JmxConfiguration org.eclipse.jetty.ee9.webapp.JndiConfiguration org.eclipse.jetty.ee9.webapp.JspConfiguration From e782f91ef20bf810a753cef223ccb57ba4e23ad5 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 24 May 2024 10:22:30 +0200 Subject: [PATCH 10/11] Fixes #1470 - Replace Timer use with Jetty Scheduler. Removed usages of the Timer class. Deprecated TimerScheduler. Code cleanup in ee10 classes. Signed-off-by: Simone Bordet --- .../jetty/util/thread/TimerScheduler.java | 5 +- .../src/main/java/org/example/Dump.java | 157 ++++++++---------- .../jetty/ee10/servlet/AsyncServletTest.java | 140 ++++++---------- .../src/main/java/org/example/Dump.java | 44 ++--- .../jetty/ee9/servlet/AsyncServletTest.java | 112 +++++-------- 5 files changed, 184 insertions(+), 274 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java index de0e0e459da1..2b731a039020 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/thread/TimerScheduler.java @@ -23,8 +23,11 @@ import org.slf4j.LoggerFactory; /** - * A scheduler based on the the JVM Timer class + * A scheduler based on the JVM {@link Timer} class. + * + * @deprecated use {@link ScheduledExecutorScheduler} instead. */ +@Deprecated(since = "12.0.9", forRemoval = true) public class TimerScheduler extends AbstractLifeCycle implements Scheduler, Runnable { private static final Logger LOG = LoggerFactory.getLogger(TimerScheduler.class); diff --git a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-jetty-webapp/src/main/java/org/example/Dump.java b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-jetty-webapp/src/main/java/org/example/Dump.java index a0fd721d813f..97165b207277 100644 --- a/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-jetty-webapp/src/main/java/org/example/Dump.java +++ b/jetty-ee10/jetty-ee10-demos/jetty-ee10-demo-jetty-webapp/src/main/java/org/example/Dump.java @@ -29,8 +29,9 @@ import java.util.Date; import java.util.Enumeration; import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; @@ -55,15 +56,15 @@ /** * Dump Servlet Request. */ -@SuppressWarnings("serial") public class Dump extends HttpServlet { /** * Zero Width Space, to allow text to be wrapped at designated spots */ private static final String ZWSP = "​"; - boolean fixed; - Timer _timer; + + private final ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); + private boolean fixed; @Override public void init(ServletConfig config) throws ServletException @@ -72,12 +73,9 @@ public void init(ServletConfig config) throws ServletException if (config.getInitParameter("unavailable") != null && !fixed) { - fixed = true; throw new UnavailableException("Unavailable test", Integer.parseInt(config.getInitParameter("unavailable"))); } - - _timer = new Timer(true); } @Override @@ -124,9 +122,9 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re final String chars = request.getParameter("chars"); final String block = request.getParameter("block"); final String dribble = request.getParameter("dribble"); - final boolean flush = request.getParameter("flush") != null ? Boolean.parseBoolean(request.getParameter("flush")) : false; + final boolean flush = request.getParameter("flush") != null && Boolean.parseBoolean(request.getParameter("flush")); - if (request.getPathInfo() != null && request.getPathInfo().toLowerCase(Locale.ENGLISH).indexOf("script") != -1) + if (request.getPathInfo() != null && request.getPathInfo().toLowerCase(Locale.ENGLISH).contains("script")) { response.sendRedirect(response.encodeRedirectURL(getServletContext().getContextPath() + "/dump/info")); return; @@ -139,6 +137,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re long end = System.currentTimeMillis() + Long.parseLong(request.getParameter("busy")); while (System.currentTimeMillis() < end) { + Thread.onSpinWait(); } } @@ -154,7 +153,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re try { long s = Long.parseLong(request.getParameter("sleep")); - if (request.getHeader("Expect") != null && request.getHeader("Expect").indexOf("102") >= 0) + if (request.getHeader("Expect") != null && request.getHeader("Expect").contains("102")) { Thread.sleep(s / 2); response.sendError(102); @@ -184,7 +183,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re { @Override - public void onTimeout(AsyncEvent event) throws IOException + public void onTimeout(AsyncEvent event) { response.addHeader("Dump", "onTimeout"); try @@ -203,19 +202,19 @@ public void onTimeout(AsyncEvent event) throws IOException } @Override - public void onStartAsync(AsyncEvent event) throws IOException + public void onStartAsync(AsyncEvent event) { response.addHeader("Dump", "onStartAsync"); } @Override - public void onError(AsyncEvent event) throws IOException + public void onError(AsyncEvent event) { response.addHeader("Dump", "onError"); } @Override - public void onComplete(AsyncEvent event) throws IOException + public void onComplete(AsyncEvent event) { response.addHeader("Dump", "onComplete"); } @@ -226,36 +225,25 @@ public void onComplete(AsyncEvent event) throws IOException request.setAttribute("RESUME", Boolean.TRUE); final long resume = Long.parseLong(request.getParameter("dispatch")); - _timer.schedule(new TimerTask() - { - @Override - public void run() - { - async.dispatch(); - } - }, resume); + _scheduler.schedule(() -> async.dispatch(), resume, TimeUnit.MILLISECONDS); } if (request.getParameter("complete") != null) { final long complete = Long.parseLong(request.getParameter("complete")); - _timer.schedule(new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setContentType("text/html"); - response.getOutputStream().println("

COMPLETED

"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setContentType("text/html"); + response.getOutputStream().println("

COMPLETED

"); + async.complete(); + } + catch (Exception e) + { + e.printStackTrace(); } - }, complete); + }, complete, TimeUnit.MILLISECONDS); } return; @@ -272,7 +260,7 @@ public void run() // Force a content length response String length = request.getParameter("length"); - if (length != null && length.length() > 0) + if (length != null && !length.isEmpty()) { response.setContentLength(Integer.parseInt(length)); } @@ -298,7 +286,7 @@ public void run() // test a reset String reset = request.getParameter("reset"); - if (reset != null && reset.length() > 0) + if (reset != null && !reset.isEmpty()) { response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); response.setHeader("SHOULD_NOT", "BE SEEN"); @@ -307,7 +295,7 @@ public void run() // handle an redirect String redirect = request.getParameter("redirect"); - if (redirect != null && redirect.length() > 0) + if (redirect != null && !redirect.isEmpty()) { response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); response.sendRedirect(response.encodeRedirectURL(redirect)); @@ -324,7 +312,7 @@ public void run() // handle an error String error = request.getParameter("error"); - if (error != null && error.length() > 0 && request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE) == null) + if (error != null && !error.isEmpty() && request.getAttribute(RequestDispatcher.ERROR_STATUS_CODE) == null) { response.getOutputStream().println("THIS SHOULD NOT BE SEEN!"); response.sendError(Integer.parseInt(error)); @@ -352,7 +340,7 @@ public void run() // Handle a extra headers String headers = request.getParameter("headers"); - if (headers != null && headers.length() > 0) + if (headers != null && !headers.isEmpty()) { long h = Long.parseLong(headers); for (int i = 0; i < h; i++) @@ -362,7 +350,7 @@ public void run() } String buffer = request.getParameter("buffer"); - if (buffer != null && buffer.length() > 0) + if (buffer != null && !buffer.isEmpty()) response.setBufferSize(Integer.parseInt(buffer)); String charset = request.getParameter("charset"); @@ -371,7 +359,7 @@ public void run() response.setCharacterEncoding(charset); response.setContentType("text/html"); - if (info != null && info.indexOf("Locale/") >= 0) + if (info != null && info.contains("Locale/")) { try { @@ -418,8 +406,7 @@ else if (pi.startsWith("/ex3/")) String buffered = request.getParameter("buffered"); - PrintWriter pout = null; - + PrintWriter pout; try { pout = response.getWriter(); @@ -438,7 +425,7 @@ else if (pi.startsWith("/ex3/")) pout.write(""); pout.write("\n"); pout.write(""); - pout.write(""); + pout.write(""); pout.write("\n"); pout.write(""); pout.write(""); @@ -459,7 +446,7 @@ else if (pi.startsWith("/ex3/")) pout.write(""); pout.write("\n"); pout.write(""); - pout.write(""); + pout.write(""); pout.write("\n"); pout.write(""); pout.write(""); @@ -507,7 +494,7 @@ else if (pi.startsWith("/ex3/")) pout.write(""); pout.write("\n"); pout.write(""); - pout.write(""); + pout.write(""); pout.write("\n"); pout.write(""); pout.write(""); @@ -541,12 +528,12 @@ else if (pi.startsWith("/ex3/")) String name; while (h.hasMoreElements()) { - name = (String)h.nextElement(); + name = h.nextElement(); Enumeration h2 = request.getHeaders(name); while (h2.hasMoreElements()) { - String hv = (String)h2.nextElement(); + String hv = h2.nextElement(); pout.write("\n"); pout.write(""); pout.write(""); @@ -558,7 +545,7 @@ else if (pi.startsWith("/ex3/")) h = request.getParameterNames(); while (h.hasMoreElements()) { - name = (String)h.nextElement(); + name = h.nextElement(); pout.write("\n"); pout.write(""); pout.write(""); @@ -646,13 +633,12 @@ else if (values.length > 1) Enumeration a = request.getAttributeNames(); while (a.hasMoreElements()) { - name = (String)a.nextElement(); + name = a.nextElement(); pout.write("\n"); pout.write(""); Object value = request.getAttribute(name); - if (value instanceof File) + if (value instanceof File file) { - File file = (File)value; pout.write(""); } else @@ -665,7 +651,7 @@ else if (values.length > 1) a = getInitParameterNames(); while (a.hasMoreElements()) { - name = (String)a.nextElement(); + name = a.nextElement(); pout.write("\n"); pout.write(""); pout.write(""); @@ -676,7 +662,7 @@ else if (values.length > 1) a = getServletContext().getInitParameterNames(); while (a.hasMoreElements()) { - name = (String)a.nextElement(); + name = a.nextElement(); pout.write("\n"); pout.write(""); pout.write(""); @@ -687,14 +673,14 @@ else if (values.length > 1) a = getServletContext().getAttributeNames(); while (a.hasMoreElements()) { - name = (String)a.nextElement(); + name = a.nextElement(); pout.write("\n"); pout.write(""); pout.write(""); } String res = request.getParameter("resource"); - if (res != null && res.length() > 0) + if (res != null && !res.isEmpty()) { pout.write("\n"); pout.write(""); @@ -707,7 +693,7 @@ else if (values.length > 1) } catch (Exception e) { - pout.write(""); + pout.write(""); } pout.write("\n"); @@ -718,7 +704,7 @@ else if (values.length > 1) } catch (Exception e) { - pout.write(""); + pout.write(""); } pout.write("\n"); @@ -729,7 +715,7 @@ else if (values.length > 1) } catch (Exception e) { - pout.write(""); + pout.write(""); } pout.write("\n"); @@ -748,7 +734,7 @@ else if (values.length > 1) } catch (Exception e) { - pout.write(""); + pout.write(""); } pout.write("\n"); @@ -759,7 +745,7 @@ else if (values.length > 1) } catch (Exception e) { - pout.write(""); + pout.write(""); } String cp = context.getContextPath(); @@ -897,12 +883,12 @@ else if (rsw instanceof ServletResponseWrapper) if (pi != null) { - if ("/ex4".equals(pi)) - throw new ServletException("test ex4", new Throwable()); - if ("/ex5".equals(pi)) - throw new IOException("test ex5"); - if ("/ex6".equals(pi)) - throw new UnavailableException("test ex6"); + switch (pi) + { + case "/ex4" -> throw new ServletException("test ex4", new Throwable()); + case "/ex5" -> throw new IOException("test ex5"); + case "/ex6" -> throw new UnavailableException("test ex6"); + } } } @@ -915,7 +901,7 @@ public String getServletInfo() @Override public void destroy() { - _timer.cancel(); + _scheduler.shutdownNow(); } private String getURI(HttpServletRequest request) @@ -935,7 +921,7 @@ private static String toString(Object o) { if (o.getClass().isArray()) { - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); if (!o.getClass().getComponentType().isPrimitive()) { Object[] array = (Object[])o; @@ -978,11 +964,11 @@ private static String toString(Object o) private boolean dump(HttpServletResponse response, String data, String chars, String block, String dribble, boolean flush) throws IOException { - if (data != null && data.length() > 0) + int len = (block != null && !block.isEmpty()) ? Integer.parseInt(block) : 50; + if (data != null && !data.isEmpty()) { - int b = (block != null && block.length() > 0) ? Integer.parseInt(block) : 50; - byte[] buf = new byte[b]; - for (int i = 0; i < b; i++) + byte[] buf = new byte[len]; + for (int i = 0; i < len; i++) { buf[i] = (byte)('0' + (i % 10)); @@ -995,15 +981,15 @@ private boolean dump(HttpServletResponse response, String data, String chars, St long d = Long.parseLong(data); while (d > 0) { - if (b == 1) + if (len == 1) { out.write(d % 80 == 0 ? '\n' : '.'); d--; } - else if (d >= b) + else if (d >= len) { out.write(buf); - d = d - b; + d = d - len; } else { @@ -1033,11 +1019,10 @@ else if (d >= b) } // Handle a dump of data - if (chars != null && chars.length() > 0) + if (chars != null && !chars.isEmpty()) { - int b = (block != null && block.length() > 0) ? Integer.parseInt(block) : 50; - char[] buf = new char[b]; - for (int i = 0; i < b; i++) + char[] buf = new char[len]; + for (int i = 0; i < len; i++) { buf[i] = (char)('0' + (i % 10)); if (i % 10 == 9) @@ -1049,15 +1034,15 @@ else if (d >= b) long d = Long.parseLong(chars); while (d > 0 && !out.checkError()) { - if (b == 1) + if (len == 1) { out.write(d % 80 == 0 ? '\n' : '.'); d--; } - else if (d >= b) + else if (d >= len) { out.write(buf); - d = d - b; + d = d - len; } else { diff --git a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/AsyncServletTest.java b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/AsyncServletTest.java index 682787744d76..5f9488d3a1fd 100644 --- a/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/AsyncServletTest.java +++ b/jetty-ee10/jetty-ee10-servlet/src/test/java/org/eclipse/jetty/ee10/servlet/AsyncServletTest.java @@ -20,10 +20,10 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import java.util.stream.Stream; @@ -42,7 +42,6 @@ import jakarta.servlet.http.HttpServletResponseWrapper; import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.logging.StacklessLogging; -import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.server.RequestLog; import org.eclipse.jetty.server.Response; @@ -69,17 +68,16 @@ public class AsyncServletTest { - protected AsyncServlet _servlet = new AsyncServlet(); - protected int _port; - protected Server _server = new Server(); - protected ServletHandler _servletHandler; - protected ErrorPageErrorHandler _errorHandler; - protected ServerConnector _connector; - protected List _log; - protected int _expectedLogs; - protected String _expectedCode; - protected List _history = new CopyOnWriteArrayList<>(); - protected CountDownLatch _latch; + private final AsyncServlet _servlet = new AsyncServlet(); + private int _port; + private final Server _server = new Server(); + private ServletHandler _servletHandler; + private ErrorPageErrorHandler _errorHandler; + private List _log; + private int _expectedLogs; + private String _expectedCode; + private final List _history = new CopyOnWriteArrayList<>(); + private CountDownLatch _latch; private void historyAdd(String item) { @@ -90,8 +88,8 @@ private void historyAdd(String item) @BeforeEach public void setUp() throws Exception { - _connector = new ServerConnector(_server); - _server.setConnectors(new Connector[]{_connector}); + ServerConnector connector = new ServerConnector(_server); + _server.addConnector(connector); _log = new ArrayList<>(); RequestLog log = new Log(); @@ -128,7 +126,7 @@ protected void onComplete(Request request, int status, HttpFields headers, Throw holder2.setAsyncSupported(false); _servletHandler.addServletWithMapping(holder2, "/noasync/*"); _server.start(); - _port = _connector.getLocalPort(); + _port = connector.getLocalPort(); _history.clear(); _latch = new CountDownLatch(1); } @@ -787,7 +785,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re private class AsyncServlet extends HttpServlet { - private final Timer _timer = new Timer(); + private final ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); @Override public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException @@ -889,28 +887,20 @@ else if (request.getContentLength() > 0) if (completeAfter > 0) { - TimerTask complete = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - historyAdd("complete"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + historyAdd("complete"); + async.complete(); } - }; - synchronized (_timer) - { - _timer.schedule(complete, completeAfter); - } + catch (Exception e) + { + e.printStackTrace(); + } + }, completeAfter, TimeUnit.MILLISECONDS); } else if (completeAfter == 0) { @@ -921,28 +911,20 @@ else if (completeAfter == 0) } else if (dispatchAfter > 0) { - TimerTask dispatch = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + historyAdd("dispatch"); + if (path != null) { - historyAdd("dispatch"); - if (path != null) - { - int q = path.indexOf('?'); - String uriInContext = (q >= 0) - ? URIUtil.encodePath(path.substring(0, q)) + path.substring(q) - : URIUtil.encodePath(path); - async.dispatch(uriInContext); - } - else - async.dispatch(); + int q = path.indexOf('?'); + String uriInContext = (q >= 0) + ? URIUtil.encodePath(path.substring(0, q)) + path.substring(q) + : URIUtil.encodePath(path); + async.dispatch(uriInContext); } - }; - synchronized (_timer) - { - _timer.schedule(dispatch, dispatchAfter); - } + else + async.dispatch(); + }, dispatchAfter, TimeUnit.MILLISECONDS); } else if (dispatchAfter == 0) { @@ -993,28 +975,20 @@ else if (sleepFor >= 0) if (complete2After > 0) { - TimerTask complete = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - historyAdd("complete"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + historyAdd("complete"); + async.complete(); } - }; - synchronized (_timer) - { - _timer.schedule(complete, complete2After); - } + catch (Exception e) + { + e.printStackTrace(); + } + }, complete2After, TimeUnit.MILLISECONDS); } else if (complete2After == 0) { @@ -1025,19 +999,11 @@ else if (complete2After == 0) } else if (dispatch2After > 0) { - TimerTask dispatch = new TimerTask() - { - @Override - public void run() - { - historyAdd("dispatch"); - async.dispatch(); - } - }; - synchronized (_timer) + _scheduler.schedule(() -> { - _timer.schedule(dispatch, dispatch2After); - } + historyAdd("dispatch"); + async.dispatch(); + }, dispatch2After, TimeUnit.MILLISECONDS); } else if (dispatch2After == 0) { diff --git a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/Dump.java b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/Dump.java index e1cae0f8999e..5ebccb8d5444 100644 --- a/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/Dump.java +++ b/jetty-ee9/jetty-ee9-demos/jetty-ee9-demo-jetty-webapp/src/main/java/org/example/Dump.java @@ -29,8 +29,9 @@ import java.util.Date; import java.util.Enumeration; import java.util.Locale; -import java.util.Timer; -import java.util.TimerTask; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; import jakarta.servlet.AsyncContext; import jakarta.servlet.AsyncEvent; @@ -63,7 +64,7 @@ public class Dump extends HttpServlet */ private static final String ZWSP = "​"; boolean fixed; - Timer _timer; + ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); @Override public void init(ServletConfig config) throws ServletException @@ -76,8 +77,6 @@ public void init(ServletConfig config) throws ServletException fixed = true; throw new UnavailableException("Unavailable test", Integer.parseInt(config.getInitParameter("unavailable"))); } - - _timer = new Timer(true); } @Override @@ -226,36 +225,25 @@ public void onComplete(AsyncEvent event) throws IOException request.setAttribute("RESUME", Boolean.TRUE); final long resume = Long.parseLong(request.getParameter("dispatch")); - _timer.schedule(new TimerTask() - { - @Override - public void run() - { - async.dispatch(); - } - }, resume); + _scheduler.schedule(() -> async.dispatch(), resume, TimeUnit.MILLISECONDS); } if (request.getParameter("complete") != null) { final long complete = Long.parseLong(request.getParameter("complete")); - _timer.schedule(new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setContentType("text/html"); - response.getOutputStream().println("

COMPLETED

"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setContentType("text/html"); + response.getOutputStream().println("

COMPLETED

"); + async.complete(); + } + catch (Exception e) + { + e.printStackTrace(); } - }, complete); + }, complete, TimeUnit.MILLISECONDS); } return; @@ -915,7 +903,7 @@ public String getServletInfo() @Override public void destroy() { - _timer.cancel(); + _scheduler.shutdownNow(); } private String getURI(HttpServletRequest request) diff --git a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/AsyncServletTest.java b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/AsyncServletTest.java index 5b58ef05a67f..fcbf52177af9 100644 --- a/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/AsyncServletTest.java +++ b/jetty-ee9/jetty-ee9-servlet/src/test/java/org/eclipse/jetty/ee9/servlet/AsyncServletTest.java @@ -19,10 +19,10 @@ import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; -import java.util.Timer; -import java.util.TimerTask; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; import jakarta.servlet.AsyncContext; @@ -691,7 +691,7 @@ public void doGet(final HttpServletRequest request, final HttpServletResponse re private static class AsyncServlet extends HttpServlet { private static final long serialVersionUID = -8161977157098646562L; - private final Timer _timer = new Timer(); + private final ScheduledExecutorService _scheduler = Executors.newSingleThreadScheduledExecutor(); @Override public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException @@ -797,28 +797,20 @@ public void run() if (completeAfter > 0) { - TimerTask complete = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - historyAdd("complete"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + historyAdd("complete"); + async.complete(); } - }; - synchronized (_timer) - { - _timer.schedule(complete, completeAfter); - } + catch (Exception e) + { + e.printStackTrace(); + } + }, completeAfter, TimeUnit.MILLISECONDS); } else if (completeAfter == 0) { @@ -829,28 +821,20 @@ else if (completeAfter == 0) } else if (dispatchAfter > 0) { - TimerTask dispatch = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + historyAdd("dispatch"); + if (path != null) { - historyAdd("dispatch"); - if (path != null) - { - int q = path.indexOf('?'); - String uriInContext = (q >= 0) - ? URIUtil.encodePath(path.substring(0, q)) + path.substring(q) - : URIUtil.encodePath(path); - async.dispatch(uriInContext); - } - else - async.dispatch(); + int q = path.indexOf('?'); + String uriInContext = (q >= 0) + ? URIUtil.encodePath(path.substring(0, q)) + path.substring(q) + : URIUtil.encodePath(path); + async.dispatch(uriInContext); } - }; - synchronized (_timer) - { - _timer.schedule(dispatch, dispatchAfter); - } + else + async.dispatch(); + }, dispatchAfter, TimeUnit.MILLISECONDS); } else if (dispatchAfter == 0) { @@ -901,28 +885,20 @@ else if (sleepFor >= 0) if (complete2After > 0) { - TimerTask complete = new TimerTask() + _scheduler.schedule(() -> { - @Override - public void run() + try { - try - { - response.setStatus(200); - response.getOutputStream().println("COMPLETED\n"); - historyAdd("complete"); - async.complete(); - } - catch (Exception e) - { - e.printStackTrace(); - } + response.setStatus(200); + response.getOutputStream().println("COMPLETED\n"); + historyAdd("complete"); + async.complete(); } - }; - synchronized (_timer) - { - _timer.schedule(complete, complete2After); - } + catch (Exception e) + { + e.printStackTrace(); + } + }, complete2After, TimeUnit.MILLISECONDS); } else if (complete2After == 0) { @@ -933,19 +909,11 @@ else if (complete2After == 0) } else if (dispatch2After > 0) { - TimerTask dispatch = new TimerTask() - { - @Override - public void run() - { - historyAdd("dispatch"); - async.dispatch(); - } - }; - synchronized (_timer) + _scheduler.schedule(() -> { - _timer.schedule(dispatch, dispatch2After); - } + historyAdd("dispatch"); + async.dispatch(); + }, dispatch2After, TimeUnit.MILLISECONDS); } else if (dispatch2After == 0) { From 7e36f3c6e95330b2fc705e0f9e287e2b97879d07 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Tue, 28 May 2024 08:06:06 +1000 Subject: [PATCH 11/11] Fix #11507 getAttribute javadoc (#11843) Fix #11507 getAttribute javadoc. As some stage we should consider @Nullable or @NotNull annotations... --- .../src/main/java/org/eclipse/jetty/util/Attributes.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java index 346ccb515a3b..ba5c7f8db6aa 100644 --- a/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java +++ b/jetty-core/jetty-util/src/main/java/org/eclipse/jetty/util/Attributes.java @@ -38,7 +38,7 @@ public interface Attributes /** * Remove an attribute * @param name the attribute to remove - * @return the value of the attribute if removed, else null + * @return the value of the attribute if removed, else {@code null} */ Object removeAttribute(String name); @@ -46,20 +46,20 @@ public interface Attributes * Set an attribute * @param name the attribute to set * @param attribute the value to set. A null value is equivalent to removing the attribute. - * @return the previous value of the attribute if set, else null + * @return the previous value of the attribute if set, else {@code null} */ Object setAttribute(String name, Object attribute); /** * Get an attribute * @param name the attribute to get - * @return the value of the attribute + * @return the value of the attribute, or {@code null} if no such attribute exists */ Object getAttribute(String name); /** * Get the immutable set of attribute names. - * @return Set of attribute names + * @return Set of attribute names, or an empty set if there are no attributes. */ Set getAttributeNameSet();
getContentLength: " + Integer.toString(request.getContentLength()) + "" + request.getContentLength() + "
getContentType: " + notag(request.getContentType()) + "" + request.getLocalAddr() + "
getLocalPort: " + Integer.toString(request.getLocalPort()) + "" + request.getLocalPort() + "
getMethod: " + notag(request.getMethod()) + "" + notag(request.getServletPath()) + "
getServerPort: " + Integer.toString(request.getServerPort()) + "" + request.getServerPort() + "
getUserPrincipal: " + request.getUserPrincipal() + "
" + notag(name) + ": " + notag(hv) + "
" + notag(name) + ": " + notag(request.getParameter(name)) + "
" + name.replace(".", ZWSP + ".") + ": " + "
" + file.getName() + " (" + file.length() + " " + new Date(file.lastModified()) + ")
" + "
" + name + ": " + toString(getInitParameter(name)) + "
" + name.replace(".", ZWSP + ".") + ": " + toString(getServletContext().getInitParameter(name)) + "
" + name.replace(".", ZWSP + ".") + ": " + "
" + toString(getServletContext().getAttribute(name)) + "
" + "

Get Resource: \"" + res + "\"
" + "" + e + "" + e + "
" + "" + e + "" + e + "
" + "" + e + "" + e + "
" + "" + e + "" + e + "
" + "" + e + "" + e + "