すべてのプロダクト
Search
ドキュメントセンター

:クイックスタート

最終更新日:Apr 10, 2024

ここでは、Java SDK クイックスタートのプロセスについて説明します。

  1. AcsClient インスタンスを作成します。

    DefaultProfile profile = DefaultProfile.getProfile(
                 mpsRegionId,      // region ID
                 accessKeyId,      //AccessKey ID of RAM account 
                 accessKeySecret); //Access Key Secret of RAM account
    IAcsClient client = new DefaultAcsClient(profile);
  2. リクエストを作成し、パラメーターを設定します。

    SubmitJobsRequest request = new SubmitJobsRequest();
  3. API のリクエストを開始し、戻り値を表示します。

    response = client.getAcsResponse(request);
    System.out.println("PipelineName is:" + response.getPipelineList().get(0).getName());
    System.out.println("PipelineId is:" + response.getPipelineList().get(0).getId());

コード全体

import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
public class Quick {
    private static String accessKeyId = "xxx";
    private static String accessKeySecret = "xxx";
    private static String[] mpsRegionIds = new String[] {
            "cn-hangzhou", "cn-beijing","cn-shenzhen", "cn-shanghai",
            "cn-hongkong", "us-west-1", "ap-southeast-1", "ap-northeast-1",
            "eu-central-1"
    };
    public static void main(String[] args) {
        for (String mpsRegionId : mpsRegionIds) {
            System.out.println("region id is:" + mpsRegionId);
            // Create DefaultAcsClient instance and finish initialization
            DefaultProfile profile = DefaultProfile.getProfile(
                    mpsRegionId,      // region  ID
                    accessKeyId,      // AccessKey ID of RAM account
                    accessKeySecret); // Access Key Secret of RAM account
            IAcsClient client = new DefaultAcsClient(profile);
            // Create API request and set parameters
            SearchPipelineRequest request = new SearchPipelineRequest();
            //initiate request and handle response or exceptions
            SearchPipelineResponse response;
            try {
                response = client.getAcsResponse(request);
                System.out.println("PipelineName is:" + response.getPipelineList().get(0).getName());
                System.out.println("PipelineId is:" + response.getPipelineList().get(0).getId());
            } catch (ServerException e) {
                e.printStackTrace();
            } catch (ClientException e) {
                e.printStackTrace();
            }
        }
    }
}