11package com .aspose .barcode .cloud ;
22
33import com .aspose .barcode .cloud .model .ApiErrorResponse ;
4- import com . squareup . okhttp . Call ;
5- import com . squareup . okhttp . Callback ;
6- import com . squareup . okhttp . FormEncodingBuilder ;
7- import com . squareup . okhttp .Headers ;
8- import com . squareup . okhttp .MediaType ;
9- import com . squareup . okhttp . MultipartBuilder ;
10- import com . squareup . okhttp .OkHttpClient ;
11- import com . squareup . okhttp .Request ;
12- import com . squareup . okhttp .RequestBody ;
13- import com . squareup . okhttp .Response ;
14- import com . squareup . okhttp .internal .http .HttpMethod ;
15- import com . squareup . okhttp .logging .HttpLoggingInterceptor ;
16- import com . squareup . okhttp .logging .HttpLoggingInterceptor .Level ;
4+
5+ import okhttp3 . Call ;
6+ import okhttp3 . FormBody ;
7+ import okhttp3 .Headers ;
8+ import okhttp3 .MediaType ;
9+ import okhttp3 . MultipartBody ;
10+ import okhttp3 .OkHttpClient ;
11+ import okhttp3 .Request ;
12+ import okhttp3 .RequestBody ;
13+ import okhttp3 .Response ;
14+ import okhttp3 .internal .http .HttpMethod ;
15+ import okhttp3 .logging .HttpLoggingInterceptor ;
16+ import okhttp3 .logging .HttpLoggingInterceptor .Level ;
1717
1818import okio .BufferedSink ;
1919import okio .Okio ;
4141/** ApiClient. */
4242public class ApiClient {
4343 public final String apiVersion = "v3.0" ;
44- public final String clientVersion = "24.9 .0" ;
44+ public final String clientVersion = "24.10 .0" ;
4545
4646 private String baseUrl = "https://api.aspose.cloud" ;
4747 private String tokenUrl = baseUrl + "/connect/token" ;
@@ -50,7 +50,7 @@ public class ApiClient {
5050 private boolean debugging = false ;
5151 private final Map <String , String > defaultHeaderMap = new HashMap <>();
5252 private String tempFolderPath = null ;
53- private final OkHttpClient httpClient ;
53+ private OkHttpClient httpClient ;
5454 private final JSON json ;
5555 private HttpLoggingInterceptor loggingInterceptor ;
5656 private String accessToken ;
@@ -79,17 +79,24 @@ public ApiClient(String clientId, String clientSecret, String baseUrl, String to
7979 }
8080 }
8181
82- protected ApiClient () {
83- httpClient = new OkHttpClient ();
82+ /** Constructor for ApiClient with readTimeout */
83+ protected ApiClient (long readTimeoutMillis ) {
84+ httpClient =
85+ new OkHttpClient .Builder ()
86+ .readTimeout (readTimeoutMillis , TimeUnit .MILLISECONDS )
87+ .build ();
8488
8589 json = new JSON ();
8690
8791 // Set default User-Agent.
88- setUserAgent ("Swagger-Codegen/24.9 .0/java" );
92+ setUserAgent ("Swagger-Codegen/24.10 .0/java" );
8993
9094 addDefaultHeader ("x-aspose-client" , "java sdk" );
9195 addDefaultHeader ("x-aspose-client-version" , clientVersion );
92- setReadTimeout (60_000 );
96+ }
97+
98+ protected ApiClient () {
99+ this (60_000 );
93100 }
94101
95102 /**
@@ -197,17 +204,7 @@ public void setTempFolderPath(String tempFolderPath) {
197204 * @return Timeout in milliseconds
198205 */
199206 public int getConnectTimeout () {
200- return httpClient .getConnectTimeout ();
201- }
202-
203- /**
204- * Sets the connect timeout (in milliseconds). A value of 0 means no timeout, otherwise values
205- * must be between 1 and {@link Integer#MAX_VALUE}.
206- *
207- * @param connectionTimeout connection timeout in milliseconds
208- */
209- public void setConnectTimeout (int connectionTimeout ) {
210- httpClient .setConnectTimeout (connectionTimeout , TimeUnit .MILLISECONDS );
207+ return httpClient .connectTimeoutMillis ();
211208 }
212209
213210 /**
@@ -216,7 +213,7 @@ public void setConnectTimeout(int connectionTimeout) {
216213 * @return Timeout in milliseconds
217214 */
218215 public int getReadTimeout () {
219- return httpClient .getReadTimeout ();
216+ return httpClient .readTimeoutMillis ();
220217 }
221218
222219 /**
@@ -226,7 +223,8 @@ public int getReadTimeout() {
226223 * @param readTimeout read timeout in milliseconds
227224 */
228225 public void setReadTimeout (int readTimeout ) {
229- httpClient .setReadTimeout (readTimeout , TimeUnit .MILLISECONDS );
226+ httpClient =
227+ new OkHttpClient .Builder ().readTimeout (readTimeout , TimeUnit .MILLISECONDS ).build ();
230228 }
231229
232230 /**
@@ -235,17 +233,7 @@ public void setReadTimeout(int readTimeout) {
235233 * @return Timeout in milliseconds
236234 */
237235 public int getWriteTimeout () {
238- return httpClient .getWriteTimeout ();
239- }
240-
241- /**
242- * Sets the write timeout (in milliseconds). A value of 0 means no timeout, otherwise values
243- * must be between 1 and {@link Integer#MAX_VALUE}.
244- *
245- * @param writeTimeout connection timeout in milliseconds
246- */
247- public void setWriteTimeout (int writeTimeout ) {
248- httpClient .setWriteTimeout (writeTimeout , TimeUnit .MILLISECONDS );
236+ return httpClient .writeTimeoutMillis ();
249237 }
250238
251239 /**
@@ -265,7 +253,7 @@ public String parameterToString(Object param) {
265253 return jsonStr .substring (1 , jsonStr .length () - 1 );
266254 } else if (param instanceof Collection ) {
267255 StringBuilder b = new StringBuilder ();
268- for (Object o : (Collection ) param ) {
256+ for (Object o : (Collection < Object > ) param ) {
269257 if (b .length () > 0 ) {
270258 b .append ("," );
271259 }
@@ -499,18 +487,18 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
499487 public RequestBody serialize (Object obj , String contentType ) throws ApiException {
500488 if (obj instanceof byte []) {
501489 // Binary (byte array) body parameter support.
502- return RequestBody .create (MediaType . parse ( contentType ), ( byte []) obj );
490+ return RequestBody .create (( byte []) obj , MediaType . parse ( contentType ) );
503491 } else if (obj instanceof File ) {
504492 // File body parameter support.
505- return RequestBody .create (MediaType .parse (contentType ), ( File ) obj );
493+ return RequestBody .create (( File ) obj , MediaType .parse (contentType ));
506494 } else if (isJsonMime (contentType )) {
507495 String content ;
508496 if (obj != null ) {
509497 content = json .serialize (obj );
510498 } else {
511499 content = null ;
512500 }
513- return RequestBody .create (MediaType .parse (contentType ), content );
501+ return RequestBody .create (content , MediaType .parse (contentType ));
514502 } else {
515503 throw new ApiException ("Content type \" " + contentType + "\" is not supported" );
516504 }
@@ -630,14 +618,14 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
630618 */
631619 public <T > void executeAsync (Call call , final Type returnType , final ApiCallback <T > callback ) {
632620 call .enqueue (
633- new Callback () {
621+ new okhttp3 . Callback () {
634622 @ Override
635- public void onFailure (Request request , IOException e ) {
623+ public void onFailure (Call call , IOException e ) {
636624 callback .onFailure (new ApiException (e ), 0 , null );
637625 }
638626
639627 @ Override
640- public void onResponse (Response response ) {
628+ public void onResponse (Call call , Response response ) {
641629 T result ;
642630 try {
643631 result = handleResponse (response , returnType );
@@ -668,7 +656,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
668656 if (response .body () != null ) {
669657 try {
670658 response .body ().close ();
671- } catch (IOException e ) {
659+ } catch (Exception e ) {
672660 throw new ApiException (
673661 response .message (),
674662 e ,
@@ -683,6 +671,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
683671 if (response .body () == null ) {
684672 throw new ApiException (response .message (), response .code ());
685673 }
674+
686675 ApiErrorResponse errorResponse ;
687676 try {
688677 errorResponse = deserialize (response , ApiErrorResponse .class );
@@ -774,7 +763,7 @@ public Request buildRequest(
774763 if (!HttpMethod .permitsRequestBody (method )) {
775764 reqBody = null ;
776765 } else if ("application/x-www-form-urlencoded" .equals (contentType )) {
777- reqBody = buildRequestBodyFormEncoding (formParams );
766+ reqBody = buildRequestBodyForm (formParams );
778767 } else if ("multipart/form-data" .equals (contentType )) {
779768 reqBody = buildRequestBodyMultipart (formParams );
780769 } else if (body == null ) {
@@ -783,7 +772,7 @@ public Request buildRequest(
783772 reqBody = null ;
784773 } else {
785774 // use an empty request body (for POST, PUT and PATCH)
786- reqBody = RequestBody .create (MediaType .parse (contentType ), "" );
775+ reqBody = RequestBody .create ("" , MediaType .parse (contentType ));
787776 }
788777 } else {
789778 reqBody = serialize (body , contentType );
@@ -876,8 +865,8 @@ public void processHeaderParams(Map<String, String> headerParams, Request.Builde
876865 * @param formParams Form parameters in the form of Map
877866 * @return RequestBody
878867 */
879- public RequestBody buildRequestBodyFormEncoding (Map <String , Object > formParams ) {
880- FormEncodingBuilder formBuilder = new FormEncodingBuilder ();
868+ public RequestBody buildRequestBodyForm (Map <String , Object > formParams ) {
869+ FormBody . Builder formBuilder = new FormBody . Builder ();
881870 for (Entry <String , Object > param : formParams .entrySet ()) {
882871 formBuilder .add (param .getKey (), parameterToString (param .getValue ()));
883872 }
@@ -892,7 +881,7 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
892881 * @return RequestBody
893882 */
894883 public RequestBody buildRequestBodyMultipart (Map <String , Object > formParams ) {
895- MultipartBuilder mpBuilder = new MultipartBuilder ().type ( MultipartBuilder .FORM );
884+ MultipartBody . Builder mpBuilder = new MultipartBody . Builder ().setType ( MultipartBody .FORM );
896885 for (Entry <String , Object > param : formParams .entrySet ()) {
897886 Object paramValue = param .getValue ();
898887 if (paramValue instanceof File ) {
@@ -906,7 +895,7 @@ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
906895 + file .getName ()
907896 + "\" " );
908897 MediaType mediaType = MediaType .parse (guessContentTypeFromFile (file ));
909- mpBuilder .addPart (partHeaders , RequestBody .create (mediaType , file ));
898+ mpBuilder .addPart (partHeaders , RequestBody .create (file , mediaType ));
910899 } else if (paramValue instanceof Collection ) {
911900 Collection <Object > collection = (Collection <Object >) paramValue ;
912901 for (Object item : collection ) {
@@ -915,15 +904,15 @@ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
915904 "Content-Disposition" ,
916905 "form-data; name=\" " + param .getKey () + "\" " );
917906 mpBuilder .addPart (
918- partHeaders , RequestBody .create (null , parameterToString (item )));
907+ partHeaders , RequestBody .create (parameterToString (item ), null ));
919908 }
920909 } else {
921910 Headers partHeaders =
922911 Headers .of (
923912 "Content-Disposition" ,
924913 "form-data; name=\" " + param .getKey () + "\" " );
925914 mpBuilder .addPart (
926- partHeaders , RequestBody .create (null , parameterToString (paramValue )));
915+ partHeaders , RequestBody .create (parameterToString (paramValue ), null ));
927916 }
928917 }
929918 return mpBuilder .build ();
@@ -952,7 +941,7 @@ public String guessContentTypeFromFile(File file) {
952941 public void requestToken () throws ApiException {
953942 try {
954943 RequestBody requestBody =
955- new FormEncodingBuilder ()
944+ new FormBody . Builder ()
956945 .addEncoded ("grant_type" , "client_credentials" )
957946 .addEncoded ("client_id" , clientId )
958947 .addEncoded ("client_secret" , clientSecret )
0 commit comments