Skip to content

Commit 933d993

Browse files
author
gaort
authored
Merge pull request aliyun#37 from aliyun/pre-release
由温仰发起的CORE SDK自动发布, BUILD_ID=184, 版本号:3.6.0
2 parents 4e98f67 + 9447b80 commit 933d993

23 files changed

+1033
-5099
lines changed

aliyun-java-sdk-core/ChangeLog.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2018-03-13 Version: 3.6.0
2+
1, Supports specifying the https certificate path
3+
2, Optimize the logic for resolving Endpoint
4+
3, Bug fixes
5+
16
2018-01-31 Version: 3.5.1
27
1, Adding the setEndpoint method to the Request.
38

aliyun-java-sdk-core/pom.xml

Lines changed: 117 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -1,123 +1,124 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
2-
<modelVersion>4.0.0</modelVersion>
3-
<groupId>com.aliyun</groupId>
4-
<artifactId>aliyun-java-sdk-core</artifactId>
5-
<packaging>jar</packaging>
6-
<version>3.5.1</version>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<modelVersion>4.0.0</modelVersion>
4+
<groupId>com.aliyun</groupId>
5+
<artifactId>aliyun-java-sdk-core</artifactId>
6+
<packaging>jar</packaging>
7+
<version>3.6.0</version>
78
<name>aliyun-java-sdk-core</name>
8-
<url>http://www.aliyun.com</url>
9-
<description>Aliyun Open API SDK for Java
9+
<url>http://www.aliyun.com</url>
10+
<description>Aliyun Open API SDK for Java
1011

11-
Copyright (C) Alibaba Cloud Computing
12-
All rights reserved.
1312

14-
版权所有 (C)阿里云计算有限公司
13+
Copyright (C) Alibaba Cloud Computing
14+
All rights reserved.
1515

16-
http://www.aliyun.com</description>
16+
版权所有 (C)阿里云计算有限公司
1717

18-
<distributionManagement>
19-
<snapshotRepository>
20-
<id>sonatype-nexus-snapshots</id>
21-
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
22-
</snapshotRepository>
23-
<repository>
24-
<id>sonatype-nexus-staging</id>
25-
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
26-
</repository>
27-
</distributionManagement>
18+
http://www.aliyun.com
19+
</description>
2820

