Skip to content

Commit d5e68ec

Browse files
committed
#63 - Add support for HttpResponse.BodyHandler with and without generic parameters
1 parent 675fc91 commit d5e68ec

File tree

5 files changed

+30
-3
lines changed

5 files changed

+30
-3
lines changed

http-generator-client/src/main/java/io/avaje/http/generator/client/ClientMethodWriter.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private void methodStart(Append writer) {
6161
*/
6262
private void checkBodyHandler(MethodParam param) {
6363
if (param.getRawType().startsWith(BODY_HANDLER)) {
64+
param.setResponseHandler();
6465
bodyHandlerParam = param;
6566
methodGenericParams = param.getUType().genericParams();
6667
}

http-generator-core/src/main/java/io/avaje/http/generator/core/ElementReader.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import javax.lang.model.element.TypeElement;
99
import javax.validation.Valid;
1010

11+
import static io.avaje.http.generator.core.ParamType.RESPONSE_HANDLER;
12+
1113
public class ElementReader {
1214

1315
private final ProcessingContext ctx;
@@ -310,4 +312,8 @@ public UType getType() {
310312
public Element getElement() {
311313
return element;
312314
}
315+
316+
public void setResponseHandler() {
317+
paramType = RESPONSE_HANDLER;
318+
}
313319
}

http-generator-core/src/main/java/io/avaje/http/generator/core/MethodParam.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,8 @@ public ParamType getParamType() {
6363
public UType getUType() {
6464
return elementParam.getType();
6565
}
66+
67+
public void setResponseHandler() {
68+
elementParam.setResponseHandler();
69+
}
6670
}

http-generator-core/src/main/java/io/avaje/http/generator/core/ParamType.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ public enum ParamType {
1010
QUERYPARAM("queryParam", "query"),
1111
FORMPARAM("formParam", "form"),
1212
COOKIE("cookie", "cookie"),
13-
HEADER("header", "header");
13+
HEADER("header", "header"),
14+
RESPONSE_HANDLER("notUsed", "notUsed");
1415

1516
private final String code;
1617
private final String type;

tests/test-client/src/main/java/org/example/JunkApi.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import io.avaje.http.client.HttpCall;
77

88
import java.io.InputStream;
9+
import java.net.http.HttpRequest;
910
import java.net.http.HttpResponse;
1011
import java.nio.file.Path;
1112
import java.util.List;
@@ -41,13 +42,24 @@ public interface JunkApi {
4142

4243
@Post
4344
Repo bean();
44-
4545
@Post
4646
List<Repo> list();
47-
4847
@Post
4948
Stream<Repo> stream();
5049

50+
@Post
51+
CompletableFuture<Repo> cfBean();
52+
@Post
53+
CompletableFuture<List<Repo>> cfList();
54+
@Post
55+
CompletableFuture<Stream<Repo>> cfStream();
56+
57+
@Post
58+
HttpCall<Repo> callBean();
59+
@Post
60+
HttpCall<List<Repo>> callList();
61+
@Post
62+
HttpCall<Stream<Repo>> callStream();
5163
// -------
5264

5365
// @Post CompletableFuture<Void> cfVoidErr();
@@ -108,4 +120,7 @@ public interface JunkApi {
108120
@Get
109121
HttpCall<HttpResponse<Path>> callWithHandPath(HttpResponse.BodyHandler<Path> handler);
110122

123+
@Post("/{id}/foo/{name}")
124+
HttpResponse<Path> reqBodyResHand2(HttpResponse.BodyHandler<Path> handler, HttpRequest.BodyPublisher body, String id, String name, String other);
125+
111126
}

0 commit comments

Comments
 (0)