diff --git a/core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java index e8364f7..6551344 100644 --- a/core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java +++ b/core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java @@ -690,10 +690,12 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class cla } else if (producesContentType.contains(MediaType.TEXT_HTML)) { postProcess = ".textHtml()."; } + else { + postProcess = String.format(".contentType(%s).",producesContentType); + } } - methodBuilder.addCode( - "$L.thenAcceptAsync( r -> r" + postProcess + "send(this,$L), io.undertow.util.SameThreadExecutor.INSTANCE )\n\t.exceptionally( ex -> ", + "$L.thenAcceptAsync( r -> io.sinistral.proteus.server.ServerResponse.response(r)" + postProcess + "send(this,$L), io.undertow.util.SameThreadExecutor.INSTANCE )\n\t.exceptionally( ex -> ", "response", "exchange"); methodBuilder.beginControlFlow("", ""); methodBuilder.addCode("\t\tthrow new java.util.concurrent.CompletionException(ex);\n\t"); diff --git a/core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java b/core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java index 8d43c66..73ecb7c 100644 --- a/core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java +++ b/core/src/test/java/io/sinistral/proteus/test/controllers/Tests.java @@ -165,10 +165,10 @@ public ServerResponse responsePlaintext(ServerRequest request) @GET @Path("response/future/map") - public CompletableFuture>> responseFutureMap( ServerRequest request ) + public CompletableFuture> responseFutureMap( ServerRequest request ) { Map map = ImmutableMap.of("message", "success"); - return CompletableFuture.completedFuture(response( map ).applicationJson()); + return CompletableFuture.completedFuture(map); } @GET @@ -393,9 +393,9 @@ public ServerResponse> debugBlockingEndpoint(ServerRequest re @GET @Path("response/future/user") @Produces((MediaType.APPLICATION_JSON)) - public CompletableFuture> responseFutureUser() + public CompletableFuture responseFutureUser() { - return CompletableFuture.completedFuture(response( new User(123L) ).applicationJson() ); + return CompletableFuture.completedFuture( new User(123L) ); } @GET diff --git a/core/src/test/resources/logback-test.xml b/core/src/test/resources/logback-test.xml index 44a9e83..3c2ac50 100644 --- a/core/src/test/resources/logback-test.xml +++ b/core/src/test/resources/logback-test.xml @@ -16,7 +16,7 @@ - +