Skip to content

Commit cc1cd37

Browse files
committed
refactor: replace default network client with OkHttp and adjust proxy support setup
- Updated build scripts to use `network-client-okhttp` by default where appropriate. - Revised README to simplify proxy setup instructions. - Adjusted integration workflows to correctly configure HTTP client preferences.
1 parent 4f354a8 commit cc1cd37

File tree

5 files changed

+26
-26
lines changed

5 files changed

+26
-26
lines changed

.github/workflows/integration-test.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ on:
88
- main
99

1010
jobs:
11-
check-rest:
11+
check-rest-httpurlconnection:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v4
@@ -24,15 +24,15 @@ jobs:
2424
- name: Set up Gradle
2525
uses: gradle/actions/setup-gradle@v3
2626

27-
- run: ./gradlew :java:testRestSuite
27+
- run: ./gradlew :java:testRestSuite -PhttpURLConnection
2828

2929
- uses: actions/upload-artifact@v4
3030
if: always()
3131
with:
3232
name: java-build-reports-rest
3333
path: java/build/reports/
3434

35-
check-realtime:
35+
check-realtime-httpurlconnection:
3636
runs-on: ubuntu-latest
3737
steps:
3838
- uses: actions/checkout@v4
@@ -48,7 +48,7 @@ jobs:
4848
- name: Set up Gradle
4949
uses: gradle/actions/setup-gradle@v3
5050

51-
- run: ./gradlew :java:testRealtimeSuite
51+
- run: ./gradlew :java:testRealtimeSuite -PhttpURLConnection
5252

5353
- uses: actions/upload-artifact@v4
5454
if: always()
@@ -71,7 +71,7 @@ jobs:
7171
- name: Set up Gradle
7272
uses: gradle/actions/setup-gradle@v3
7373

74-
- run: ./gradlew :java:testRestSuite -Pokhttp
74+
- run: ./gradlew :java:testRestSuite
7575

7676
check-realtime-okhttp:
7777
runs-on: ubuntu-latest
@@ -89,7 +89,7 @@ jobs:
8989
- name: Set up Gradle
9090
uses: gradle/actions/setup-gradle@v3
9191

92-
- run: ./gradlew :java:testRealtimeSuite -Pokhttp
92+
- run: ./gradlew :java:testRealtimeSuite
9393

9494
check-liveobjects:
9595
runs-on: ubuntu-latest

README.md

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,17 +134,7 @@ You can add proxy support to the Ably Java SDK by configuring `ProxyOptions` in
134134
<details>
135135
<summary>Proxy support setup details.</summary>
136136

137-
To enable proxy support for both REST and Realtime clients in the Ably SDK, use the OkHttp library to handle HTTP requests and WebSocket connections.
138-
139-
Add the following dependency to your `build.gradle` file:
140-
141-
```groovy
142-
dependencies {
143-
runtimeOnly("io.ably:network-client-okhttp:1.4.2")
144-
}
145-
```
146-
147-
After adding the OkHttp dependency, enable proxy support by specifying proxy settings in the ClientOptions when initializing your Ably client.
137+
Enable proxy support by specifying proxy settings in the ClientOptions when initializing your Ably client.
148138

149139
The following example sets up a proxy using the Pub/Sub Java SDK:
150140

android/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,17 @@ dependencies {
5454
compileOnly(libs.jetbrains)
5555
testImplementation(libs.bundles.tests)
5656
implementation(project(":network-client-core"))
57-
runtimeOnly(project(":network-client-default"))
57+
runtimeOnly(project(":network-client-okhttp"))
5858
implementation(libs.firebase.messaging)
5959
androidTestImplementation(libs.bundles.instrumental.android)
6060
}
6161

6262
configurations {
6363
all {
6464
exclude(group = "org.hamcrest", module = "hamcrest-core")
65+
resolutionStrategy {
66+
force(libs.jetbrains)
67+
}
6568
}
6669
getByName("androidTestImplementation") {
6770
extendsFrom(configurations.getByName("testImplementation"))

java/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ dependencies {
2222
implementation(libs.bundles.common)
2323
compileOnly(libs.jetbrains)
2424
implementation(project(":network-client-core"))
25-
if (findProperty("okhttp") == null) {
26-
runtimeOnly(project(":network-client-default"))
27-
} else {
25+
if (findProperty("httpURLConnection") == null) {
2826
runtimeOnly(project(":network-client-okhttp"))
27+
} else {
28+
runtimeOnly(project(":network-client-default"))
2929
}
3030
testImplementation(libs.bundles.tests)
3131
}

network-client-okhttp/src/main/java/io/ably/lib/network/OkHttpCall.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package io.ably.lib.network;
22

33
import okhttp3.Call;
4+
import okhttp3.MediaType;
45
import okhttp3.Response;
6+
import okhttp3.ResponseBody;
57

68
import java.io.IOException;
79
import java.net.ConnectException;
@@ -23,11 +25,7 @@ public HttpResponse execute() {
2325
.headers(response.headers().toMultimap())
2426
.code(response.code())
2527
.message(response.message())
26-
.body(
27-
response.body() != null && response.body().contentType() != null
28-
? new HttpBody(response.body().contentType().toString(), response.body().bytes())
29-
: null
30-
)
28+
.body(buildHttpBody(response))
3129
.build();
3230

3331
} catch (ConnectException | SocketTimeoutException | UnknownHostException | NoRouteToHostException fce) {
@@ -42,4 +40,13 @@ public HttpResponse execute() {
4240
public void cancel() {
4341
call.cancel();
4442
}
43+
44+
private HttpBody buildHttpBody(Response response) throws IOException {
45+
try (ResponseBody body = response.body()) {
46+
MediaType contentType = body != null ? body.contentType() : null;
47+
return contentType != null
48+
? new HttpBody(contentType.toString(), body.bytes())
49+
: null;
50+
}
51+
}
4552
}

0 commit comments

Comments
 (0)