2727
2828package com .aspose .words .cloud ;
2929
30- import com .aspose .words .cloud .model .requests .RequestIfc ;
30+ import com .aspose .words .cloud .model .requests .* ;
3131import com .squareup .okhttp .*;
3232import com .squareup .okhttp .internal .http .HttpMethod ;
3333import com .squareup .okhttp .logging .HttpLoggingInterceptor ;
3737import org .threeten .bp .LocalDate ;
3838import org .threeten .bp .OffsetDateTime ;
3939
40+ import javax .crypto .BadPaddingException ;
41+ import javax .crypto .Cipher ;
42+ import javax .crypto .IllegalBlockSizeException ;
43+ import javax .crypto .NoSuchPaddingException ;
4044import javax .mail .BodyPart ;
4145import javax .mail .MessagingException ;
4246import javax .mail .internet .MimeMultipart ;
4347import javax .mail .util .ByteArrayDataSource ;
4448import java .io .*;
4549import java .lang .reflect .Type ;
50+ import java .math .BigInteger ;
4651import java .net .URLConnection ;
4752import java .net .URLEncoder ;
53+ import java .nio .charset .StandardCharsets ;
54+ import java .security .InvalidKeyException ;
55+ import java .security .KeyFactory ;
56+ import java .security .NoSuchAlgorithmException ;
57+ import java .security .PublicKey ;
58+ import java .security .spec .InvalidKeySpecException ;
59+ import java .security .spec .RSAPublicKeySpec ;
4860import java .util .*;
4961import java .util .Map .Entry ;
5062import java .util .concurrent .TimeUnit ;
@@ -56,7 +68,7 @@ public class ApiClient {
5668 private String apiVersion = "v4.0" ;
5769 private String baseUrl = "https://api.aspose.cloud" ;
5870 private String basePath = baseUrl + "/" + apiVersion ;
59- private String clientVersion = "21.11 " ;
71+ private String clientVersion = "21.12 " ;
6072 private boolean debugging = false ;
6173 private Map <String , String > defaultHeaderMap = new HashMap <String , String >();
6274 private String tempFolderPath = null ;
@@ -72,6 +84,7 @@ public class ApiClient {
7284 private String refreshToken ;
7385 private String ClientSecret ;
7486 private String clientId ;
87+ private Cipher key ;
7588
7689 public ApiClient (String clientId , String clientSecret , String baseUrl ) {
7790 this ();
@@ -92,11 +105,29 @@ public ApiClient() {
92105 json = new JSON ();
93106
94107 // Set default User-Agent.
95- setUserAgent ("Swagger-Codegen/1.0.0/java" );
96108 addDefaultHeader ("x-aspose-client" , "java sdk" );
97109 addDefaultHeader ("x-aspose-client-version" , clientVersion );
98- setConnectTimeout (5 * 60 * 1000 );
99- setReadTimeout (5 * 60 * 1000 );
110+ setConnectTimeout (180 );
111+ setReadTimeout (180 );
112+ }
113+
114+
115+ /**
116+ * Gets a public key
117+ * @return public key
118+ */
119+ public Cipher getKey () {
120+ return key ;
121+ }
122+
123+ /**
124+ * Sets a public key
125+ * @param key
126+ * @return api client
127+ */
128+ public ApiClient setKey (Cipher key ) {
129+ this .key = key ;
130+ return this ;
100131 }
101132
102133 /**
@@ -355,68 +386,68 @@ public ApiClient setTempFolderPath(String tempFolderPath) {
355386 }
356387
357388 /**
358- * Get connection timeout (in milliseconds ).
389+ * Get connection timeout (in seconds ).
359390 *
360- * @return Timeout in milliseconds
391+ * @return Timeout in seconds
361392 */
362393 public int getConnectTimeout () {
363394 return httpClient .getConnectTimeout ();
364395 }
365396
366397 /**
367- * Sets the connect timeout (in milliseconds ).
398+ * Sets the connect timeout (in seconds ).
368399 * A value of 0 means no timeout, otherwise values must be between 1 and
369400 * {@link Integer#MAX_VALUE}.
370401 *
371- * @param connectionTimeout connection timeout in milliseconds
402+ * @param connectionTimeout connection timeout in seconds
372403 * @return Api client
373404 */
374405 public ApiClient setConnectTimeout (int connectionTimeout ) {
375- httpClient .setConnectTimeout (connectionTimeout , TimeUnit .MILLISECONDS );
406+ httpClient .setConnectTimeout (connectionTimeout , TimeUnit .SECONDS );
376407 return this ;
377408 }
378409
379410 /**
380- * Get read timeout (in milliseconds ).
411+ * Get read timeout (in seconds ).
381412 *
382- * @return Timeout in milliseconds
413+ * @return Timeout in seconds
383414 */
384415 public int getReadTimeout () {
385416 return httpClient .getReadTimeout ();
386417 }
387418
388419 /**
389- * Sets the read timeout (in milliseconds ).
420+ * Sets the read timeout (in seconds ).
390421 * A value of 0 means no timeout, otherwise values must be between 1 and
391422 * {@link Integer#MAX_VALUE}.
392423 *
393- * @param readTimeout read timeout in milliseconds
424+ * @param readTimeout read timeout in seconds
394425 * @return Api client
395426 */
396427 public ApiClient setReadTimeout (int readTimeout ) {
397- httpClient .setReadTimeout (readTimeout , TimeUnit .MILLISECONDS );
428+ httpClient .setReadTimeout (readTimeout , TimeUnit .SECONDS );
398429 return this ;
399430 }
400431
401432 /**
402- * Get write timeout (in milliseconds ).
433+ * Get write timeout (in seconds ).
403434 *
404- * @return Timeout in milliseconds
435+ * @return Timeout in seconds
405436 */
406437 public int getWriteTimeout () {
407438 return httpClient .getWriteTimeout ();
408439 }
409440
410441 /**
411- * Sets the write timeout (in milliseconds ).
442+ * Sets the write timeout (in seconds ).
412443 * A value of 0 means no timeout, otherwise values must be between 1 and
413444 * {@link Integer#MAX_VALUE}.
414445 *
415- * @param writeTimeout connection timeout in milliseconds
446+ * @param writeTimeout connection timeout in seconds
416447 * @return Api client
417448 */
418449 public ApiClient setWriteTimeout (int writeTimeout ) {
419- httpClient .setWriteTimeout (writeTimeout , TimeUnit .MILLISECONDS );
450+ httpClient .setWriteTimeout (writeTimeout , TimeUnit .SECONDS );
420451 return this ;
421452 }
422453
@@ -1145,11 +1176,34 @@ public void requestToken() throws ApiException {
11451176 }
11461177 }
11471178
1179+ public void setRsaKey (String modulus , String exponent ) throws NoSuchAlgorithmException , InvalidKeySpecException , NoSuchPaddingException , InvalidKeyException {
1180+ byte [] modulusByte = Base64 .getDecoder ().decode (modulus );
1181+ BigInteger modulusInt = new BigInteger (1 , modulusByte );
1182+ byte [] exponentByte = Base64 .getDecoder ().decode (exponent );
1183+ BigInteger exponentInt = new BigInteger (1 , exponentByte );
1184+ RSAPublicKeySpec spec = new RSAPublicKeySpec (modulusInt , exponentInt );
1185+ KeyFactory factory = KeyFactory .getInstance ("RSA" );
1186+ PublicKey key = factory .generatePublic (spec );
1187+ this .key = Cipher .getInstance ("RSA" );
1188+ this .key .init (Cipher .ENCRYPT_MODE , key );
1189+ }
1190+
11481191 /**
11491192 * AddParameterToQuery
11501193 */
11511194 public void addParameterToQuery (List <Pair > queryParams , String paramName , Object paramValue ) {
1152- queryParams .addAll (parameterToPair (paramName , paramValue ));
1195+ if (paramName .equals ("password" ) && paramValue != null && !paramValue .toString ().isEmpty ()) {
1196+ try {
1197+ queryParams .addAll (parameterToPair ("encryptedPassword" , Base64 .getEncoder ().encode (this .key .doFinal (paramValue .toString ().getBytes (StandardCharsets .UTF_8 )))));
1198+ }
1199+ catch (IllegalBlockSizeException e ) {
1200+ }
1201+ catch (BadPaddingException e ) {
1202+ }
1203+ }
1204+ else {
1205+ queryParams .addAll (parameterToPair (paramName , paramValue ));
1206+ }
11531207 }
11541208
11551209 /**
@@ -1171,18 +1225,23 @@ public String addParameterToPath(String path, String paramName, Object paramValu
11711225 /**
11721226 * Build batch request
11731227 */
1174- public Request buildBatchRequest (RequestIfc [] requests ) throws ApiException , IOException {
1228+ public Request buildBatchRequest (BatchPartRequest [] requests , Boolean displayIntermediateResults ) throws ApiException , IOException {
11751229 Headers multipartHeaders = Headers .of ("Content-Disposition" , "form-data" );
11761230 MultipartBuilder builder = new MultipartBuilder ().type (MultipartBuilder .FORM );
1177- for (RequestIfc request : requests ) {
1178- Request httpRequest = request .buildHttpRequest (this , null , null , false );
1179- builder .addPart (multipartHeaders , new ChildRequestContent (httpRequest , basePath + "/words/" ));
1231+ for (BatchPartRequest request : requests ) {
1232+ builder .addPart (multipartHeaders , new ChildRequestContent (this , request , basePath + "/words/" ));
11801233 }
11811234
11821235 RequestBody requestBody = builder .build ();
11831236 Map <String , String > headers = new HashMap <>();
11841237 headers .put ("Content-Type" , requestBody .contentType ().toString ());
1185- return buildRequest ("/words/batch" , "PUT" , new ArrayList <>(), new ArrayList <>(), requestBody , headers , new HashMap <>(), true , null );
1238+
1239+ String url = "/words/batch" ;
1240+ if (!displayIntermediateResults ) {
1241+ url += "?displayIntermediateResults=false" ;
1242+ }
1243+
1244+ return buildRequest (url , "PUT" , new ArrayList <>(), new ArrayList <>(), requestBody , headers , new HashMap <>(), true , null );
11861245 }
11871246
11881247 /**
@@ -1279,7 +1338,8 @@ public Object parseBatchPart(Request masterRequest, BodyPart bodyPart, Type retu
12791338 Headers headers = headersBuilder .build ();
12801339 byte [] rawBody = buffer .toByteArray ();
12811340 if (rawBody .length != lastSplitIndex + 2 ) {
1282- byte [] responseBytes = Arrays .copyOfRange (rawBody , lastSplitIndex + 2 , rawBody .length );
1341+ byte [] responseBytes = new byte [rawBody .length - (lastSplitIndex + 2 )];
1342+ System .arraycopy (rawBody , lastSplitIndex + 2 , responseBytes , 0 , responseBytes .length );
12831343 responseBody = ResponseBody .create (MediaType .parse (headers .get ("Content-Type" )), responseBytes );
12841344 }
12851345
0 commit comments