This project fork from Retrofit,I refactor project to make custom protocol( base TCP) 、volley、UrlConnection support restful api
You can use some call factories(UrlConnectionCallFactory / OkHttpCallFactory / VolleyCallFactory /CronetCallFactory)) to create call , and add you custom protocol to this project.
replace implementation com.squareup.retrofit2:retrofit:2.9.0
with implementation 'io.github.jamesfchen:retrofit:1.0.0'
implementation 'io.github.jamesfchen:callfactory-urlconnection:1.0.0'
Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new ToStringConverterFactory())
.callFactory(UrlConnectionCallFactory.create())
.build();
Service example = retrofit.create(Service.class);
server.enqueue(new MockResponse().setBody("Hi"));
Response<String> response = example.getString().execute();
assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isEqualTo("Hi");
implementation 'io.github.jamesfchen:callfactory-volley:1.0.0'
val api = Retrofit.Builder()
.baseUrl("....")
.addConverterFactory(GsonConverterFactory.create())
.callFactory(VolleyCallFactory.create(application))
.build().create(LocationApi::class.java)
1 case:
Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new ToStringConverterFactory())
.callFactory(OkHttpCallFactory.create())
.build();
Service example = retrofit.create(Service.class);
server.enqueue(new MockResponse().setBody("Hi"));
Response<String> response = example.getString().execute();
assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isEqualTo("Hi");
2 case:
OkHttpClient okHttpClient = OkHttpClient.Builder()
.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.pingInterval(1, TimeUnit.SECONDS)
.retryOnConnectionFailure(true)
.protocols(listOf(Protocol.HTTP_2))
.build()
Retrofit retrofit =
new Retrofit.Builder()
.baseUrl(server.url("/"))
.addConverterFactory(new ToStringConverterFactory())
.callFactory(OkHttpCallFactory.create(okHttpClient))
.build();
Service example = retrofit.create(Service.class);
server.enqueue(new MockResponse().setBody("Hi"));
Response<String> response = example.getString().execute();
assertThat(response.isSuccessful()).isTrue();
assertThat(response.body()).isEqualTo("Hi");
To Be Countinue...
To Be Countinue...