12
12
13
13
package com .telstra ;
14
14
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 ;
19
19
import okio .BufferedSink ;
20
20
import okio .Okio ;
21
21
import org .threeten .bp .LocalDate ;
22
22
import org .threeten .bp .OffsetDateTime ;
23
23
import org .threeten .bp .format .DateTimeFormatter ;
24
-
25
24
import javax .net .ssl .*;
26
25
import java .io .File ;
27
26
import java .io .IOException ;
@@ -494,7 +493,7 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
494
493
* @return Timeout in milliseconds
495
494
*/
496
495
public int getConnectTimeout () {
497
- return httpClient .getConnectTimeout ();
496
+ return httpClient .connectTimeoutMillis ();
498
497
}
499
498
500
499
/**
@@ -505,7 +504,7 @@ public int getConnectTimeout() {
505
504
* @return Api client
506
505
*/
507
506
public ApiClient setConnectTimeout (int connectionTimeout ) {
508
- httpClient . setConnectTimeout ( connectionTimeout , TimeUnit .MILLISECONDS );
507
+ httpClient = httpClient . newBuilder (). connectTimeout ( connectionTimeout , TimeUnit .MILLISECONDS ). build ( );
509
508
return this ;
510
509
}
511
510
@@ -515,7 +514,7 @@ public ApiClient setConnectTimeout(int connectionTimeout) {
515
514
* @return Timeout in milliseconds
516
515
*/
517
516
public int getReadTimeout () {
518
- return httpClient .getReadTimeout ();
517
+ return httpClient .readTimeoutMillis ();
519
518
}
520
519
521
520
/**
@@ -527,7 +526,7 @@ public int getReadTimeout() {
527
526
* @return Api client
528
527
*/
529
528
public ApiClient setReadTimeout (int readTimeout ) {
530
- httpClient . setReadTimeout ( readTimeout , TimeUnit .MILLISECONDS );
529
+ httpClient = httpClient . newBuilder (). readTimeout ( readTimeout , TimeUnit .MILLISECONDS ). build ( );
531
530
return this ;
532
531
}
533
532
@@ -537,7 +536,7 @@ public ApiClient setReadTimeout(int readTimeout) {
537
536
* @return Timeout in milliseconds
538
537
*/
539
538
public int getWriteTimeout () {
540
- return httpClient .getWriteTimeout ();
539
+ return httpClient .writeTimeoutMillis ();
541
540
}
542
541
543
542
/**
@@ -549,7 +548,7 @@ public int getWriteTimeout() {
549
548
* @return Api client
550
549
*/
551
550
public ApiClient setWriteTimeout (int writeTimeout ) {
552
- httpClient . setWriteTimeout ( writeTimeout , TimeUnit .MILLISECONDS );
551
+ httpClient = httpClient . newBuilder (). writeTimeout ( writeTimeout , TimeUnit .MILLISECONDS ). build ( );
553
552
return this ;
554
553
}
555
554
@@ -940,12 +939,13 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
940
939
public <T > void executeAsync (Call call , final Type returnType , final ApiCallback <T > callback ) {
941
940
call .enqueue (new Callback () {
942
941
@ Override
943
- public void onFailure (Request request , IOException e ) {
942
+ public void onFailure (Call call , IOException e ) {
944
943
callback .onFailure (new ApiException (e ), 0 , null );
944
+
945
945
}
946
946
947
947
@ Override
948
- public void onResponse (Response response ) throws IOException {
948
+ public void onResponse (Call call , Response response ) throws IOException {
949
949
T result ;
950
950
try {
951
951
result = (T ) handleResponse (response , returnType );
@@ -972,14 +972,6 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
972
972
if (response .isSuccessful ()) {
973
973
if (returnType == null || response .code () == 204 ) {
974
974
// 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
- }
983
975
return null ;
984
976
} else {
985
977
return deserialize (response , returnType );
@@ -1165,7 +1157,7 @@ public void updateParamsForAuth(String[] authNames, List<Pair> queryParams, Map<
1165
1157
* @return RequestBody
1166
1158
*/
1167
1159
public RequestBody buildRequestBodyFormEncoding (Map <String , Object > formParams ) {
1168
- FormEncodingBuilder formBuilder = new FormEncodingBuilder ();
1160
+ FormBody . Builder formBuilder = new FormBody . Builder ();
1169
1161
for (Entry <String , Object > param : formParams .entrySet ()) {
1170
1162
formBuilder .add (param .getKey (), parameterToString (param .getValue ()));
1171
1163
}
@@ -1180,7 +1172,7 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
1180
1172
* @return RequestBody
1181
1173
*/
1182
1174
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 );
1184
1176
for (Entry <String , Object > param : formParams .entrySet ()) {
1185
1177
if (param .getValue () instanceof File ) {
1186
1178
File file = (File ) param .getValue ();
@@ -1254,11 +1246,11 @@ public void checkServerTrusted(X509Certificate[] chain, String authType) throws
1254
1246
if (keyManagers != null || trustManagers != null ) {
1255
1247
SSLContext sslContext = SSLContext .getInstance ("TLS" );
1256
1248
sslContext .init (keyManagers , trustManagers , new SecureRandom ());
1257
- httpClient . setSslSocketFactory ( sslContext .getSocketFactory ());
1249
+ httpClient = httpClient . newBuilder (). sslSocketFactory ( sslContext .getSocketFactory ()). build ( );
1258
1250
} else {
1259
- httpClient . setSslSocketFactory ( null );
1251
+ httpClient = httpClient . newBuilder (). sslSocketFactory ( null ). build ( );
1260
1252
}
1261
- httpClient . setHostnameVerifier ( hostnameVerifier );
1253
+ httpClient = httpClient . newBuilder (). hostnameVerifier ( hostnameVerifier ). build ( );
1262
1254
} catch (GeneralSecurityException e ) {
1263
1255
throw new RuntimeException (e );
1264
1256
}
0 commit comments