From 487d57cae528b14e7c72df0a4ecf87bb59a82a18 Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Mon, 14 Sep 2020 21:55:00 -0700 Subject: [PATCH] Remove further looping state for server responses. --- CHANGELOG.md | 5 +++++ .../java/io/sinistral/proteus/server/ServerResponse.java | 4 ++++ .../sinistral/proteus/server/handlers/HandlerGenerator.java | 4 ++-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 898c095..7af40ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,11 @@ Proteus Changelog. ## Unreleased ### No issue +**Expose socket timeouts.** + + +[2621026ce02933c](https://github.com/noboomu/proteus/commit/2621026ce02933c) Joshua Bauer *2020-09-14 20:13:41* + **Fix for looping requests when response wrapped in completable future.** diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java index 5076290..dd21481 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/server/ServerResponse.java @@ -709,6 +709,10 @@ public static ServerResponse response(String body) public static ServerResponse response(T entity) { + if(entity == null) + { + return new ServerResponse().notFound(); + } return new ServerResponse().entity(entity); } diff --git a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java index b4f80f3..80f37fb 100644 --- a/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java +++ b/proteus-core/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java @@ -677,7 +677,7 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class cla if (m.getReturnType().equals(ServerResponse.class)) { - methodBuilder.addStatement("$L.send(this,$L)", "response", "exchange"); + methodBuilder.addStatement("$L.send($L)", "response", "exchange"); } else if ((m.getGenericReturnType().toString().contains("java.util.concurrent.CompletionStage") && m.getGenericReturnType().toString().contains("ServerResponse")) || (m.getGenericReturnType().toString().contains("java.util.concurrent.CompletableFuture") && m.getGenericReturnType().toString().contains("ServerResponse"))) @@ -720,7 +720,7 @@ else if (m.getReturnType().getTypeName().contains("java.util.concurrent.Completi methodBuilder.addCode( - "$L.thenAccept( r -> io.sinistral.proteus.server.ServerResponse.response(r)" + postProcess + "send(this,$L) )\n\t.exceptionally( ex -> ", + "$L.thenAccept( r -> io.sinistral.proteus.server.ServerResponse.response(r)" + postProcess + "send($L) )\n\t.exceptionally( ex -> ", "response", "exchange"); methodBuilder.beginControlFlow("", ""); methodBuilder.addCode("\t\tthrow new java.util.concurrent.CompletionException(ex);\n\t");