Skip to content

Commit 08cf5b2

Browse files
deps: Upgrade okhttp to 5.x (#203)
1 parent 59685f1 commit 08cf5b2

File tree

6 files changed

+36
-15
lines changed

6 files changed

+36
-15
lines changed

.github/workflows/run-tests.yml

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ jobs:
1414
matrix:
1515
java: [ "11", "17", "21" ]
1616
distribution: [ "zulu", "adopt" ]
17+
okhttp: [ "okhttp5", "okhttp4" ]
18+
include:
19+
- okhttp: "okhttp5"
20+
maven_profiles: ""
21+
- okhttp: "okhttp4"
22+
maven_profiles: "-P test-okhttp4"
1723

1824
steps:
1925
- name: Checkout repository
@@ -31,8 +37,8 @@ jobs:
3137
uses: actions/cache@v4
3238
with:
3339
path: ~/.m2
34-
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
40+
key: ${{ runner.os }}-m2-${{ matrix.okhttp }}-${{ hashFiles('**/pom.xml') }}
3541
restore-keys: ${{ runner.os }}-m2
3642

37-
- name: Build with Maven
38-
run: mvn clean install
43+
- name: Build with Maven (OkHttp ${{ matrix.okhttp }})
44+
run: mvn clean install ${{ matrix.maven_profiles }}

pom.xml

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,17 @@
4848
<slf4j.version>1.7.30</slf4j.version>
4949
<maven.checkstyle.version>3.4.0</maven.checkstyle.version>
5050
<junit.jupiter.version>5.14.0</junit.jupiter.version>
51+
<!-- OkHttp dependency coordinates — overridden by the test-okhttp4 profile -->
52+
<okhttp.artifactId>okhttp-jvm</okhttp.artifactId>
53+
<okhttp.version>5.0.0</okhttp.version>
54+
<okhttp.mockwebserver.version>5.0.0</okhttp.mockwebserver.version>
5155
</properties>
5256

5357
<dependencies>
5458
<dependency>
5559
<groupId>com.squareup.okhttp3</groupId>
56-
<artifactId>okhttp</artifactId>
57-
<version>4.12.0</version>
60+
<artifactId>${okhttp.artifactId}</artifactId>
61+
<version>${okhttp.version}</version>
5862
</dependency>
5963
<dependency>
6064
<groupId>com.jayway.jsonpath</groupId>
@@ -157,7 +161,7 @@
157161
<dependency>
158162
<groupId>com.squareup.okhttp3</groupId>
159163
<artifactId>mockwebserver</artifactId>
160-
<version>3.10.0</version>
164+
<version>${okhttp.mockwebserver.version}</version>
161165
<scope>test</scope>
162166
</dependency>
163167
<dependency>
@@ -173,9 +177,9 @@
173177
<version>1.14.17</version>
174178
</dependency>
175179
<dependency>
176-
<groupId>com.github.gmazzo</groupId>
177-
<artifactId>okhttp-mock</artifactId>
178-
<version>1.4.1</version>
180+
<groupId>com.github.gmazzo.okhttp.mock</groupId>
181+
<artifactId>mock-client</artifactId>
182+
<version>2.0.0</version>
179183
<scope>test</scope>
180184
</dependency>
181185
</dependencies>
@@ -368,5 +372,17 @@
368372
</plugins>
369373
</build>
370374
</profile>
375+
<profile>
376+
<!--
377+
Run the test suite against OkHttp 4.x to verify backward compatibility.
378+
Activate with: mvn test -P test-okhttp4
379+
-->
380+
<id>test-okhttp4</id>
381+
<properties>
382+
<okhttp.artifactId>okhttp</okhttp.artifactId>
383+
<okhttp.version>4.12.0</okhttp.version>
384+
<okhttp.mockwebserver.version>4.12.0</okhttp.mockwebserver.version>
385+
</properties>
386+
</profile>
371387
</profiles>
372388
</project>

src/main/java/com/flagsmith/FlagsmithApiWrapper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public Flags identifyUserWithTraits(
201201
node.putPOJO("traits", traits);
202202
}
203203

204-
MediaType json = MediaType.parse("application/json; charset=utf-8");
204+
MediaType json = MediaType.get("application/json; charset=utf-8");
205205
RequestBody body = RequestBody.create(node.toString(), json);
206206

207207
HttpUrl url = defaultConfig.getIdentitiesUri();

src/main/java/com/flagsmith/config/FlagsmithConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public final class FlagsmithConfig {
2828
private static final int DEFAULT_READ_TIMEOUT_MILLIS = 5000;
2929
private static final int DEFAULT_ENVIRONMENT_REFRESH_SECONDS = 60;
3030
private static final HttpUrl DEFAULT_BASE_URI = HttpUrl
31-
.parse("https://edge.api.flagsmith.com/api/v1/");
31+
.get("https://edge.api.flagsmith.com/api/v1/");
3232
private final HttpUrl flagsUri;
3333
private final HttpUrl identitiesUri;
3434
private final HttpUrl traitsUri;
@@ -129,7 +129,7 @@ private Builder() {
129129
*/
130130
public Builder baseUri(String baseUri) {
131131
if (baseUri != null) {
132-
this.baseUri = HttpUrl.parse(baseUri);
132+
this.baseUri = HttpUrl.get(baseUri);
133133
}
134134
return this;
135135
}

src/main/java/com/flagsmith/threads/AnalyticsProcessor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ public void flush() {
132132
return;
133133
}
134134

135-
MediaType json = MediaType.parse("application/json; charset=utf-8");
136-
RequestBody body = RequestBody.create(json, response);
135+
MediaType json = MediaType.get("application/json; charset=utf-8");
136+
RequestBody body = RequestBody.create(response, json);
137137

138138
Request request = api.newPostRequest(getAnalyticsUrl(), body);
139139

src/test/java/com/flagsmith/FlagsmithApiWrapperTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import okhttp3.Response;
3939
import okhttp3.ResponseBody;
4040
import okhttp3.mock.MockInterceptor;
41-
import org.bouncycastle.ocsp.Req;
4241
import org.junit.jupiter.api.BeforeEach;
4342
import org.junit.jupiter.api.Test;
4443

0 commit comments

Comments
 (0)