diff --git a/changes.md b/changes.md index 4552c900c6..b17e9584ee 100644 --- a/changes.md +++ b/changes.md @@ -80,9 +80,12 @@ Changes log to lowercase at the HTTP boundary. - Added the `Protocol.STDIO` pseudo-protocol constant for standard input/output connectors. - Bugs fixed + - Fixed the OpenAPI extension build path for Commons Lang types inherited from Swagger. - Slf4j bridge reports wrong line number and caller class in log4j. Issue #233. - When GET is an allowed method of a server resource, HEAD is now also listed (e.g. in the Allow header of a 405 response). Issue #266. - Misc + - Fixed JDK HTTP client accessibility in core and WebSocket tests in Eclipse and VS Code, + without adding a production module dependency. - Pinned the Maven Deploy plugin to version 3.2.0 (avoids resolving incompatible Maven 4 beta versions). - Added Netty 4.2.19 (imported with the `netty-bom`). CI builds with Java 25. - The `dangling-doc-comments` lint, new in Java 23, is disabled because license headers diff --git a/org.restlet.ext.crypto/src/main/java/module-info.java b/org.restlet.ext.crypto/src/main/java/module-info.java index efd900c5b0..d25b1c35ac 100644 --- a/org.restlet.ext.crypto/src/main/java/module-info.java +++ b/org.restlet.ext.crypto/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.crypto { requires transitive org.restlet; diff --git a/org.restlet.ext.freemarker/src/main/java/module-info.java b/org.restlet.ext.freemarker/src/main/java/module-info.java index cc9a42f605..c0dc206cdd 100644 --- a/org.restlet.ext.freemarker/src/main/java/module-info.java +++ b/org.restlet.ext.freemarker/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.freemarker { requires transitive org.restlet; requires transitive freemarker; diff --git a/org.restlet.ext.gson/src/main/java/module-info.java b/org.restlet.ext.gson/src/main/java/module-info.java index f41bc78697..81da599a44 100644 --- a/org.restlet.ext.gson/src/main/java/module-info.java +++ b/org.restlet.ext.gson/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.gson { requires transitive org.restlet; requires transitive com.google.gson; diff --git a/org.restlet.ext.jaas/src/main/java/module-info.java b/org.restlet.ext.jaas/src/main/java/module-info.java index f880141efa..e7c4b44129 100644 --- a/org.restlet.ext.jaas/src/main/java/module-info.java +++ b/org.restlet.ext.jaas/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.jaas { requires transitive org.restlet; diff --git a/org.restlet.ext.jackson/src/main/java/module-info.java b/org.restlet.ext.jackson/src/main/java/module-info.java index db8759f1c2..b06d67e757 100644 --- a/org.restlet.ext.jackson/src/main/java/module-info.java +++ b/org.restlet.ext.jackson/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.jackson { requires transitive org.restlet; requires tools.jackson.core; diff --git a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Customer.java b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Customer.java index 4c7873fb7b..506d7711b6 100644 --- a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Customer.java +++ b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Customer.java @@ -8,16 +8,20 @@ */ package org.restlet.ext.jackson; +import java.io.Serial; +import java.io.Serializable; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; -public class Customer { +public class Customer implements Serializable { + + @Serial private static final long serialVersionUID = 1L; private String firstName; private String lastName; - private List invoices = new CopyOnWriteArrayList(); + private CopyOnWriteArrayList invoices = new CopyOnWriteArrayList(); public String getFirstName() { return firstName; diff --git a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Invoice.java b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Invoice.java index b1da7abd0a..2c8d369bdb 100644 --- a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Invoice.java +++ b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/Invoice.java @@ -8,9 +8,13 @@ */ package org.restlet.ext.jackson; +import java.io.Serial; +import java.io.Serializable; import java.util.Date; -public class Invoice { +public class Invoice implements Serializable { + + @Serial private static final long serialVersionUID = 1L; private Date date; diff --git a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/JacksonTestCase.java b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/JacksonTestCase.java index c067841b22..a367a20d2e 100644 --- a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/JacksonTestCase.java +++ b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/JacksonTestCase.java @@ -10,6 +10,10 @@ import static org.junit.jupiter.api.Assertions.assertThrows; +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; import java.util.Date; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -89,6 +93,25 @@ void testException() throws Exception { assertEquals(me, rep.getObject()); } + @Test + void testExceptionJavaSerialization() throws Exception { + MyException exception = new MyException(createCustomer(), "CUST-1234"); + exception.setStackTrace(new StackTraceElement[0]); + + ByteArrayOutputStream bytes = new ByteArrayOutputStream(); + try (ObjectOutputStream output = new ObjectOutputStream(bytes)) { + output.writeObject(exception); + } + + MyException copy; + try (ObjectInputStream input = + new ObjectInputStream(new ByteArrayInputStream(bytes.toByteArray()))) { + copy = (MyException) input.readObject(); + } + + assertEquals(exception, copy); + } + @Test void testJson() throws Exception { Customer customer = createCustomer(); diff --git a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/MyException.java b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/MyException.java index 9413425ab3..96f2eef890 100644 --- a/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/MyException.java +++ b/org.restlet.ext.jackson/src/test/java/org/restlet/ext/jackson/MyException.java @@ -16,7 +16,6 @@ public class MyException extends Exception { @Serial private static final long serialVersionUID = 1L; - @SuppressWarnings("serial") private Customer customer; private String errorCode; diff --git a/org.restlet.ext.json/src/main/java/module-info.java b/org.restlet.ext.json/src/main/java/module-info.java index 4ba7260598..fd6726ca58 100644 --- a/org.restlet.ext.json/src/main/java/module-info.java +++ b/org.restlet.ext.json/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.json { requires transitive org.restlet; requires transitive org.json; diff --git a/org.restlet.ext.openapi/pom.xml b/org.restlet.ext.openapi/pom.xml index 5d6480f921..4e1d38ce3c 100644 --- a/org.restlet.ext.openapi/pom.xml +++ b/org.restlet.ext.openapi/pom.xml @@ -33,6 +33,10 @@ + + org.apache.commons + commons-lang3 + io.swagger.core.v3 swagger-core diff --git a/org.restlet.ext.openapi/src/main/java/module-info.java b/org.restlet.ext.openapi/src/main/java/module-info.java index d149df7b20..424739d8a2 100644 --- a/org.restlet.ext.openapi/src/main/java/module-info.java +++ b/org.restlet.ext.openapi/src/main/java/module-info.java @@ -6,9 +6,10 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.openapi { requires transitive org.restlet; + requires org.apache.commons.lang3; requires io.swagger.v3.core; requires io.swagger.v3.oas.models; requires io.swagger.v3.oas.integration; diff --git a/org.restlet.ext.openapi/src/test/java/org/restlet/ext/openapi/OpenApiGenerationTest.java b/org.restlet.ext.openapi/src/test/java/org/restlet/ext/openapi/OpenApiGenerationTest.java index fff9e4114b..4d5577c689 100644 --- a/org.restlet.ext.openapi/src/test/java/org/restlet/ext/openapi/OpenApiGenerationTest.java +++ b/org.restlet.ext.openapi/src/test/java/org/restlet/ext/openapi/OpenApiGenerationTest.java @@ -14,7 +14,6 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import java.util.stream.Stream; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; @@ -36,7 +35,19 @@ import org.restlet.resource.ClientResource; class OpenApiGenerationTest { - private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper(new YAMLFactory()); + private static final ObjectMapper OBJECT_MAPPER = createYamlMapper(); + + private static ObjectMapper createYamlMapper() { + try { + var yamlFactory = + Class.forName("com.fasterxml.jackson.dataformat.yaml.YAMLFactory") + .getConstructor() + .newInstance(); + return new ObjectMapper((com.fasterxml.jackson.core.JsonFactory) yamlFactory); + } catch (ReflectiveOperationException e) { + throw new IllegalStateException("Unable to initialize the YAML parser", e); + } + } Component component; Server server; diff --git a/org.restlet.ext.slf4j/src/main/java/module-info.java b/org.restlet.ext.slf4j/src/main/java/module-info.java index 671f769f79..f49a6e3861 100644 --- a/org.restlet.ext.slf4j/src/main/java/module-info.java +++ b/org.restlet.ext.slf4j/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.slf4j { requires transitive org.restlet; requires transitive org.slf4j; diff --git a/org.restlet.ext.spring/src/main/java/module-info.java b/org.restlet.ext.spring/src/main/java/module-info.java index 7f109d4d61..6e9639f7a5 100644 --- a/org.restlet.ext.spring/src/main/java/module-info.java +++ b/org.restlet.ext.spring/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.spring { requires transitive org.restlet; requires transitive spring.beans; diff --git a/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringContextTestCase.java b/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringContextTestCase.java index 23f0e90960..6efa5c4341 100644 --- a/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringContextTestCase.java +++ b/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringContextTestCase.java @@ -30,56 +30,60 @@ private Context restletContextWithClapDispatcher() { @Test void getRestletContext_returnsConstructorArgument() { Context restletContext = new Context(); - SpringContext springContext = new SpringContext(restletContext); - assertSame(restletContext, springContext.getRestletContext()); + try (SpringContext springContext = new SpringContext(restletContext)) { + assertSame(restletContext, springContext.getRestletContext()); + } } @Test void getPropertyConfigRefs_lazyInitializesToEmptyModifiableList() { - SpringContext springContext = new SpringContext(new Context()); - assertNotNull(springContext.getPropertyConfigRefs()); - assertTrue(springContext.getPropertyConfigRefs().isEmpty()); - springContext.getPropertyConfigRefs().add("some-ref"); - assertEquals(1, springContext.getPropertyConfigRefs().size()); + try (SpringContext springContext = new SpringContext(new Context())) { + assertNotNull(springContext.getPropertyConfigRefs()); + assertTrue(springContext.getPropertyConfigRefs().isEmpty()); + springContext.getPropertyConfigRefs().add("some-ref"); + assertEquals(1, springContext.getPropertyConfigRefs().size()); + } } @Test void getXmlConfigRefs_lazyInitializesToEmptyModifiableList() { - SpringContext springContext = new SpringContext(new Context()); - assertNotNull(springContext.getXmlConfigRefs()); - assertTrue(springContext.getXmlConfigRefs().isEmpty()); - springContext.getXmlConfigRefs().add("some-ref"); - assertEquals(1, springContext.getXmlConfigRefs().size()); + try (SpringContext springContext = new SpringContext(new Context())) { + assertNotNull(springContext.getXmlConfigRefs()); + assertTrue(springContext.getXmlConfigRefs().isEmpty()); + springContext.getXmlConfigRefs().add("some-ref"); + assertEquals(1, springContext.getXmlConfigRefs().size()); + } } @Test void refresh_withoutConfigRefs_refreshesEmptyContext() { - SpringContext springContext = new SpringContext(new Context()); - springContext.refresh(); - assertTrue(springContext.isActive()); + try (SpringContext springContext = new SpringContext(new Context())) { + springContext.refresh(); + assertTrue(springContext.isActive()); + } } @Test void refresh_withPropertyConfigRef_loadsBeanDefinitionsFromProperties() { - SpringContext springContext = new SpringContext(restletContextWithClapDispatcher()); - springContext - .getPropertyConfigRefs() - .add("clap://class/org/restlet/ext/spring/SpringContextTestCase.properties"); + try (SpringContext springContext = new SpringContext(restletContextWithClapDispatcher())) { + springContext + .getPropertyConfigRefs() + .add("clap://class/org/restlet/ext/spring/SpringContextTestCase.properties"); + springContext.refresh(); - springContext.refresh(); - - assertNotNull(springContext.getBean("myPropertyBean")); + assertNotNull(springContext.getBean("myPropertyBean")); + } } @Test void refresh_withXmlConfigRef_loadsBeanDefinitionsFromXml() { - SpringContext springContext = new SpringContext(restletContextWithClapDispatcher()); - springContext - .getXmlConfigRefs() - .add("clap://class/org/restlet/ext/spring/SpringContextTestCase.xml"); - - springContext.refresh(); + try (SpringContext springContext = new SpringContext(restletContextWithClapDispatcher())) { + springContext + .getXmlConfigRefs() + .add("clap://class/org/restlet/ext/spring/SpringContextTestCase.xml"); + springContext.refresh(); - assertNotNull(springContext.getBean("myXmlBean")); + assertNotNull(springContext.getBean("myXmlBean")); + } } } diff --git a/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringResourceTestCase.java b/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringResourceTestCase.java index e219334b7c..0efcddb87f 100644 --- a/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringResourceTestCase.java +++ b/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringResourceTestCase.java @@ -100,6 +100,7 @@ void equalsAndHashCode_basedOnWrappedRepresentation() { assertEquals(resource1, resource2); assertEquals(resource1.hashCode(), resource2.hashCode()); assertNotEquals(resource1, resource3); - assertFalse(resource1.equals("not a resource")); + Object notAResource = "not a resource"; + assertFalse(resource1.equals(notAResource)); } } diff --git a/org.restlet.ext.thymeleaf/src/main/java/module-info.java b/org.restlet.ext.thymeleaf/src/main/java/module-info.java index ecb5d2d03d..58900eed72 100644 --- a/org.restlet.ext.thymeleaf/src/main/java/module-info.java +++ b/org.restlet.ext.thymeleaf/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.thymeleaf { requires transitive org.restlet; requires transitive thymeleaf; diff --git a/org.restlet.ext.websocket/pom.xml b/org.restlet.ext.websocket/pom.xml new file mode 100644 index 0000000000..12f5447c70 --- /dev/null +++ b/org.restlet.ext.websocket/pom.xml @@ -0,0 +1,65 @@ + + + 4.0.0 + + org.restlet + org.restlet.parent + 3.0.0-SNAPSHOT + ../pom.xml + + + org.restlet.ext.websocket + Restlet Framework - WebSocket extension + Support for WebSocket servers and clients (experimental), on the Netty connectors. + + + + org.restlet + org.restlet + ${project.version} + + + io.netty + netty-codec-http + + + io.netty + netty-handler + + + org.junit.jupiter + junit-jupiter-api + ${lib-junit-version} + test + + + + + m2e-test-modules + + m2e.version + + + + + maven-compiler-plugin + + + default-testCompile + + + + --add-reads + org.restlet.ext.websocket=java.net.http + + + + + + + + + + diff --git a/org.restlet.ext.xml/src/main/java/module-info.java b/org.restlet.ext.xml/src/main/java/module-info.java index 2709d23eed..02a02a4b86 100644 --- a/org.restlet.ext.xml/src/main/java/module-info.java +++ b/org.restlet.ext.xml/src/main/java/module-info.java @@ -6,7 +6,7 @@ * *

