Skip to content

Commit d1bfe6c

Browse files
Merge branch 'master' into release
2 parents f3f4d48 + 2767fb8 commit d1bfe6c

24 files changed

+1653
-63
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ This repository contains Aspose.Words Cloud SDK for Java source code. This SDK a
1313
* Watermarks and protection
1414
* Full read & write access to Document Object Model, including sections, paragraphs, text, images, tables, headers/footers and many others
1515

16+
## Enhancements in Version 21.12
17+
18+
- Added dependsOn and resultOf features for batch requests
19+
- Added query parameter 'displayIntermediateResults' for batch requests. If 'false', the last response in batch will be returned only. Default is 'true'
20+
- Added 'timeout' in seconds
21+
- Support encryption of 'CommonRequest.Password'. Automatic encryption of all passwords sent to the API server as request parameters.
22+
1623
## Enhancements in Version 21.11
1724

1825

@@ -175,7 +182,7 @@ Add this dependency to your project's POM:
175182
<dependency>
176183
<groupId>com.aspose</groupId>
177184
<artifactId>aspose-words-cloud</artifactId>
178-
<version>21.11.0</version>
185+
<version>21.12.0</version>
179186
</dependency>
180187
</dependencies>
181188
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" standalone="yes"?>
2+
<NewDataSet>
3+
<info>
4+
<FirstName>Alexey</FirstName>
5+
<LastName>Noskov</LastName>
6+
<City>Kharkov</City>
7+
<Company>Aspose</Company>
8+
</info>
9+
</NewDataSet>
Binary file not shown.

examples/AcceptAllRevisions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
1010
WordsApi wordsApi = new WordsApi(apiClient);
11-
String fileName = "test_doc.docx";
11+
String fileName = "test_doc.docx";
1212

1313
// Upload original document to cloud storage.
1414
byte[] myVar1 = Files.readAllBytes(Paths.get(fileName).toAbsolutePath());

examples/AcceptAllRevisionsOnline.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
ApiClient apiClient = new ApiClient(/*clientId*/ "####-####-####-####-####", /*clientSecret*/ "##################", null);
22
WordsApi wordsApi = new WordsApi(apiClient);
3-
String fileName = "test_doc.docx";
3+
String fileName = "test_doc.docx";
44

55
// Calls AcceptAllRevisionsOnline method for document in cloud.
66
byte[] requestDocument = Files.readAllBytes(Paths.get(fileName).toAbsolutePath());

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<artifactId>aspose-words-cloud</artifactId>
55
<packaging>jar</packaging>
66
<name>AsposeWordsCloud</name>
7-
<version>21.11.0</version>
7+
<version>21.12.0</version>
88
<url>https://www.aspose.cloud/</url>
99
<description>Aspose Words Java SDK</description>
1010
<scm>

src/main/java/com/aspose/words/cloud/ApiClient.java

Lines changed: 87 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
package com.aspose.words.cloud;
2929

30-
import com.aspose.words.cloud.model.requests.RequestIfc;
30+
import com.aspose.words.cloud.model.requests.*;
3131
import com.squareup.okhttp.*;
3232
import com.squareup.okhttp.internal.http.HttpMethod;
3333
import com.squareup.okhttp.logging.HttpLoggingInterceptor;
@@ -37,14 +37,26 @@
3737
import org.threeten.bp.LocalDate;
3838
import 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;
4044
import javax.mail.BodyPart;
4145
import javax.mail.MessagingException;
4246
import javax.mail.internet.MimeMultipart;
4347
import javax.mail.util.ByteArrayDataSource;
4448
import java.io.*;
4549
import java.lang.reflect.Type;
50+
import java.math.BigInteger;
4651
import java.net.URLConnection;
4752
import 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;
4860
import java.util.*;
4961
import java.util.Map.Entry;
5062
import 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

src/main/java/com/aspose/words/cloud/ChildRequestContent.java

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
package com.aspose.words.cloud;
2929

30+
import com.aspose.words.cloud.model.requests.*;
3031
import com.squareup.okhttp.MediaType;
3132
import com.squareup.okhttp.Request;
3233
import com.squareup.okhttp.RequestBody;
@@ -37,10 +38,12 @@
3738

3839
public class ChildRequestContent extends RequestBody {
3940
private static final String CRLF = "\r\n";
40-
private Request request;
41+
private ApiClient apiClient;
42+
private BatchPartRequest request;
4143
private URI baseUri;
4244

43-
public ChildRequestContent(Request request, String rootUrl) {
45+
public ChildRequestContent(ApiClient apiClient, BatchPartRequest request, String rootUrl) {
46+
this.apiClient = apiClient;
4447
this.request = request;
4548
this.baseUri = URI.create(rootUrl);
4649
}
@@ -52,22 +55,40 @@ public MediaType contentType() {
5255

5356
@Override
5457
public void writeTo(BufferedSink bufferedSink) throws IOException {
55-
bufferedSink.writeUtf8(request.method());
58+
Request httpRequest;
59+
try {
60+
httpRequest = request.getRequest().buildHttpRequest(this.apiClient, null, null, false);
61+
}
62+
catch (ApiException ex) {
63+
throw new IOException(ex.getMessage());
64+
}
65+
66+
bufferedSink.writeUtf8(httpRequest.method());
5667
bufferedSink.writeUtf8(" ");
57-
bufferedSink.writeUtf8(baseUri.relativize(request.uri()).toString());
68+
bufferedSink.writeUtf8(baseUri.relativize(httpRequest.uri()).toString());
5869
bufferedSink.writeUtf8(" ");
5970
bufferedSink.writeUtf8(CRLF);
6071

61-
for (String key : request.headers().names()) {
72+
bufferedSink.writeUtf8("RequestId: ");
73+
bufferedSink.writeUtf8(request.getRequestId());
74+
bufferedSink.writeUtf8(CRLF);
75+
76+
if (request.getParentRequestId() != null) {
77+
bufferedSink.writeUtf8("DependsOn: ");
78+
bufferedSink.writeUtf8(request.getParentRequestId());
79+
bufferedSink.writeUtf8(CRLF);
80+
}
81+
82+
for (String key : httpRequest.headers().names()) {
6283
bufferedSink.writeUtf8(key);
6384
bufferedSink.writeUtf8(": ");
64-
bufferedSink.writeUtf8(request.headers().get(key));
85+
bufferedSink.writeUtf8(httpRequest.headers().get(key));
6586
bufferedSink.writeUtf8(CRLF);
6687
}
6788

6889
bufferedSink.writeUtf8(CRLF);
69-
if (request.body() != null) {
70-
request.body().writeTo(bufferedSink);
90+
if (httpRequest.body() != null) {
91+
httpRequest.body().writeTo(bufferedSink);
7192
}
7293
}
7394
}

0 commit comments

Comments
 (0)