Skip to content

Commit fa2c6ca

Browse files
committed
update for okhttp3
1 parent f707a30 commit fa2c6ca

15 files changed

+206
-217
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ Add this dependency to your project's POM:
6868
<dependency>
6969
<groupId>com.telstra.messaging</groupId>
7070
<artifactId>telstra-messaging</artifactId>
71-
<version>3.2-SNAPSHOT</version>
71+
<version>3.3-SNAPSHOT</version>
7272
</dependency>
7373
```
7474

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ if(hasProperty('target') && target == 'android') {
9595

9696
dependencies {
9797
compile 'io.swagger.core.v3:swagger-annotations:2.0.0'
98-
compile 'com.squareup.okhttp:okhttp:2.7.5'
99-
compile 'com.squareup.okhttp:logging-interceptor:2.7.5'
98+
compile 'com.squareup.okhttp3:okhttp:4.12.0'
99+
compile 'com.squareup.okhttp3:logging-interceptor:4.12.0'
100100
compile 'com.google.code.gson:gson:2.8.1'
101101
compile 'io.gsonfire:gson-fire:1.8.3'
102102
compile 'org.threeten:threetenbp:1.3.5'

build.sbt

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ lazy val root = (project in file(".")).
1010
resolvers += Resolver.mavenLocal,
1111
libraryDependencies ++= Seq(
1212
"io.swagger.core.v3" % "swagger-annotations" % "2.0.0",
13-
"com.squareup.okhttp" % "okhttp" % "2.7.5",
14-
"com.squareup.okhttp" % "logging-interceptor" % "2.7.5",
13+
"com.squareup.okhttp3" % "okhttp" % "4.12.0",
14+
"com.squareup.okhttp3" % "logging-interceptor" % "4.12.0",
1515
"com.google.code.gson" % "gson" % "2.8.1",
1616
"io.gsonfire" % "gson-fire" % "1.8.3" % "compile",
1717
"org.threeten" % "threetenbp" % "1.3.5" % "compile",

pom.xml

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<artifactId>telstra-messaging</artifactId>
66
<packaging>jar</packaging>
77
<name>telstra-messaging</name>
8-
<version>3.2-SNAPSHOT</version>
8+
<version>3.3-SNAPSHOT</version>
99
<url>https://github.com/swagger-api/swagger-codegen</url>
1010
<description>Swagger Java</description>
1111
<scm>
@@ -170,12 +170,12 @@
170170
<version>${swagger-core-version}</version>
171171
</dependency>
172172
<dependency>
173-
<groupId>com.squareup.okhttp</groupId>
173+
<groupId>com.squareup.okhttp3</groupId>
174174
<artifactId>okhttp</artifactId>
175175
<version>${okhttp-version}</version>
176176
</dependency>
177177
<dependency>
178-
<groupId>com.squareup.okhttp</groupId>
178+
<groupId>com.squareup.okhttp3</groupId>
179179
<artifactId>logging-interceptor</artifactId>
180180
<version>${okhttp-version}</version>
181181
</dependency>
@@ -220,7 +220,7 @@
220220
<maven.compiler.source>${java.version}</maven.compiler.source>
221221
<maven.compiler.target>${java.version}</maven.compiler.target>
222222
<swagger-core-version>2.0.0</swagger-core-version>
223-
<okhttp-version>2.7.5</okhttp-version>
223+
<okhttp-version>4.12.0</okhttp-version>
224224
<gson-version>2.8.1</gson-version>
225225
<gson-fire-version>1.8.3</gson-fire-version>
226226
<threetenbp-version>1.3.5</threetenbp-version>

src/main/java/com/telstra/ApiClient.java

+18-26
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,15 @@
1212

1313
package com.telstra;
1414

15-
import com.squareup.okhttp.*;
16-
import com.squareup.okhttp.internal.http.HttpMethod;
17-
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
18-
import com.squareup.okhttp.logging.HttpLoggingInterceptor.Level;
15+
import okhttp3.*;
16+
import okhttp3.internal.http.HttpMethod;
17+
import okhttp3.logging.HttpLoggingInterceptor;
18+
import okhttp3.logging.HttpLoggingInterceptor.Level;
1919
import okio.BufferedSink;
2020
import okio.Okio;
2121
import org.threeten.bp.LocalDate;
2222
import org.threeten.bp.OffsetDateTime;
2323
import org.threeten.bp.format.DateTimeFormatter;
24-
2524
import javax.net.ssl.*;
2625
import java.io.File;
2726
import java.io.IOException;
@@ -494,7 +493,7 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
494493
* @return Timeout in milliseconds
495494
*/
496495
public int getConnectTimeout() {
497-
return httpClient.getConnectTimeout();
496+
return httpClient.connectTimeoutMillis();
498497
}
499498

500499
/**
@@ -505,7 +504,7 @@ public int getConnectTimeout() {
505504
* @return Api client
506505
*/
507506
public ApiClient setConnectTimeout(int connectionTimeout) {
508-
httpClient.setConnectTimeout(connectionTimeout, TimeUnit.MILLISECONDS);
507+
httpClient = httpClient.newBuilder().connectTimeout(connectionTimeout, TimeUnit.MILLISECONDS).build();
509508
return this;
510509
}
511510

@@ -515,7 +514,7 @@ public ApiClient setConnectTimeout(int connectionTimeout) {
515514
* @return Timeout in milliseconds
516515
*/
517516
public int getReadTimeout() {
518-
return httpClient.getReadTimeout();
517+
return httpClient.readTimeoutMillis();
519518
}
520519

521520
/**
@@ -527,7 +526,7 @@ public int getReadTimeout() {
527526
* @return Api client
528527
*/
529528
public ApiClient setReadTimeout(int readTimeout) {
530-
httpClient.setReadTimeout(readTimeout, TimeUnit.MILLISECONDS);
529+
httpClient = httpClient.newBuilder().readTimeout(readTimeout, TimeUnit.MILLISECONDS).build();
531530
return this;
532531
}
533532

@@ -537,7 +536,7 @@ public ApiClient setReadTimeout(int readTimeout) {
537536
* @return Timeout in milliseconds
538537
*/
539538
public int getWriteTimeout() {
540-
return httpClient.getWriteTimeout();
539+
return httpClient.writeTimeoutMillis();
541540
}
542541

543542
/**
@@ -549,7 +548,7 @@ public int getWriteTimeout() {
549548
* @return Api client
550549
*/
551550
public ApiClient setWriteTimeout(int writeTimeout) {
552-
httpClient.setWriteTimeout(writeTimeout, TimeUnit.MILLISECONDS);
551+
httpClient = httpClient.newBuilder().writeTimeout(writeTimeout, TimeUnit.MILLISECONDS).build();
553552
return this;
554553
}
555554

@@ -940,12 +939,13 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
940939
public <T> void executeAsync(Call call, final Type returnType, final ApiCallback<T> callback) {
941940
call.enqueue(new Callback() {
942941
@Override
943-
public void onFailure(Request request, IOException e) {
942+
public void onFailure(Call call, IOException e) {
944943
callback.onFailure(new ApiException(e), 0, null);
944+
945945
}
946946

947947
@Override
948-
public void onResponse(Response response) throws IOException {
948+
public void onResponse(Call call, Response response) throws IOException {
949949
T result;
950950
try {
951951
result = (T) handleResponse(response, returnType);
@@ -972,14 +972,6 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
972972
if (response.isSuccessful()) {
973973
if (returnType == null || response.code() == 204) {
974974
// returning null if the returnType is not defined,
975-
// or the status code is 204 (No Content)
976-
if (response.body() != null) {
977-
try {
978-
response.body().close();
979-
} catch (IOException e) {
980-
throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap());
981-
}
982-
}
983975
return null;
984976
} else {
985977
return deserialize(response, returnType);
@@ -1165,7 +1157,7 @@ public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<
11651157
* @return RequestBody
11661158
*/
11671159
public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams) {
1168-
FormEncodingBuilder formBuilder = new FormEncodingBuilder();
1160+
FormBody.Builder formBuilder = new FormBody.Builder();
11691161
for (Entry<String, Object> param : formParams.entrySet()) {
11701162
formBuilder.add(param.getKey(), parameterToString(param.getValue()));
11711163
}
@@ -1180,7 +1172,7 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
11801172
* @return RequestBody
11811173
*/
11821174
public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
1183-
MultipartBuilder mpBuilder = new MultipartBuilder().type(MultipartBuilder.FORM);
1175+
MultipartBody.Builder mpBuilder = new MultipartBody.Builder().setType(MultipartBody.FORM);
11841176
for (Entry<String, Object> param : formParams.entrySet()) {
11851177
if (param.getValue() instanceof File) {
11861178
File file = (File) param.getValue();
@@ -1254,11 +1246,11 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
12541246
if (keyManagers != null || trustManagers != null) {
12551247
SSLContext sslContext = SSLContext.getInstance("TLS");
12561248
sslContext.init(keyManagers, trustManagers, new SecureRandom());
1257-
httpClient.setSslSocketFactory(sslContext.getSocketFactory());
1249+
httpClient = httpClient.newBuilder().sslSocketFactory(sslContext.getSocketFactory()).build();
12581250
} else {
1259-
httpClient.setSslSocketFactory(null);
1251+
httpClient = httpClient.newBuilder().sslSocketFactory(null).build();
12601252
}
1261-
httpClient.setHostnameVerifier(hostnameVerifier);
1253+
httpClient = httpClient.newBuilder().hostnameVerifier(hostnameVerifier).build();
12621254
} catch (GeneralSecurityException e) {
12631255
throw new RuntimeException(e);
12641256
}

src/main/java/com/telstra/GzipRequestInterceptor.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
package com.telstra;
1414

15-
import com.squareup.okhttp.*;
15+
import okhttp3.*;
1616
import okio.Buffer;
1717
import okio.BufferedSink;
1818
import okio.GzipSink;

src/main/java/com/telstra/ProgressRequestBody.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212

1313
package com.telstra;
1414

15-
import com.squareup.okhttp.MediaType;
16-
import com.squareup.okhttp.RequestBody;
15+
import okhttp3.MediaType;
16+
import okhttp3.RequestBody;
1717

1818
import java.io.IOException;
1919

src/main/java/com/telstra/ProgressResponseBody.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@
1111
*/
1212

1313
package com.telstra;
14-
15-
import com.squareup.okhttp.MediaType;
16-
import com.squareup.okhttp.ResponseBody;
14+
import okhttp3.MediaType;
15+
import okhttp3.ResponseBody;
1716

1817
import java.io.IOException;
1918

@@ -44,12 +43,12 @@ public MediaType contentType() {
4443
}
4544

4645
@Override
47-
public long contentLength() throws IOException {
46+
public long contentLength() {
4847
return responseBody.contentLength();
4948
}
5049

5150
@Override
52-
public BufferedSource source() throws IOException {
51+
public BufferedSource source() {
5352
if (bufferedSource == null) {
5453
bufferedSource = Okio.buffer(source(responseBody.source()));
5554
}

src/main/java/com/telstra/auth/HttpBasicAuth.java

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@
1313
package com.telstra.auth;
1414

1515
import com.telstra.Pair;
16-
17-
import com.squareup.okhttp.Credentials;
18-
16+
import okhttp3.*;
1917
import java.util.Map;
2018
import java.util.List;
2119

src/main/java/com/telstra/messaging/AuthenticationApi.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static ApiClient getAuthToken(ApiClient apiClient) {
8888
* @return Call to execute
8989
* @throws ApiException If fail to serialize the request body object
9090
*/
91-
public com.squareup.okhttp.Call authTokenCall(String clientId, String clientSecret, String grantType, String scope, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
91+
public okhttp3.Call authTokenCall(String clientId, String clientSecret, String grantType, String scope, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
9292
Object localVarPostBody = null;
9393

9494
// create path and map variables
@@ -122,10 +122,10 @@ public com.squareup.okhttp.Call authTokenCall(String clientId, String clientSecr
122122
localVarHeaderParams.put("Content-Type", localVarContentType);
123123

124124
if(progressListener != null) {
125-
apiClient.getHttpClient().networkInterceptors().add(new com.squareup.okhttp.Interceptor() {
125+
apiClient.getHttpClient().networkInterceptors().add(new okhttp3.Interceptor() {
126126
@Override
127-
public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Chain chain) throws IOException {
128-
com.squareup.okhttp.Response originalResponse = chain.proceed(chain.request());
127+
public okhttp3.Response intercept(okhttp3.Interceptor.Chain chain) throws IOException {
128+
okhttp3.Response originalResponse = chain.proceed(chain.request());
129129
return originalResponse.newBuilder()
130130
.body(new ProgressResponseBody(originalResponse.body(), progressListener))
131131
.build();
@@ -138,7 +138,7 @@ public com.squareup.okhttp.Response intercept(com.squareup.okhttp.Interceptor.Ch
138138
}
139139

140140
@SuppressWarnings("rawtypes")
141-
private com.squareup.okhttp.Call authTokenValidateBeforeCall(String clientId, String clientSecret, String grantType, String scope, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
141+
private okhttp3.Call authTokenValidateBeforeCall(String clientId, String clientSecret, String grantType, String scope, final ProgressResponseBody.ProgressListener progressListener, final ProgressRequestBody.ProgressRequestListener progressRequestListener) throws ApiException {
142142
// verify the required parameter 'clientId' is set
143143
if (clientId == null) {
144144
throw new ApiException("Missing the required parameter 'clientId' when calling authToken(Async)");
@@ -156,7 +156,7 @@ private com.squareup.okhttp.Call authTokenValidateBeforeCall(String clientId, St
156156
throw new ApiException("Missing the required parameter 'scope' when calling authToken(Async)");
157157
}
158158

159-
com.squareup.okhttp.Call call = authTokenCall(clientId, clientSecret, grantType, scope, progressListener, progressRequestListener);
159+
okhttp3.Call call = authTokenCall(clientId, clientSecret, grantType, scope, progressListener, progressRequestListener);
160160
return call;
161161
}
162162

@@ -186,7 +186,7 @@ public OAuth authToken(String clientId, String clientSecret, String grantType, S
186186
* @throws ApiException If fail to call the API, e.g. server error or cannot deserialize the response body
187187
*/
188188
public ApiResponse<OAuth> authTokenWithHttpInfo(String clientId, String clientSecret, String grantType, String scope) throws ApiException {
189-
com.squareup.okhttp.Call call = authTokenValidateBeforeCall(clientId, clientSecret, grantType, scope, null, null);
189+
okhttp3.Call call = authTokenValidateBeforeCall(clientId, clientSecret, grantType, scope, null, null);
190190
Type localVarReturnType = new TypeToken<OAuth>(){}.getType();
191191
return apiClient.execute(call, localVarReturnType);
192192
}
@@ -202,7 +202,7 @@ public ApiResponse<OAuth> authTokenWithHttpInfo(String clientId, String clientSe
202202
* @return The request call
203203
* @throws ApiException If fail to process the API call, e.g. serializing the request body object
204204
*/
205-
public com.squareup.okhttp.Call authTokenAsync(String clientId, String clientSecret, String grantType, String scope, final ApiCallback<OAuth> callback) throws ApiException {
205+
public okhttp3.Call authTokenAsync(String clientId, String clientSecret, String grantType, String scope, final ApiCallback<OAuth> callback) throws ApiException {
206206

207207
ProgressResponseBody.ProgressListener progressListener = null;
208208
ProgressRequestBody.ProgressRequestListener progressRequestListener = null;
@@ -223,7 +223,7 @@ public void onRequestProgress(long bytesWritten, long contentLength, boolean don
223223
};
224224
}
225225

226-
com.squareup.okhttp.Call call = authTokenValidateBeforeCall(clientId, clientSecret, grantType, scope, progressListener, progressRequestListener);
226+
okhttp3.Call call = authTokenValidateBeforeCall(clientId, clientSecret, grantType, scope, progressListener, progressRequestListener);
227227
Type localVarReturnType = new TypeToken<OAuth>(){}.getType();
228228
apiClient.executeAsync(call, localVarReturnType, callback);
229229
return call;

0 commit comments

Comments
 (0)