Retrofit and GRPC

Viewed 2713

Been tackling this for two days. I'm trying to use the ProtoConverterFactory with gRPC but not having any luck with it.

public class RetrofitService {
    public void makeRequest() {

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://myurl:444")
                .addConverterFactory(ProtoConverterFactory.create())
                .build();

        RetrofitServiceImp serviceImp = retrofit.create(RetrofitServiceImp.class);
        serviceImp.getToken(Empty.getDefaultInstance()).enqueue(new Callback<Token.TokenResponse>() {
            @Override
            public void onResponse(Call<Token.TokenResponse> call, Response<Token.TokenResponse> response) {
                Log.d("SUCCESS", "onResponse: ");
            }

            @Override
            public void onFailure(Call<Token.TokenResponse> call, Throwable t) {
                Log.d("ERROR", "onFailure: " + t.getLocalizedMessage() + t.getMessage());
            }
        });
    }

    interface RetrofitServiceImp {

        @POST("/")
        Call<Token.TokenResponse> getToken(@Body Empty empty);

    }
}

There are no examples of how to do this correctly so I tried following the Unit Tests in the converter factory.

https://github.com/square/retrofit/blob/master/retrofit-converters/protobuf/src/test/java/retrofit2/converter/protobuf/ProtoConverterFactoryTest.java

How do I link the compiled gRPC code to the converter or the retrofit lib?

2 Answers
Related