1
1
package com .aspose .barcode .cloud ;
2
2
3
3
import 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 ;
17
17
18
18
import okio .BufferedSink ;
19
19
import okio .Okio ;
41
41
/** ApiClient. */
42
42
public class ApiClient {
43
43
public final String apiVersion = "v3.0" ;
44
- public final String clientVersion = "24.9 .0" ;
44
+ public final String clientVersion = "24.10 .0" ;
45
45
46
46
private String baseUrl = "https://api.aspose.cloud" ;
47
47
private String tokenUrl = baseUrl + "/connect/token" ;
@@ -50,7 +50,7 @@ public class ApiClient {
50
50
private boolean debugging = false ;
51
51
private final Map <String , String > defaultHeaderMap = new HashMap <>();
52
52
private String tempFolderPath = null ;
53
- private final OkHttpClient httpClient ;
53
+ private OkHttpClient httpClient ;
54
54
private final JSON json ;
55
55
private HttpLoggingInterceptor loggingInterceptor ;
56
56
private String accessToken ;
@@ -79,17 +79,24 @@ public ApiClient(String clientId, String clientSecret, String baseUrl, String to
79
79
}
80
80
}
81
81
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 ();
84
88
85
89
json = new JSON ();
86
90
87
91
// Set default User-Agent.
88
- setUserAgent ("Swagger-Codegen/24.9 .0/java" );
92
+ setUserAgent ("Swagger-Codegen/24.10 .0/java" );
89
93
90
94
addDefaultHeader ("x-aspose-client" , "java sdk" );
91
95
addDefaultHeader ("x-aspose-client-version" , clientVersion );
92
- setReadTimeout (60_000 );
96
+ }
97
+
98
+ protected ApiClient () {
99
+ this (60_000 );
93
100
}
94
101
95
102
/**
@@ -197,17 +204,7 @@ public void setTempFolderPath(String tempFolderPath) {
197
204
* @return Timeout in milliseconds
198
205
*/
199
206
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 ();
211
208
}
212
209
213
210
/**
@@ -216,7 +213,7 @@ public void setConnectTimeout(int connectionTimeout) {
216
213
* @return Timeout in milliseconds
217
214
*/
218
215
public int getReadTimeout () {
219
- return httpClient .getReadTimeout ();
216
+ return httpClient .readTimeoutMillis ();
220
217
}
221
218
222
219
/**
@@ -226,7 +223,8 @@ public int getReadTimeout() {
226
223
* @param readTimeout read timeout in milliseconds
227
224
*/
228
225
public void setReadTimeout (int readTimeout ) {
229
- httpClient .setReadTimeout (readTimeout , TimeUnit .MILLISECONDS );
226
+ httpClient =
227
+ new OkHttpClient .Builder ().readTimeout (readTimeout , TimeUnit .MILLISECONDS ).build ();
230
228
}
231
229
232
230
/**
@@ -235,17 +233,7 @@ public void setReadTimeout(int readTimeout) {
235
233
* @return Timeout in milliseconds
236
234
*/
237
235
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 ();
249
237
}
250
238
251
239
/**
@@ -265,7 +253,7 @@ public String parameterToString(Object param) {
265
253
return jsonStr .substring (1 , jsonStr .length () - 1 );
266
254
} else if (param instanceof Collection ) {
267
255
StringBuilder b = new StringBuilder ();
268
- for (Object o : (Collection ) param ) {
256
+ for (Object o : (Collection < Object > ) param ) {
269
257
if (b .length () > 0 ) {
270
258
b .append ("," );
271
259
}
@@ -499,18 +487,18 @@ public <T> T deserialize(Response response, Type returnType) throws ApiException
499
487
public RequestBody serialize (Object obj , String contentType ) throws ApiException {
500
488
if (obj instanceof byte []) {
501
489
// Binary (byte array) body parameter support.
502
- return RequestBody .create (MediaType . parse ( contentType ), ( byte []) obj );
490
+ return RequestBody .create (( byte []) obj , MediaType . parse ( contentType ) );
503
491
} else if (obj instanceof File ) {
504
492
// File body parameter support.
505
- return RequestBody .create (MediaType .parse (contentType ), ( File ) obj );
493
+ return RequestBody .create (( File ) obj , MediaType .parse (contentType ));
506
494
} else if (isJsonMime (contentType )) {
507
495
String content ;
508
496
if (obj != null ) {
509
497
content = json .serialize (obj );
510
498
} else {
511
499
content = null ;
512
500
}
513
- return RequestBody .create (MediaType .parse (contentType ), content );
501
+ return RequestBody .create (content , MediaType .parse (contentType ));
514
502
} else {
515
503
throw new ApiException ("Content type \" " + contentType + "\" is not supported" );
516
504
}
@@ -630,14 +618,14 @@ public <T> void executeAsync(Call call, ApiCallback<T> callback) {
630
618
*/
631
619
public <T > void executeAsync (Call call , final Type returnType , final ApiCallback <T > callback ) {
632
620
call .enqueue (
633
- new Callback () {
621
+ new okhttp3 . Callback () {
634
622
@ Override
635
- public void onFailure (Request request , IOException e ) {
623
+ public void onFailure (Call call , IOException e ) {
636
624
callback .onFailure (new ApiException (e ), 0 , null );
637
625
}
638
626
639
627
@ Override
640
- public void onResponse (Response response ) {
628
+ public void onResponse (Call call , Response response ) {
641
629
T result ;
642
630
try {
643
631
result = handleResponse (response , returnType );
@@ -668,7 +656,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
668
656
if (response .body () != null ) {
669
657
try {
670
658
response .body ().close ();
671
- } catch (IOException e ) {
659
+ } catch (Exception e ) {
672
660
throw new ApiException (
673
661
response .message (),
674
662
e ,
@@ -683,6 +671,7 @@ public <T> T handleResponse(Response response, Type returnType) throws ApiExcept
683
671
if (response .body () == null ) {
684
672
throw new ApiException (response .message (), response .code ());
685
673
}
674
+
686
675
ApiErrorResponse errorResponse ;
687
676
try {
688
677
errorResponse = deserialize (response , ApiErrorResponse .class );
@@ -774,7 +763,7 @@ public Request buildRequest(
774
763
if (!HttpMethod .permitsRequestBody (method )) {
775
764
reqBody = null ;
776
765
} else if ("application/x-www-form-urlencoded" .equals (contentType )) {
777
- reqBody = buildRequestBodyFormEncoding (formParams );
766
+ reqBody = buildRequestBodyForm (formParams );
778
767
} else if ("multipart/form-data" .equals (contentType )) {
779
768
reqBody = buildRequestBodyMultipart (formParams );
780
769
} else if (body == null ) {
@@ -783,7 +772,7 @@ public Request buildRequest(
783
772
reqBody = null ;
784
773
} else {
785
774
// use an empty request body (for POST, PUT and PATCH)
786
- reqBody = RequestBody .create (MediaType .parse (contentType ), "" );
775
+ reqBody = RequestBody .create ("" , MediaType .parse (contentType ));
787
776
}
788
777
} else {
789
778
reqBody = serialize (body , contentType );
@@ -876,8 +865,8 @@ public void processHeaderParams(Map<String, String> headerParams, Request.Builde
876
865
* @param formParams Form parameters in the form of Map
877
866
* @return RequestBody
878
867
*/
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 ();
881
870
for (Entry <String , Object > param : formParams .entrySet ()) {
882
871
formBuilder .add (param .getKey (), parameterToString (param .getValue ()));
883
872
}
@@ -892,7 +881,7 @@ public RequestBody buildRequestBodyFormEncoding(Map<String, Object> formParams)
892
881
* @return RequestBody
893
882
*/
894
883
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 );
896
885
for (Entry <String , Object > param : formParams .entrySet ()) {
897
886
Object paramValue = param .getValue ();
898
887
if (paramValue instanceof File ) {
@@ -906,7 +895,7 @@ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
906
895
+ file .getName ()
907
896
+ "\" " );
908
897
MediaType mediaType = MediaType .parse (guessContentTypeFromFile (file ));
909
- mpBuilder .addPart (partHeaders , RequestBody .create (mediaType , file ));
898
+ mpBuilder .addPart (partHeaders , RequestBody .create (file , mediaType ));
910
899
} else if (paramValue instanceof Collection ) {
911
900
Collection <Object > collection = (Collection <Object >) paramValue ;
912
901
for (Object item : collection ) {
@@ -915,15 +904,15 @@ public RequestBody buildRequestBodyMultipart(Map<String, Object> formParams) {
915
904
"Content-Disposition" ,
916
905
"form-data; name=\" " + param .getKey () + "\" " );
917
906
mpBuilder .addPart (
918
- partHeaders , RequestBody .create (null , parameterToString (item )));
907
+ partHeaders , RequestBody .create (parameterToString (item ), null ));
919
908
}
920
909
} else {
921
910
Headers partHeaders =
922
911
Headers .of (
923
912
"Content-Disposition" ,
924
913
"form-data; name=\" " + param .getKey () + "\" " );
925
914
mpBuilder .addPart (
926
- partHeaders , RequestBody .create (null , parameterToString (paramValue )));
915
+ partHeaders , RequestBody .create (parameterToString (paramValue ), null ));
927
916
}
928
917
}
929
918
return mpBuilder .build ();
@@ -952,7 +941,7 @@ public String guessContentTypeFromFile(File file) {
952
941
public void requestToken () throws ApiException {
953
942
try {
954
943
RequestBody requestBody =
955
- new FormEncodingBuilder ()
944
+ new FormBody . Builder ()
956
945
.addEncoded ("grant_type" , "client_credentials" )
957
946
.addEncoded ("client_id" , clientId )
958
947
.addEncoded ("client_secret" , clientSecret )
0 commit comments