29-
<licenses>
30-
<license>
31-
<name></name>
32-
<url></url>
33-
<distribution></distribution>
34-
</license>
35-
</licenses>
36-
<scm>
37-
<url></url>
38-
<connection></connection>
39-
</scm>
40-
<developers>
41-
<developer>
42-
<id>aliyunproducts</id>
43-
<name>Aliyun SDK</name>
44-
<email>aliyunsdk@aliyun.com</email>
45-
</developer>
46-
</developers>
47-
<dependencies>
48-
<dependency>
49-
<groupId>junit</groupId>
50-
<artifactId>junit</artifactId>
51-
<version>4.12</version>
52-
<scope>test</scope>
53-
</dependency>
54-
<dependency>
55-
<groupId>com.alibaba</groupId>
56-
<artifactId>fastjson</artifactId>
57-
<version>1.1.36</version>
58-
<scope>test</scope>
59-
</dependency>
60-
<dependency>
61-
<groupId>org.json</groupId>
62-
<artifactId>json</artifactId>
63-
<version>20170516</version>
64-
</dependency>
65-
</dependencies>
66-
67-
<build>
68-
<plugins>
69-
<plugin>
70-
<groupId>org.apache.maven.plugins</groupId>
71-
<artifactId>maven-compiler-plugin</artifactId>
72-
<version>2.3.2</version>
73-
<configuration>
74-
<source>1.6</source>
75-
<target>1.6</target>
76-
<encoding>UTF-8</encoding>
77-
</configuration>
78-
</plugin>
79-
<plugin>
80-
<groupId>org.apache.maven.plugins</groupId>
81-
<artifactId>maven-jar-plugin</artifactId>
82-
<version>2.3.2</version>
83-
<configuration>
84-
<excludes>
85-
</excludes>
86-
</configuration>
87-
</plugin>
88-
<plugin>
89-
<groupId>org.apache.maven.plugins</groupId>
90-
<artifactId>maven-javadoc-plugin</artifactId>
91-
<version>2.8</version>
92-
<configuration>
93-
<encoding>UTF-8</encoding>
94-
</configuration>
95-
</plugin>
96-
<plugin>
97-
<groupId>org.apache.maven.plugins</groupId>
98-
<artifactId>maven-gpg-plugin</artifactId>
99-
<version>1.5</version>
100-
<executions>
101-
<execution>
102-
<id>sign-artifacts</id>
103-
<phase>verify</phase>
104-
<goals>
105-
<goal>sign</goal>
106-
</goals>
107-
</execution>
108-
</executions>
109-
</plugin>
110-
<plugin>
111-
<groupId>org.sonatype.plugins</groupId>
112-
<artifactId>nexus-staging-maven-plugin</artifactId>
113-
<version>1.6.3</version>
114-
<extensions>true</extensions>
115-
<configuration>
116-
<serverId>sonatype-nexus-staging</serverId>
117-
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
118-
<autoReleaseAfterClose>true</autoReleaseAfterClose>
119-
</configuration>
120-
</plugin>
121-
</plugins>
122-
</build>
21+
<distributionManagement>
22+
<snapshotRepository>
23+
<id>sonatype-nexus-snapshots</id>
24+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
25+
</snapshotRepository>
26+
<repository>
27+
<id>sonatype-nexus-staging</id>
28+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
29+
</repository>
30+
</distributionManagement>
31+
32+
<licenses>
33+
<license>
34+
<name></name>
35+
<url></url>
36+
<distribution></distribution>
37+
</license>
38+
</licenses>
39+
<scm>
40+
<url></url>
41+
<connection></connection>
42+
</scm>
43+
<developers>
44+
<developer>
45+
<id>aliyunproducts</id>
46+
<name>Aliyun SDK</name>
47+
<email>aliyunsdk@aliyun.com</email>
48+
</developer>
49+
</developers>
50+
<dependencies>
51+
<dependency>
52+
<groupId>junit</groupId>
53+
<artifactId>junit</artifactId>
54+
<version>4.12</version>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>com.alibaba</groupId>
59+
<artifactId>fastjson</artifactId>
60+
<version>1.1.36</version>
61+
<scope>test</scope>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.json</groupId>
65+
<artifactId>json</artifactId>
66+
<version>20170516</version>
67+
</dependency>
68+
</dependencies>
69+
70+
<build>
71+
<plugins>
72+
<plugin>
73+
<groupId>org.apache.maven.plugins</groupId>
74+
<artifactId>maven-compiler-plugin</artifactId>
75+
<version>2.3.2</version>
76+
<configuration>
77+
<source>1.6</source>
78+
<target>1.6</target>
79+
<encoding>UTF-8</encoding>
80+
</configuration>
81+
</plugin>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-jar-plugin</artifactId>
85+
<version>2.3.2</version>
86+
<configuration>
87+
</configuration>
88+
</plugin>
89+
<plugin>
90+
<groupId>org.apache.maven.plugins</groupId>
91+
<artifactId>maven-javadoc-plugin</artifactId>
92+
<version>2.8</version>
93+
<configuration>
94+
<encoding>UTF-8</encoding>
95+
</configuration>
96+
</plugin>
97+
<plugin>
98+
<groupId>org.apache.maven.plugins</groupId>
99+
<artifactId>maven-gpg-plugin</artifactId>
100+
<version>1.5</version>
101+
<executions>
102+
<execution>
103+
<id>sign-artifacts</id>
104+
<phase>verify</phase>
105+
<goals>
106+
<goal>sign</goal>
107+
</goals>
108+
</execution>
109+
</executions>
110+
</plugin>
111+
<!--<plugin>-->
112+
<!--<groupId>org.sonatype.plugins</groupId>-->
113+
<!--<artifactId>nexus-staging-maven-plugin</artifactId>-->
114+
<!--<version>1.6.3</version>-->
115+
<!--<extensions>true</extensions>-->
116+
<!--<configuration>-->
117+
<!--<serverId>sonatype-nexus-staging</serverId>-->
118+
<!--<nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
119+
<!--<autoReleaseAfterClose>true</autoReleaseAfterClose>-->
120+
<!--</configuration>-->
121+
<!--</plugin>-->
122+
</plugins>
123+
</build>
123124
</project>

aliyun-java-sdk-core/src/main/java/com/aliyuncs/DefaultAcsClient.java

Lines changed: 37 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -36,42 +36,62 @@
3636
import com.aliyuncs.regions.Endpoint;
3737
import com.aliyuncs.regions.ProductDomain;
3838
import com.aliyuncs.transform.UnmarshallerContext;
39+
import com.aliyuncs.utils.HttpsUtils;
3940

4041
import java.io.IOException;
4142
import java.io.UnsupportedEncodingException;
4243
import java.net.SocketTimeoutException;
44+
import java.security.GeneralSecurityException;
4345
import java.security.InvalidKeyException;
4446
import java.security.NoSuchAlgorithmException;
4547
import java.util.ArrayList;
4648
import java.util.List;
4749

