1212
1313package 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 ;
1919import okio .BufferedSink ;
2020import okio .Okio ;
2121import org .threeten .bp .LocalDate ;
2222import org .threeten .bp .OffsetDateTime ;
2323import org .threeten .bp .format .DateTimeFormatter ;
24-
2524import javax .net .ssl .*;
2625import java .io .File ;
2726import 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 }
0 commit comments