8

I have created a .proto message and I'm exposing a rest service which looks like this

@Path("/test")
public interface test{

@POST
@Produces("application/x-protobuf")
@Consumes("application/x-protobuf")
public Response getProperties(TestRequest testrq);
}

Now TestRequest being the Java generated file of .protobuf how do i pass it in request body ?

this will be be the .proto file format

message TestRequest
{
    string id = 1;
    string name = 2;
    enum TestType
    {
        Test=1
    }
   TestType testType = 3; 
}
4

2 回答 2

7

如果你需要一个简单的 protobuf api 客户端,试试Protoman

免责声明:这是我的副业

于 2020-03-01T00:32:47.537 回答
4

您可以使用此代码片段来测试 protobuf,因为我找不到 postman 或 dhcclient 的任何解决方案

URL url = new URL("https://localhost:8080/test");
HttpURLConnection urlc = (HttpURLConnection) url.openConnection();
urlc.setDoInput(true);
urlc.setDoOutput(true);
urlc.setRequestMethod("POST");
urlc.setRequestProperty("Accept", "application/x-protobuf");
urlc.setRequestProperty("Content-Type","application/x-protobuf");
TestRequestPb.TestRequest.Builder testRequestBuilder = TestRequestPb.TestRequest.newBuilder();
TestRequest testRequest = testRequestBuilder.build();
testRequest.writeTo(urlc.getOutputStream());

testRequest = TestRequest.newBuilder().mergeFrom(urlc.getInputStream()).build();
于 2016-10-04T10:09:32.367 回答