50+
import javax.net.ssl.SSLException;
51+
import javax.net.ssl.SSLSocketFactory;
52+
4853
@SuppressWarnings("deprecation")
4954
public class DefaultAcsClient implements IAcsClient {
5055
private int maxRetryNumber = 3;
5156
private boolean autoRetry = true;
5257
private IClientProfile clientProfile = null;
5358
private AlibabaCloudCredentialsProvider credentialsProvider;
5459

60+
private SSLSocketFactory sslSocketFactory = null;
61+
5562
public DefaultAcsClient() {
5663
this.clientProfile = DefaultProfile.getProfile();
64+
initSslSocketFactory();
5765
}
5866

5967
public DefaultAcsClient(IClientProfile profile) {
6068
this.clientProfile = profile;
6169
this.credentialsProvider = new StaticCredentialsProvider(profile);
6270
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
71+
initSslSocketFactory();
6372
}
6473

6574
public DefaultAcsClient(IClientProfile profile, AlibabaCloudCredentials credentials) {
6675
this.clientProfile = profile;
6776
this.credentialsProvider = new StaticCredentialsProvider(credentials);
6877
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
78+
initSslSocketFactory();
6979
}
7080

7181
public DefaultAcsClient(IClientProfile profile, AlibabaCloudCredentialsProvider credentialsProvider) {
7282
this.clientProfile = profile;
7383
this.credentialsProvider = credentialsProvider;
7484
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
85+
initSslSocketFactory();
86+
}
87+
88+
private void initSslSocketFactory(){
89+
try {
90+
this.sslSocketFactory = HttpsUtils.buildJavaSSLSocketFactory(clientProfile.getCertPath());
91+
}catch(SSLException e){
92+
// keep exceptions for keep compatible
93+
System.err.println("buildSSLSocketFactory failed" + e.toString());
94+
}
7595
}
7696

7797
@Override
@@ -146,18 +166,18 @@ public <T extends AcsResponse> T getAcsResponse(AcsRequest<T> request, String re
146166
HttpResponse baseResponse = this.doAction(request, regionId, credential);
147167
return parseAcsResponse(request.getResponseClass(), baseResponse);
148168
}
149-
169+
150170
@SuppressWarnings("unchecked")
151171
@Override
152-
public CommonResponse getCommonResponse(CommonRequest request)
153-
throws ServerException, ClientException{
172+
public CommonResponse getCommonResponse(CommonRequest request)
173+
throws ServerException, ClientException {
154174
HttpResponse baseResponse = this.doAction(request.buildRequest());
155175
String stringContent = getResponseContent(baseResponse);
156176
CommonResponse response = new CommonResponse();
157177
response.setData(stringContent);
158178
response.setHttpStatus(baseResponse.getStatus());
159179
response.setHttpResponse(baseResponse);
160-
180+
161181
return response;
162182
}
163183

@@ -218,12 +238,12 @@ request, autoRetry, maxRetryNumber, regionId, new LegacyCredentials(credential),
218238
);
219239
}
220240

221-
private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
222-
boolean autoRetry, int maxRetryNumber,
223-
String regionId,
224-
AlibabaCloudCredentials credentials,
225-
Signer signer, FormatType format,
226-
List<Endpoint> endpoints)
241+
private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
242+
boolean autoRetry, int maxRetryNumber,
243+
String regionId,
244+
AlibabaCloudCredentials credentials,
245+
Signer signer, FormatType format,
246+
List<Endpoint> endpoints)
227247
throws ClientException, ServerException {
228248

229249
try {
@@ -242,11 +262,12 @@ private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
242262
}
243263

244264
boolean shouldRetry = true;
245-
for (int retryTimes = 0; shouldRetry; retryTimes ++) {
265+
for (int retryTimes = 0; shouldRetry; retryTimes++) {
246266

247267
shouldRetry = autoRetry && retryTimes < maxRetryNumber;
248268

249269
HttpRequest httpRequest = request.signRequest(signer, credentials, format, domain);
270+
httpRequest.setSslSocketFactory(this.sslSocketFactory);
250271

251272
HttpResponse response;
252273
response = HttpResponse.getResponse(httpRequest);
@@ -274,6 +295,8 @@ private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
274295
throw new ClientException("SDK.ServerUnreachable", "Server unreachable: " + exp.toString());
275296
} catch (NoSuchAlgorithmException exp) {
276297
throw new ClientException("SDK.InvalidMD5Algorithm", "MD5 hash is not supported by client side.");
298+
} catch (GeneralSecurityException exp) {
299+
throw new ClientException("SDK.SecureConnectorError", "Send request with specific SecureConnector failed: " + exp.toString());
277300
}
278301

279302
return null;
@@ -290,14 +313,14 @@ private <T extends AcsResponse> T readResponse(Class<T> clasz, HttpResponse http
290313
} catch (Exception e) {
291314
throw new ClientException("SDK.InvalidResponseClass", "Unable to allocate " + clasz.getName() + " class");
292315
}
293-
316+
294317
String responseEndpoint = clasz.getName().substring(clasz.getName().lastIndexOf(".") + 1);
295318
if (response.checkShowJsonItemName()) {
296319
context.setResponseMap(reader.read(stringContent, responseEndpoint));
297320
} else {
298-
context.setResponseMap(reader.readForHideArrayItem(stringContent, responseEndpoint));
321+
context.setResponseMap(reader.readForHideArrayItem(stringContent, responseEndpoint));
299322
}
300-
323+
301324
context.setHttpResponse(httpResponse);
302325
response.getInstance(context);
303326
return response;

0 commit comments

Comments
 (0)