Skip to content

Commit

Permalink
Fixes after Micronaut update
Browse files Browse the repository at this point in the history
  • Loading branch information
andriy-dmytruk committed Aug 20, 2024
1 parent 5b1a41c commit 6ff8b94
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ class SimpleServerSpec extends BaseServerlessApplicationSpec {
then:
app.read() == """\
HTTP/1.1 200 Ok
Content-Type: text/plain
Content-Length: 32
Content-Type: text/plain
Hello, Micronaut Without Netty!
""".stripIndent()
Expand All @@ -39,8 +39,8 @@ class SimpleServerSpec extends BaseServerlessApplicationSpec {
then:
app.read() == """\
HTTP/1.1 404 Not Found
Content-Type: application/json
Content-Length: 140
Content-Type: application/json
{"_links":{"self":[{"href":"/invalid-test","templated":false}]},"_embedded":{"errors":[{"message":"Page Not Found"}]},"message":"Not Found"}""".stripIndent()
}
Expand All @@ -56,8 +56,8 @@ class SimpleServerSpec extends BaseServerlessApplicationSpec {
then:
app.read() == """\
HTTP/1.1 400 Bad Request
Content-Type: text/plain
Content-Length: 32
Content-Type: text/plain
HTTP request could not be parsed""".stripIndent()
}
Expand Down Expand Up @@ -89,8 +89,8 @@ class SimpleServerSpec extends BaseServerlessApplicationSpec {
then:
app.read() == """\
HTTP/1.1 201 Created
Content-Type: text/plain
Content-Length: 13
Content-Type: text/plain
Hello, Dream
""".stripIndent()
Expand All @@ -107,8 +107,8 @@ class SimpleServerSpec extends BaseServerlessApplicationSpec {
then:
app.read() == """\
HTTP/1.1 200 Ok
Content-Type: text/plain
Content-Length: 15
Content-Type: text/plain
Hello, Dream1!
""".stripIndent()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import io.micronaut.http.context.event.HttpRequestReceivedEvent;
import io.micronaut.http.context.event.HttpRequestTerminatedEvent;
import io.micronaut.http.exceptions.HttpStatusException;
import io.micronaut.http.hateoas.JsonError;
import io.micronaut.http.server.RequestLifecycle;
import io.micronaut.http.server.RouteExecutor;
import io.micronaut.http.server.types.files.FileCustomizableResponseType;
Expand Down Expand Up @@ -420,7 +421,11 @@ private void encodeResponse(ServletExchange<REQ, RES> exchange,
MessageBodyWriter<Object> messageBodyWriter = null;
if (!(body instanceof HttpStatus)) {
messageBodyWriter = routeInfoAttribute.map(RouteInfo::getMessageBodyWriter).orElse(null);
if (messageBodyWriter == null) {
if (messageBodyWriter == null
// A special POJA case because the TCK bring in the netty client dependency
|| ("io.micronaut.http.netty.body.NettyCharSequenceBodyWriter".equals(messageBodyWriter.getClass().getName())
&& (JsonError.class.isAssignableFrom(bodyType)))
) {
MediaType finalMediaType = mediaType;
Argument<Object> finalBodyArgument = bodyArgument;
Optional<MessageBodyWriter<Object>> writer = messageBodyHandlerRegistry.findWriter(bodyArgument, List.of(mediaType));
Expand Down

0 comments on commit 6ff8b94

Please sign in to comment.