From 68ed3bce1b6ddf401ec40b825de5a2af0125373f Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Wed, 20 Sep 2023 15:47:29 +0200 Subject: [PATCH 1/3] build: Micronaut Core 4.1.5 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 9a2bd11bd7..d16fd2f16a 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -14,7 +14,7 @@ swagger-parser = "1.0.67" swagger-parser-v3 = "2.1.16" javaparser = "3.25.5" -micronaut = "4.1.2" +micronaut = "4.1.5" micronaut-security = "4.1.0" micronaut-serde = "2.2.4" micronaut-rxjava2 = "2.0.1" From 530f580c72345ca302fd8d01d34bc8f80b9712f7 Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Wed, 20 Sep 2023 15:47:36 +0200 Subject: [PATCH 2/3] build: Platform 4.1.1 --- gradle/libs.versions.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d16fd2f16a..ea8f795434 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -25,7 +25,7 @@ micronaut-validation = "4.0.3" micronaut-data = "4.1.2" micronaut-test = "4.0.2" micronaut-kotlin = "4.0.2" -micronaut-platform = "4.0.5" +micronaut-platform = "4.1.1" micronaut-logging = "1.1.2" [libraries] From 9c609f619a5f347b72bc9bc0bd971079dbcb7368 Mon Sep 17 00:00:00 2001 From: Sergio del Amo Date: Wed, 20 Sep 2023 16:45:26 +0200 Subject: [PATCH 3/3] rewrite BodyWriter --- .../test/dated/DatedResponseBodyWriter.java | 48 ++++------------- .../openapi/test/page/PageBodyWriter.java | 53 ++++--------------- .../src/test/resources/logback.xml | 15 ++++++ 3 files changed, 35 insertions(+), 81 deletions(-) create mode 100644 test-suite-server-generator/src/test/resources/logback.xml diff --git a/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/dated/DatedResponseBodyWriter.java b/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/dated/DatedResponseBodyWriter.java index 0a9f75e637..dd8351d6ac 100644 --- a/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/dated/DatedResponseBodyWriter.java +++ b/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/dated/DatedResponseBodyWriter.java @@ -1,8 +1,6 @@ package io.micronaut.openapi.test.dated; - import io.micronaut.context.exceptions.ConfigurationException; -import io.micronaut.core.annotation.Nullable; import io.micronaut.core.annotation.Order; import io.micronaut.core.type.Argument; import io.micronaut.core.type.MutableHeaders; @@ -11,7 +9,6 @@ import io.micronaut.http.body.MessageBodyHandlerRegistry; import io.micronaut.http.body.MessageBodyWriter; import io.micronaut.http.codec.CodecException; -import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.io.OutputStream; @@ -30,32 +27,9 @@ final class DatedResponseBodyWriter implements MessageBodyWriter bodyWriter; - private final Argument bodyType; - @Inject DatedResponseBodyWriter(MessageBodyHandlerRegistry registry) { - this(registry, null, null); - } - - private DatedResponseBodyWriter( - MessageBodyHandlerRegistry registry, - @Nullable MessageBodyWriter bodyWriter, - @Nullable Argument bodyType - ) { this.registry = registry; - this.bodyWriter = bodyWriter; - this.bodyType = bodyType; - } - - @Override - public MessageBodyWriter> createSpecific( - Argument> type - ) { - Argument bt = type.getTypeParameters()[0]; - MessageBodyWriter writer = registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)) - .orElseThrow(() -> new ConfigurationException("No JSON message writer present")); - return new DatedResponseBodyWriter<>(registry, writer, bt); } @Override @@ -66,14 +40,13 @@ public void writeTo( MutableHeaders headers, OutputStream outputStream ) throws CodecException { - if (bodyType != null && bodyWriter != null) { - if (dated.getLastModified() != null) { - headers.add(LAST_MODIFIED_HEADER, dated.getLastModified().toString()); - } - bodyWriter.writeTo(bodyType, mediaType, dated.getBody(), headers, outputStream); - } else { - throw new ConfigurationException("No JSON message writer present"); + Argument bt = type.getTypeParameters()[0]; + MessageBodyWriter writer = registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)) + .orElseThrow(() -> new ConfigurationException("No JSON message writer present")); + if (dated.getLastModified() != null) { + headers.add(LAST_MODIFIED_HEADER, dated.getLastModified().toString()); } + writer.writeTo(bt, mediaType, dated.getBody(), headers, outputStream); } @Override @@ -81,12 +54,9 @@ public boolean isWriteable( Argument> type, MediaType mediaType ) { - return bodyType != null && bodyWriter != null && bodyWriter.isWriteable(bodyType, mediaType); - } - - @Override - public boolean isBlocking() { - return bodyWriter != null && bodyWriter.isBlocking(); + Argument bt = type.getTypeParameters()[0]; + return registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)).isPresent() && + mediaType.equals(MediaType.APPLICATION_JSON_TYPE); } } diff --git a/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/page/PageBodyWriter.java b/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/page/PageBodyWriter.java index 65a21a12b2..3b476cba97 100644 --- a/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/page/PageBodyWriter.java +++ b/test-suite-server-generator/src/main/java/io/micronaut/openapi/test/page/PageBodyWriter.java @@ -1,8 +1,6 @@ package io.micronaut.openapi.test.page; - import io.micronaut.context.exceptions.ConfigurationException; -import io.micronaut.core.annotation.Nullable; import io.micronaut.core.annotation.Order; import io.micronaut.core.type.Argument; import io.micronaut.core.type.MutableHeaders; @@ -12,7 +10,6 @@ import io.micronaut.http.body.MessageBodyHandlerRegistry; import io.micronaut.http.body.MessageBodyWriter; import io.micronaut.http.codec.CodecException; -import jakarta.inject.Inject; import jakarta.inject.Singleton; import java.io.OutputStream; @@ -34,32 +31,9 @@ final class PageBodyWriter implements MessageBodyWriter> { private static final String PAGE_COUNT_HEADER = "X-Page-Count"; private final MessageBodyHandlerRegistry registry; - private final MessageBodyWriter> bodyWriter; - private final Argument> bodyType; - @Inject PageBodyWriter(MessageBodyHandlerRegistry registry) { - this(registry, null, null); - } - - private PageBodyWriter( - MessageBodyHandlerRegistry registry, - @Nullable MessageBodyWriter> bodyWriter, - @Nullable Argument> bodyType - ) { this.registry = registry; - this.bodyWriter = bodyWriter; - this.bodyType = bodyType; - } - - @Override - public MessageBodyWriter> createSpecific( - Argument> type - ) { - Argument> bt = Argument.listOf(type.getTypeParameters()[0]); - MessageBodyWriter> writer = registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)) - .orElseThrow(() -> new ConfigurationException("No JSON message writer present")); - return new PageBodyWriter<>(registry, writer, bt); } @Override @@ -70,16 +44,15 @@ public void writeTo( MutableHeaders headers, OutputStream outputStream ) throws CodecException { - if (bodyType != null && bodyWriter != null) { - headers.add(PAGE_NUMBER_HEADER, String.valueOf(page.getPageNumber())); - headers.add(PAGE_SIZE_HEADER, String.valueOf(page.getSize())); - headers.add(PAGE_COUNT_HEADER, String.valueOf(page.getTotalPages())); - headers.add(TOTAL_COUNT_HEADER, String.valueOf(page.getTotalSize())); + Argument> bt = Argument.listOf(type.getTypeParameters()[0]); + MessageBodyWriter> writer = registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)) + .orElseThrow(() -> new ConfigurationException("No JSON message writer present")); - bodyWriter.writeTo(bodyType, mediaType, page.getContent(), headers, outputStream); - } else { - throw new ConfigurationException("No JSON message writer present"); - } + headers.add(PAGE_NUMBER_HEADER, String.valueOf(page.getPageNumber())); + headers.add(PAGE_SIZE_HEADER, String.valueOf(page.getSize())); + headers.add(PAGE_COUNT_HEADER, String.valueOf(page.getTotalPages())); + headers.add(TOTAL_COUNT_HEADER, String.valueOf(page.getTotalSize())); + writer.writeTo(bt, mediaType, page.getContent(), headers, outputStream); } @Override @@ -87,12 +60,8 @@ public boolean isWriteable( Argument> type, MediaType mediaType ) { - return bodyType != null && bodyWriter != null && bodyWriter.isWriteable(bodyType, mediaType); - } - - @Override - public boolean isBlocking() { - return bodyWriter != null && bodyWriter.isBlocking(); + Argument> bt = Argument.listOf(type.getTypeParameters()[0]); + return mediaType.equals(MediaType.APPLICATION_JSON_TYPE) && + registry.findWriter(bt, List.of(MediaType.APPLICATION_JSON_TYPE)).isPresent(); } - } diff --git a/test-suite-server-generator/src/test/resources/logback.xml b/test-suite-server-generator/src/test/resources/logback.xml new file mode 100644 index 0000000000..e224af2223 --- /dev/null +++ b/test-suite-server-generator/src/test/resources/logback.xml @@ -0,0 +1,15 @@ + + + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + +