File tree Expand file tree Collapse file tree 5 files changed +26
-26
lines changed
network-client-okhttp/src/main/java/io/ably/lib/network Expand file tree Collapse file tree 5 files changed +26
-26
lines changed Original file line number Diff line number Diff line change 88 - main
99
1010jobs :
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
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()
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
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
Original file line number Diff line number Diff 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
149139The following example sets up a proxy using the Pub/Sub Java SDK:
150140
Original file line number Diff line number Diff 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
6262configurations {
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" ))
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 11package io .ably .lib .network ;
22
33import okhttp3 .Call ;
4+ import okhttp3 .MediaType ;
45import okhttp3 .Response ;
6+ import okhttp3 .ResponseBody ;
57
68import java .io .IOException ;
79import 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}
You can’t perform that action at this time.
0 commit comments