All Products
Search
Document Center

:JAVA-SDK

Last Updated:Apr 09, 2018
  • Environment requirements

    Java 6+

    Maven

  • Installation

    • Add a Maven repository

      1. <repositories>
      2. <repository>
      3. <id>sonatype-nexus-staging</id>
      4. <name>Sonatype Nexus Staging</name>
      5. <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
      6. <releases>
      7. <enabled>true</enabled>
      8. </releases>
      9. <snapshots>
      10. <enabled>true</enabled>
      11. </snapshots>
      12. </repository>
      13. </repositories>
    • Add JAR package dependency

      1. <dependency>
      2. <groupId>com.aliyun</groupId>
      3. <artifactId>aliyun-java-sdk-core</artifactId>
      4. <version>3.0.6</version>
      5. </dependency>
      6. <dependency>
      7. <groupId>com.aliyun</groupId>
      8. <artifactId>aliyun-java-sdk-mts</artifactId>
      9. <version>2.1.7</version>
      10. </dependency>
  • Multi-region support

    Add the Beijing region (add other regions in a similar way):

    1. import com.aliyuncs.profile.DefaultProfile;
    2. DefaultProfile.addEndpoint("cn-beijing",
    3. "cn-beijing",
    4. "Mts",
    5. "mts.cn-beijing.aliyuncs.com");
    • API call example

      The following calls SearchMediaWorkflow as an example.

      1. import com.aliyuncs.DefaultAcsClient;
      2. import com.aliyuncs.exceptions.ClientException;
      3. import com.aliyuncs.exceptions.ServerException;
      4. import com.aliyuncs.mts.model.v20140618.SearchMediaWorkflowRequest;
      5. import com.aliyuncs.mts.model.v20140618.SearchMediaWorkflowResponse;
      1. SearchMediaWorkflowResponse searchMediaWorkflow(DefaultAcsClient client) {
      2. SearchMediaWorkflowRequest request = new SearchMediaWorkflowRequest();
      3. SearchMediaWorkflowResponse response = null;
      4. try {
      5. response = client.getAcsResponse(request);
      6. } catch (ServerException e) {
      7. throw new RuntimeException("SearchMediaWorkflowRequest Server failed");
      8. } catch (ClientException e) {
      9. throw new RuntimeException("SearchMediaWorkflowRequest Client failed");
      10. }
      11. return response;
      12. }
    • Hangzhou region

      When initializing the profile and client, set RegionId to “cn-hangzhou”. No special configuration is required during the API call.

      1. import com.aliyuncs.profile.DefaultProfile;
      2. import com.aliyuncs.DefaultAcsClient;
      1. DefaultProfile profile = DefaultProfile.getProfile(
      2. "cn-hangzhou",
      3. accessKeyId,
      4. accessKeySecret);
      5. DefaultAcsClient client = new DefaultAcsClient(profile);
      6. searchMediaWorkflow(client);
    • Beijing region

      When initializing the profile and client, set RegionId to “cn-beijing”. No special configuration is required during the API call.

      1. import com.aliyuncs.profile.DefaultProfile;
      2. import com.aliyuncs.DefaultAcsClient;
      1. DefaultProfile profile = DefaultProfile.getProfile(
      2. "cn-beijing",
      3. accessKeyId,
      4. accessKeySecret);
      5. DefaultAcsClient client = new DefaultAcsClient(profile);
      6. searchMediaWorkflow(client);