diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml
index 4399b06e..e8d68040 100644
--- a/.github/workflows/run-tests.yml
+++ b/.github/workflows/run-tests.yml
@@ -14,6 +14,12 @@ jobs:
matrix:
java: [ "11", "17", "21" ]
distribution: [ "zulu", "adopt" ]
+ okhttp: [ "okhttp5", "okhttp4" ]
+ include:
+ - okhttp: "okhttp5"
+ maven_profiles: ""
+ - okhttp: "okhttp4"
+ maven_profiles: "-P test-okhttp4"
steps:
- name: Checkout repository
@@ -31,8 +37,8 @@ jobs:
uses: actions/cache@v4
with:
path: ~/.m2
- key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
+ key: ${{ runner.os }}-m2-${{ matrix.okhttp }}-${{ hashFiles('**/pom.xml') }}
restore-keys: ${{ runner.os }}-m2
- - name: Build with Maven
- run: mvn clean install
+ - name: Build with Maven (OkHttp ${{ matrix.okhttp }})
+ run: mvn clean install ${{ matrix.maven_profiles }}
diff --git a/pom.xml b/pom.xml
index b088bcc8..284df292 100644
--- a/pom.xml
+++ b/pom.xml
@@ -48,13 +48,17 @@
1.7.30
3.4.0
5.14.0
+
+ okhttp-jvm
+ 5.0.0
+ 5.0.0
com.squareup.okhttp3
- okhttp
- 4.12.0
+ ${okhttp.artifactId}
+ ${okhttp.version}
com.jayway.jsonpath
@@ -157,7 +161,7 @@
com.squareup.okhttp3
mockwebserver
- 3.10.0
+ ${okhttp.mockwebserver.version}
test
@@ -173,9 +177,9 @@
1.14.17
- com.github.gmazzo
- okhttp-mock
- 1.4.1
+ com.github.gmazzo.okhttp.mock
+ mock-client
+ 2.0.0
test
@@ -368,5 +372,17 @@
+
+
+ test-okhttp4
+
+ okhttp
+ 4.12.0
+ 4.12.0
+
+
diff --git a/src/main/java/com/flagsmith/FlagsmithApiWrapper.java b/src/main/java/com/flagsmith/FlagsmithApiWrapper.java
index c1478f92..bb7f06af 100644
--- a/src/main/java/com/flagsmith/FlagsmithApiWrapper.java
+++ b/src/main/java/com/flagsmith/FlagsmithApiWrapper.java
@@ -201,7 +201,7 @@ public Flags identifyUserWithTraits(
node.putPOJO("traits", traits);
}
- MediaType json = MediaType.parse("application/json; charset=utf-8");
+ MediaType json = MediaType.get("application/json; charset=utf-8");
RequestBody body = RequestBody.create(node.toString(), json);
HttpUrl url = defaultConfig.getIdentitiesUri();
diff --git a/src/main/java/com/flagsmith/config/FlagsmithConfig.java b/src/main/java/com/flagsmith/config/FlagsmithConfig.java
index e2ea1a8a..ffb7357f 100644
--- a/src/main/java/com/flagsmith/config/FlagsmithConfig.java
+++ b/src/main/java/com/flagsmith/config/FlagsmithConfig.java
@@ -28,7 +28,7 @@ public final class FlagsmithConfig {
private static final int DEFAULT_READ_TIMEOUT_MILLIS = 5000;
private static final int DEFAULT_ENVIRONMENT_REFRESH_SECONDS = 60;
private static final HttpUrl DEFAULT_BASE_URI = HttpUrl
- .parse("https://edge.api.flagsmith.com/api/v1/");
+ .get("https://edge.api.flagsmith.com/api/v1/");
private final HttpUrl flagsUri;
private final HttpUrl identitiesUri;
private final HttpUrl traitsUri;
@@ -129,7 +129,7 @@ private Builder() {
*/
public Builder baseUri(String baseUri) {
if (baseUri != null) {
- this.baseUri = HttpUrl.parse(baseUri);
+ this.baseUri = HttpUrl.get(baseUri);
}
return this;
}
diff --git a/src/main/java/com/flagsmith/threads/AnalyticsProcessor.java b/src/main/java/com/flagsmith/threads/AnalyticsProcessor.java
index 58ddf412..da631f56 100644
--- a/src/main/java/com/flagsmith/threads/AnalyticsProcessor.java
+++ b/src/main/java/com/flagsmith/threads/AnalyticsProcessor.java
@@ -132,8 +132,8 @@ public void flush() {
return;
}
- MediaType json = MediaType.parse("application/json; charset=utf-8");
- RequestBody body = RequestBody.create(json, response);
+ MediaType json = MediaType.get("application/json; charset=utf-8");
+ RequestBody body = RequestBody.create(response, json);
Request request = api.newPostRequest(getAnalyticsUrl(), body);
diff --git a/src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java b/src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java
index ad4df9fb..14caf72c 100644
--- a/src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java
+++ b/src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java
@@ -38,7 +38,6 @@
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.mock.MockInterceptor;
-import org.bouncycastle.ocsp.Req;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;