Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/emulate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
emulator-options: -no-snapshot-save -no-window -gpu swiftshader_indirect -noaudio -no-boot-anim -camera-back none
disable-animations: true
# Print emulator logs if tests fail
script: ./gradlew :android:connectedAndroidTest || (adb logcat -d System.out:I && exit 1)
script: ./gradlew :android:connectedAndroidTest ${{ matrix.android-api-level == 19 && '-PhttpURLConnection' || '' }} || (adb logcat -d System.out:I && exit 1)

- uses: actions/upload-artifact@v4
if: always()
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
- main

jobs:
check-rest:
check-rest-httpurlconnection:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -24,15 +24,15 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- run: ./gradlew :java:testRestSuite
- run: ./gradlew :java:testRestSuite -PhttpURLConnection

- uses: actions/upload-artifact@v4
if: always()
with:
name: java-build-reports-rest
path: java/build/reports/

check-realtime:
check-realtime-httpurlconnection:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -48,7 +48,7 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- run: ./gradlew :java:testRealtimeSuite
- run: ./gradlew :java:testRealtimeSuite -PhttpURLConnection

- uses: actions/upload-artifact@v4
if: always()
Expand All @@ -71,7 +71,7 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- run: ./gradlew :java:testRestSuite -Pokhttp
- run: ./gradlew :java:testRestSuite

check-realtime-okhttp:
runs-on: ubuntu-latest
Expand All @@ -89,7 +89,7 @@ jobs:
- name: Set up Gradle
uses: gradle/actions/setup-gradle@v3

- run: ./gradlew :java:testRealtimeSuite -Pokhttp
- run: ./gradlew :java:testRealtimeSuite

check-liveobjects:
runs-on: ubuntu-latest
Expand Down
12 changes: 1 addition & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,17 +134,7 @@ You can add proxy support to the Ably Java SDK by configuring `ProxyOptions` in
<details>
<summary>Proxy support setup details.</summary>

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.

Add the following dependency to your `build.gradle` file:

```groovy
dependencies {
runtimeOnly("io.ably:network-client-okhttp:1.4.2")
}
```

After adding the OkHttp dependency, enable proxy support by specifying proxy settings in the ClientOptions when initializing your Ably client.
Enable proxy support by specifying proxy settings in the ClientOptions when initializing your Ably client.

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

Expand Down
9 changes: 8 additions & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,21 @@ dependencies {
compileOnly(libs.jetbrains)
testImplementation(libs.bundles.tests)
implementation(project(":network-client-core"))
runtimeOnly(project(":network-client-default"))
if (findProperty("httpURLConnection") == null) {
runtimeOnly(project(":network-client-okhttp"))
} else {
runtimeOnly(project(":network-client-default"))
}
implementation(libs.firebase.messaging)
androidTestImplementation(libs.bundles.instrumental.android)
}

configurations {
all {
exclude(group = "org.hamcrest", module = "hamcrest-core")
resolutionStrategy {
force(libs.jetbrains)
}
}
getByName("androidTestImplementation") {
extendsFrom(configurations.getByName("testImplementation"))
Expand Down
6 changes: 3 additions & 3 deletions java/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ dependencies {
implementation(libs.bundles.common)
compileOnly(libs.jetbrains)
implementation(project(":network-client-core"))
if (findProperty("okhttp") == null) {
runtimeOnly(project(":network-client-default"))
} else {
if (findProperty("httpURLConnection") == null) {
runtimeOnly(project(":network-client-okhttp"))
} else {
runtimeOnly(project(":network-client-default"))
}
testImplementation(libs.bundles.tests)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.ably.lib.network;

import okhttp3.Call;
import okhttp3.MediaType;
import okhttp3.Response;
import okhttp3.ResponseBody;

import java.io.IOException;
import java.net.ConnectException;
Expand All @@ -23,11 +25,7 @@ public HttpResponse execute() {
.headers(response.headers().toMultimap())
.code(response.code())
.message(response.message())
.body(
response.body() != null && response.body().contentType() != null
? new HttpBody(response.body().contentType().toString(), response.body().bytes())
: null
)
.body(buildHttpBody(response))
.build();

} catch (ConnectException | SocketTimeoutException | UnknownHostException | NoRouteToHostException fce) {
Expand All @@ -42,4 +40,13 @@ public HttpResponse execute() {
public void cancel() {
call.cancel();
}

private HttpBody buildHttpBody(Response response) throws IOException {
try (ResponseBody body = response.body()) {
MediaType contentType = body != null ? body.contentType() : null;
return contentType != null
? new HttpBody(contentType.toString(), body.bytes())
: null;
}
}
}
Loading