Restlet is a registered trademark of QlikTech International AB. */ -@SuppressWarnings({"module", "requires-automatic", "requires-transitive-automatic"}) +@SuppressWarnings({"requires-automatic", "requires-transitive-automatic"}) module org.restlet.ext.xml { requires transitive org.restlet; requires java.xml; diff --git a/org.restlet/pom.xml b/org.restlet/pom.xml index a41c5dcfb2..c9017eb4be 100644 --- a/org.restlet/pom.xml +++ b/org.restlet/pom.xml @@ -134,8 +134,34 @@ - + + m2e-test-modules + + m2e.version + + + + + maven-compiler-plugin + + + default-testCompile + + + + --add-reads + org.restlet=java.net.http + + + + + + + + + quic-linux-x86_64 diff --git a/org.restlet/src/main/java/org/restlet/engine/application/DecodeRepresentation.java b/org.restlet/src/main/java/org/restlet/engine/application/DecodeRepresentation.java index 3b8e5cad6b..05fb7a2e0b 100644 --- a/org.restlet/src/main/java/org/restlet/engine/application/DecodeRepresentation.java +++ b/org.restlet/src/main/java/org/restlet/engine/application/DecodeRepresentation.java @@ -96,11 +96,13 @@ private InputStream getDecodedStream(Encoding encoding, InputStream encodedStrea } else if (encoding.equals(Encoding.DEFLATE)) { result = new InflaterInputStream(encodedStream); } else if (encoding.equals(Encoding.DEFLATE_NOWRAP)) { - result = new InflaterInputStream(encodedStream, new Inflater(true)); + result = new OwnedInflaterInputStream(encodedStream, new Inflater(true)); } else if (encoding.equals(Encoding.ZIP)) { final ZipInputStream stream = new ZipInputStream(encodedStream); if (stream.getNextEntry() != null) { result = stream; + } else { + stream.close(); } } else if (encoding.equals(Encoding.IDENTITY)) { throw new IOException("Decoder unnecessary for identity decoding"); @@ -110,6 +112,24 @@ private InputStream getDecodedStream(Encoding encoding, InputStream encodedStrea return result; } + private static final class OwnedInflaterInputStream extends InflaterInputStream { + private final Inflater ownedInflater; + + private OwnedInflaterInputStream(InputStream inputStream, Inflater inflater) { + super(inputStream, inflater); + this.ownedInflater = inflater; + } + + @Override + public void close() throws IOException { + try { + super.close(); + } finally { + this.ownedInflater.close(); + } + } + } + /** * Returns the encodings applied to the entity. * diff --git a/org.restlet/src/main/java/org/restlet/engine/application/EncodeRepresentation.java b/org.restlet/src/main/java/org/restlet/engine/application/EncodeRepresentation.java index c8ecd54c3e..51a59d62fa 100644 --- a/org.restlet/src/main/java/org/restlet/engine/application/EncodeRepresentation.java +++ b/org.restlet/src/main/java/org/restlet/engine/application/EncodeRepresentation.java @@ -173,9 +173,10 @@ public void write(OutputStream outputStream) throws IOException { } else if (this.encoding.equals(Encoding.DEFLATE)) { encoderOutputStream = new DeflaterOutputStream(outputStream); } else if (this.encoding.equals(Encoding.DEFLATE_NOWRAP)) { - encoderOutputStream = - new DeflaterOutputStream( - outputStream, new Deflater(Deflater.DEFAULT_COMPRESSION, true)); + try (Deflater deflater = new Deflater(Deflater.DEFAULT_COMPRESSION, true)) { + writeEncoded(new DeflaterOutputStream(outputStream, deflater)); + } + return; } else if (this.encoding.equals(Encoding.ZIP)) { final ZipOutputStream stream = new ZipOutputStream(outputStream); String name = "entry"; @@ -193,9 +194,7 @@ public void write(OutputStream outputStream) throws IOException { } if (encoderOutputStream != null) { - getWrappedRepresentation().write(encoderOutputStream); - encoderOutputStream.flush(); - encoderOutputStream.finish(); + writeEncoded(encoderOutputStream); } else { getWrappedRepresentation().write(outputStream); } @@ -204,6 +203,12 @@ public void write(OutputStream outputStream) throws IOException { } } + private void writeEncoded(DeflaterOutputStream encoderOutputStream) throws IOException { + getWrappedRepresentation().write(encoderOutputStream); + encoderOutputStream.flush(); + encoderOutputStream.finish(); + } + @Override public void write(java.io.Writer writer) throws IOException { if (canEncode()) { diff --git a/org.restlet/src/main/java/org/restlet/engine/converter/DefaultConverter.java b/org.restlet/src/main/java/org/restlet/engine/converter/DefaultConverter.java index c85063b784..197712cf20 100644 --- a/org.restlet/src/main/java/org/restlet/engine/converter/DefaultConverter.java +++ b/org.restlet/src/main/java/org/restlet/engine/converter/DefaultConverter.java @@ -129,17 +129,17 @@ public List getVariants(Class source) { @Override public float score(Object source, Variant target, Resource resource) { return switch (source) { - case String s -> 1.0F; - case File f -> 1.0F; - case InputStream is -> 1.0F; - case Reader r -> 1.0F; - case Representation rep -> 1.0F; - case Form form + case String _ -> 1.0F; + case File _ -> 1.0F; + case InputStream _ -> 1.0F; + case Reader _ -> 1.0F; + case Representation _ -> 1.0F; + case Form _ when target != null && MediaType.APPLICATION_WWW_FORM.isCompatible(target.getMediaType()) -> 1.0F; - case Form form -> 0.6F; - case Serializable s -> scoreSerializable(target); + case Form _ -> 0.6F; + case Serializable _ -> scoreSerializable(target); case null, default -> -1.0F; }; } diff --git a/org.restlet/src/test/java/org/restlet/engine/application/EncodeRepresentationTestCase.java b/org.restlet/src/test/java/org/restlet/engine/application/EncodeRepresentationTestCase.java index 73c09b28d5..60062d5d0d 100644 --- a/org.restlet/src/test/java/org/restlet/engine/application/EncodeRepresentationTestCase.java +++ b/org.restlet/src/test/java/org/restlet/engine/application/EncodeRepresentationTestCase.java @@ -16,6 +16,7 @@ import java.io.ByteArrayOutputStream; import java.io.StringWriter; import java.util.zip.GZIPInputStream; +import java.util.zip.Inflater; import java.util.zip.InflaterInputStream; import java.util.zip.ZipInputStream; import org.junit.jupiter.api.Test; @@ -125,10 +126,10 @@ void write_deflateNowrap_producesDeflateNowrapStream() throws Exception { ByteArrayOutputStream out = new ByteArrayOutputStream(); representation.write(out); - try (InflaterInputStream inflater = - new InflaterInputStream( - new java.io.ByteArrayInputStream(out.toByteArray()), - new java.util.zip.Inflater(true))) { + try (Inflater deflater = new Inflater(true); + InflaterInputStream inflater = + new InflaterInputStream( + new java.io.ByteArrayInputStream(out.toByteArray()), deflater)) { assertEquals("hello", IoUtils.toString(inflater)); } } diff --git a/org.restlet/src/test/java/org/restlet/engine/connector/AsyncTestCase.java b/org.restlet/src/test/java/org/restlet/engine/connector/AsyncTestCase.java index 57ed21d185..60e8f0cce8 100644 --- a/org.restlet/src/test/java/org/restlet/engine/connector/AsyncTestCase.java +++ b/org.restlet/src/test/java/org/restlet/engine/connector/AsyncTestCase.java @@ -65,7 +65,7 @@ private void testCall(Context context, int count, Method method) throws Exceptio String item = request.getResourceRef().getQueryAsForm().getFirstValue("item"); try { - assertEquals(item, Integer.toString(response.getAge())); + assertEquals(item, response.getHeaders().getFirstValue("X-Test-Item")); if (responseEntityExpected(request.getMethod())) { assertEquals(Status.SUCCESS_OK, response.getStatus()); assertTrue(response.isEntityAvailable()); @@ -109,12 +109,12 @@ void setUpEach() throws Exception { new Restlet(originComponent.getContext().createChildContext()) { @Override public void handle(Request request, Response response) { - // let's set the item number as age ;-) - response.setAge( - Integer.parseInt( + response.getHeaders() + .add( + "X-Test-Item", request.getResourceRef() .getQueryAsForm() - .getFirstValue("item"))); + .getFirstValue("item")); if (responseEntityExpected(request.getMethod())) { // Print the requested URI path diff --git a/org.restlet/src/test/java/org/restlet/engine/io/WriterOutputStreamTestCase.java b/org.restlet/src/test/java/org/restlet/engine/io/WriterOutputStreamTestCase.java index 15a085237e..5c22d1cb64 100644 --- a/org.restlet/src/test/java/org/restlet/engine/io/WriterOutputStreamTestCase.java +++ b/org.restlet/src/test/java/org/restlet/engine/io/WriterOutputStreamTestCase.java @@ -22,9 +22,9 @@ class WriterOutputStreamTestCase { @Test void writeByteArray_decodesUsingGivenCharacterSet() throws IOException { StringWriter writer = new StringWriter(); - WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8); - - out.write("hello".getBytes(StandardCharsets.UTF_8)); + try (WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8)) { + out.write("hello".getBytes(StandardCharsets.UTF_8)); + } assertEquals("hello", writer.toString()); } @@ -32,9 +32,9 @@ void writeByteArray_decodesUsingGivenCharacterSet() throws IOException { @Test void writeByteArray_nullCharacterSet_defaultsToIso88591() throws IOException { StringWriter writer = new StringWriter(); - WriterOutputStream out = new WriterOutputStream(writer, null); - - out.write("abc".getBytes(StandardCharsets.ISO_8859_1)); + try (WriterOutputStream out = new WriterOutputStream(writer, null)) { + out.write("abc".getBytes(StandardCharsets.ISO_8859_1)); + } assertEquals("abc", writer.toString()); } @@ -42,9 +42,9 @@ void writeByteArray_nullCharacterSet_defaultsToIso88591() throws IOException { @Test void writeSingleByte_delegatesToWriter() throws IOException { StringWriter writer = new StringWriter(); - WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8); - - out.write('a'); + try (WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8)) { + out.write('a'); + } assertEquals("a", writer.toString()); } @@ -52,10 +52,10 @@ void writeSingleByte_delegatesToWriter() throws IOException { @Test void writeByteArrayWithOffsetAndLength_writesOnlyThatSlice() throws IOException { StringWriter writer = new StringWriter(); - WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8); byte[] data = "xxhelloxx".getBytes(StandardCharsets.UTF_8); - - out.write(data, 2, 5); + try (WriterOutputStream out = new WriterOutputStream(writer, CharacterSet.UTF_8)) { + out.write(data, 2, 5); + } assertEquals("hello", writer.toString()); } @@ -72,9 +72,9 @@ public void flush() throws IOException { super.flush(); } }; - WriterOutputStream out = new WriterOutputStream(tracker, CharacterSet.UTF_8); - - out.flush(); + try (WriterOutputStream out = new WriterOutputStream(tracker, CharacterSet.UTF_8)) { + out.flush(); + } assertTrue(flushed.get()); } @@ -91,9 +91,9 @@ public void close() throws IOException { super.close(); } }; - WriterOutputStream out = new WriterOutputStream(tracker, CharacterSet.UTF_8); - - out.close(); + try (WriterOutputStream out = new WriterOutputStream(tracker, CharacterSet.UTF_8)) { + out.flush(); + } assertTrue(closed.get()); } diff --git a/org.restlet/src/test/java/org/restlet/resource/AnnotatedResource13TestCase.java b/org.restlet/src/test/java/org/restlet/resource/AnnotatedResource13TestCase.java index d649dbacd9..cde6cbed5b 100644 --- a/org.restlet/src/test/java/org/restlet/resource/AnnotatedResource13TestCase.java +++ b/org.restlet/src/test/java/org/restlet/resource/AnnotatedResource13TestCase.java @@ -20,7 +20,7 @@ * * @author Jerome Louvel */ -class AnnotatedResource13TestCase extends AbstractAnnotatedResourceWithFinderTestCase { +public class AnnotatedResource13TestCase extends AbstractAnnotatedResourceWithFinderTestCase { private MyResource13 myResource; diff --git a/org.restlet/src/test/java/org/restlet/service/TaskServiceTestCase.java b/org.restlet/src/test/java/org/restlet/service/TaskServiceTestCase.java index 320bb9ea24..b52e4f8394 100644 --- a/org.restlet/src/test/java/org/restlet/service/TaskServiceTestCase.java +++ b/org.restlet/src/test/java/org/restlet/service/TaskServiceTestCase.java @@ -165,7 +165,6 @@ void scheduleWithFixedDelay_runsMultipleTimes() throws Exception { void invokeAll_executesAllTasks() throws Exception { taskService = new TaskService(); - @SuppressWarnings({"rawtypes", "unchecked"}) List> futures = taskService.invokeAll( List.of((Callable) () -> "a", (Callable) () -> "b")); @@ -179,7 +178,6 @@ void invokeAll_executesAllTasks() throws Exception { void invokeAny_returnsOneResult() throws Exception { taskService = new TaskService(); - @SuppressWarnings("unchecked") Object result = taskService.invokeAny(List.of((Callable) () -> "only")); assertEquals("only", result);