Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions aliyun-java-sdk-core/ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
2018-03-13 Version: 3.6.0
1, Supports specifying the https certificate path
2, Optimize the logic for resolving Endpoint
3, Bug fixes

2018-01-31 Version: 3.5.1
1, Adding the setEndpoint method to the Request.

Expand Down
233 changes: 117 additions & 116 deletions aliyun-java-sdk-core/pom.xml
Original file line number Diff line number Diff line change
@@ -1,123 +1,124 @@
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<packaging>jar</packaging>
<version>3.5.1</version>
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<packaging>jar</packaging>
<version>3.6.0</version>
<name>aliyun-java-sdk-core</name>
<url>http://www.aliyun.com</url>
<description>Aliyun Open API SDK for Java
<url>http://www.aliyun.com</url>
<description>Aliyun Open API SDK for Java

Copyright (C) Alibaba Cloud Computing
All rights reserved.

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

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

<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>
http://www.aliyun.com
</description>

<licenses>
<license>
<name></name>
<url></url>
<distribution></distribution>
</license>
</licenses>
<scm>
<url></url>
<connection></connection>
</scm>
<developers>
<developer>
<id>aliyunproducts</id>
<name>Aliyun SDK</name>
<email>aliyunsdk@aliyun.com</email>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<excludes>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
<version>1.6.3</version>
<extensions>true</extensions>
<configuration>
<serverId>sonatype-nexus-staging</serverId>
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
<autoReleaseAfterClose>true</autoReleaseAfterClose>
</configuration>
</plugin>
</plugins>
</build>
<distributionManagement>
<snapshotRepository>
<id>sonatype-nexus-snapshots</id>
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
</snapshotRepository>
<repository>
<id>sonatype-nexus-staging</id>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
</repository>
</distributionManagement>

<licenses>
<license>
<name></name>
<url></url>
<distribution></distribution>
</license>
</licenses>
<scm>
<url></url>
<connection></connection>
</scm>
<developers>
<developer>
<id>aliyunproducts</id>
<name>Aliyun SDK</name>
<email>aliyunsdk@aliyun.com</email>
</developer>
</developers>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.1.36</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.2</version>
<configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-gpg-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<id>sign-artifacts</id>
<phase>verify</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
</plugin>
<!--<plugin>-->
<!--<groupId>org.sonatype.plugins</groupId>-->
<!--<artifactId>nexus-staging-maven-plugin</artifactId>-->
<!--<version>1.6.3</version>-->
<!--<extensions>true</extensions>-->
<!--<configuration>-->
<!--<serverId>sonatype-nexus-staging</serverId>-->
<!--<nexusUrl>https://oss.sonatype.org/</nexusUrl>-->
<!--<autoReleaseAfterClose>true</autoReleaseAfterClose>-->
<!--</configuration>-->
<!--</plugin>-->
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,42 +36,62 @@
import com.aliyuncs.regions.Endpoint;
import com.aliyuncs.regions.ProductDomain;
import com.aliyuncs.transform.UnmarshallerContext;
import com.aliyuncs.utils.HttpsUtils;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.SocketTimeoutException;
import java.security.GeneralSecurityException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocketFactory;

@SuppressWarnings("deprecation")
public class DefaultAcsClient implements IAcsClient {
private int maxRetryNumber = 3;
private boolean autoRetry = true;
private IClientProfile clientProfile = null;
private AlibabaCloudCredentialsProvider credentialsProvider;

private SSLSocketFactory sslSocketFactory = null;

public DefaultAcsClient() {
this.clientProfile = DefaultProfile.getProfile();
initSslSocketFactory();
}

public DefaultAcsClient(IClientProfile profile) {
this.clientProfile = profile;
this.credentialsProvider = new StaticCredentialsProvider(profile);
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
initSslSocketFactory();
}

public DefaultAcsClient(IClientProfile profile, AlibabaCloudCredentials credentials) {
this.clientProfile = profile;
this.credentialsProvider = new StaticCredentialsProvider(credentials);
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
initSslSocketFactory();
}

public DefaultAcsClient(IClientProfile profile, AlibabaCloudCredentialsProvider credentialsProvider) {
this.clientProfile = profile;
this.credentialsProvider = credentialsProvider;
this.clientProfile.setCredentialsProvider(this.credentialsProvider);
initSslSocketFactory();
}

private void initSslSocketFactory(){
try {
this.sslSocketFactory = HttpsUtils.buildJavaSSLSocketFactory(clientProfile.getCertPath());
}catch(SSLException e){
// keep exceptions for keep compatible
System.err.println("buildSSLSocketFactory failed" + e.toString());
}
}

@Override
Expand Down Expand Up @@ -146,18 +166,18 @@ public <T extends AcsResponse> T getAcsResponse(AcsRequest<T> request, String re
HttpResponse baseResponse = this.doAction(request, regionId, credential);
return parseAcsResponse(request.getResponseClass(), baseResponse);
}

@SuppressWarnings("unchecked")
@Override
public CommonResponse getCommonResponse(CommonRequest request)
throws ServerException, ClientException{
public CommonResponse getCommonResponse(CommonRequest request)
throws ServerException, ClientException {
HttpResponse baseResponse = this.doAction(request.buildRequest());
String stringContent = getResponseContent(baseResponse);
CommonResponse response = new CommonResponse();
response.setData(stringContent);
response.setHttpStatus(baseResponse.getStatus());
response.setHttpResponse(baseResponse);

return response;
}

Expand Down Expand Up @@ -218,12 +238,12 @@ request, autoRetry, maxRetryNumber, regionId, new LegacyCredentials(credential),
);
}

private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
boolean autoRetry, int maxRetryNumber,
String regionId,
AlibabaCloudCredentials credentials,
Signer signer, FormatType format,
List<Endpoint> endpoints)
private <T extends AcsResponse> HttpResponse doAction(AcsRequest<T> request,
boolean autoRetry, int maxRetryNumber,
String regionId,
AlibabaCloudCredentials credentials,
Signer signer, FormatType format,
List<Endpoint> endpoints)
throws ClientException, ServerException {

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

boolean shouldRetry = true;
for (int retryTimes = 0; shouldRetry; retryTimes ++) {
for (int retryTimes = 0; shouldRetry; retryTimes++) {

shouldRetry = autoRetry && retryTimes < maxRetryNumber;

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

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

return null;
Expand All @@ -290,14 +313,14 @@ private <T extends AcsResponse> T readResponse(Class<T> clasz, HttpResponse http
} catch (Exception e) {
throw new ClientException("SDK.InvalidResponseClass", "Unable to allocate " + clasz.getName() + " class");
}

String responseEndpoint = clasz.getName().substring(clasz.getName().lastIndexOf(".") + 1);
if (response.checkShowJsonItemName()) {
context.setResponseMap(reader.read(stringContent, responseEndpoint));
} else {
context.setResponseMap(reader.readForHideArrayItem(stringContent, responseEndpoint));
context.setResponseMap(reader.readForHideArrayItem(stringContent, responseEndpoint));
}

context.setHttpResponse(httpResponse);
response.getInstance(context);
return response;
Expand Down
Loading