Skip to content

Commit b3fbf0b

Browse files
committed
Wrap protobuf in Response object
1 parent bac1dfc commit b3fbf0b

File tree

4 files changed

+18
-17
lines changed

4 files changed

+18
-17
lines changed

plugin/src/main/java/com/flit/protoc/gen/server/jaxrs/RpcGenerator.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,16 @@ private void addHandleMethod(MethodDescriptorProto mdp) {
5656
.addMember("value", "$S", "/" + mdp.getName())
5757
.build())
5858
.addAnnotation(AnnotationSpec.builder(PRODUCES)
59-
.addMember("value", "$S", "application/protobuf")
59+
.addMember("value", "$S", "application/x-protobuf")
6060
.addMember("value", "$S", "application/json")
6161
.build())
6262
.addAnnotation(AnnotationSpec.builder(CONSUMES)
63-
.addMember("value", "$S", "application/protobuf")
63+
.addMember("value", "$S", "application/x-protobuf")
6464
.addMember("value", "$S", "application/json")
6565
.build())
6666
.addParameter(inputType, "request")
67-
.addStatement("return service.handle$L(request)", mdp.getName())
68-
.returns(outputType)
67+
.addStatement("return Response.ok(service.handle$L(request)).build()", mdp.getName())
68+
.returns(ClassName.bestGuess("javax.ws.rs.core.Response"))
6969
.build());
7070
}
7171

plugin/src/test/java/com/flit/protoc/gen/server/jaxrs/HelloworldGeneratorTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ public void test_Generate() throws Exception {
2222

2323
assertNotNull(response);
2424
assertEquals(2, response.getFileCount());
25-
System.out.println(response.getFile(0).getContent());
2625
assertEquals(response.getFile(0).getName(), "com/example/helloworld/RpcHelloWorld.java");
2726
assertEquals(response.getFile(1).getName(), "com/example/helloworld/RpcHelloWorldResource.java");
2827

plugin/src/test/java/com/flit/protoc/gen/server/jaxrs/HelloworldGeneratorTest.test_Generate.approved.txt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import javax.ws.rs.Consumes;
1212
import javax.ws.rs.POST;
1313
import javax.ws.rs.Path;
1414
import javax.ws.rs.Produces;
15+
import javax.ws.rs.core.Response;
1516

1617
@Path("/twirp/com.example.helloworld.HelloWorld")
1718
public class RpcHelloWorldResource {
@@ -24,29 +25,29 @@ public class RpcHelloWorldResource {
2425
@POST
2526
@Path("/Hello")
2627
@Produces({
27-
"application/protobuf",
28+
"application/x-protobuf",
2829
"application/json"
2930
})
3031
@Consumes({
31-
"application/protobuf",
32+
"application/x-protobuf",
3233
"application/json"
3334
})
34-
public Helloworld.HelloResp handleHello(Helloworld.HelloReq request) {
35-
return service.handleHello(request);
35+
public Response handleHello(Helloworld.HelloReq request) {
36+
return Response.ok(service.handleHello(request)).build();
3637
}
3738

3839
@POST
3940
@Path("/HelloAgain")
4041
@Produces({
41-
"application/protobuf",
42+
"application/x-protobuf",
4243
"application/json"
4344
})
4445
@Consumes({
45-
"application/protobuf",
46+
"application/x-protobuf",
4647
"application/json"
4748
})
48-
public Helloworld.HelloResp handleHelloAgain(Helloworld.HelloReq request) {
49-
return service.handleHelloAgain(request);
49+
public Response handleHelloAgain(Helloworld.HelloReq request) {
50+
return Response.ok(service.handleHelloAgain(request)).build();
5051
}
5152
}
5253

plugin/src/test/java/com/flit/protoc/gen/server/jaxrs/StatusGeneratorTest.test_Generate.approved.txt

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import javax.ws.rs.Consumes;
1010
import javax.ws.rs.POST;
1111
import javax.ws.rs.Path;
1212
import javax.ws.rs.Produces;
13+
import javax.ws.rs.core.Response;
1314

1415
@Path("/twirp/com.example.helloworld.Status")
1516
public class RpcStatusResource {
@@ -22,15 +23,15 @@ public class RpcStatusResource {
2223
@POST
2324
@Path("/GetStatus")
2425
@Produces({
25-
"application/protobuf",
26+
"application/x-protobuf",
2627
"application/json"
2728
})
2829
@Consumes({
29-
"application/protobuf",
30+
"application/x-protobuf",
3031
"application/json"
3132
})
32-
public StatusOuterClass.StatusResponse handleGetStatus(Core.Empty request) {
33-
return service.handleGetStatus(request);
33+
public Response handleGetStatus(Core.Empty request) {
34+
return Response.ok(service.handleGetStatus(request)).build();
3435
}
3536
}
3637

0 commit comments

Comments
 (0)