Environment requirements
Java 6+
Maven
Installation
Add a Maven repository
<repositories>
<repository>
<id>sonatype-nexus-staging</id>
<name>Sonatype Nexus Staging</name>
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
Add JAR package dependency
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-core</artifactId>
<version>3.0.6</version>
</dependency>
<dependency>
<groupId>com.aliyun</groupId>
<artifactId>aliyun-java-sdk-mts</artifactId>
<version>2.1.7</version>
</dependency>
Multi-region support
Add the Beijing region (add other regions in a similar way):
import com.aliyuncs.profile.DefaultProfile;
DefaultProfile.addEndpoint("cn-beijing",
"cn-beijing",
"Mts",
"mts.cn-beijing.aliyuncs.com");
API call example
The following calls
SearchMediaWorkflow
as an example.import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.SearchMediaWorkflowRequest;
import com.aliyuncs.mts.model.v20140618.SearchMediaWorkflowResponse;
SearchMediaWorkflowResponse searchMediaWorkflow(DefaultAcsClient client) {
SearchMediaWorkflowRequest request = new SearchMediaWorkflowRequest();
SearchMediaWorkflowResponse response = null;
try {
response = client.getAcsResponse(request);
} catch (ServerException e) {
throw new RuntimeException("SearchMediaWorkflowRequest Server failed");
} catch (ClientException e) {
throw new RuntimeException("SearchMediaWorkflowRequest Client failed");
}
return response;
}
Hangzhou region
When initializing the profile and client, set RegionId to “cn-hangzhou”. No special configuration is required during the API call.
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
DefaultProfile profile = DefaultProfile.getProfile(
"cn-hangzhou",
accessKeyId,
accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
searchMediaWorkflow(client);
Beijing region
When initializing the profile and client, set RegionId to “cn-beijing”. No special configuration is required during the API call.
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
DefaultProfile profile = DefaultProfile.getProfile(
"cn-beijing",
accessKeyId,
accessKeySecret);
DefaultAcsClient client = new DefaultAcsClient(profile);
searchMediaWorkflow(client);