This topic describes how to use the SMC Java SDK to call the StopReplicationJob operation to stop a migration task.

Background information

You can call the StopReplicationJob operation to stop a migration task. For more information, see StopReplicationJob.

Sample code

The following code can be used to stop a migration task:

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.profile.DefaultProfile;
import com.aliyuncs.smc.model.v20190601.StartReplicationJobResponse;
import com.aliyuncs.smc.model.v20190601.StopReplicationJobRequest;
import com.aliyuncs.smc.model.v20190601.StopReplicationJobResponse;

public class StopReplicationJob {
    public static void main(String[] args) {
        // Initialize the AcsClient instance, and set the region ID and your AccessKey pair.
        DefaultProfile profile = DefaultProfile.getProfile("<region-Id>", "<accessKeyId>", "<accessSecret>");
        IAcsClient client = new DefaultAcsClient(profile);

        // Create an API request and configure its parameters.
        StopReplicationJobRequest request = new StopReplicationJobRequest();
        // The ID of the migration task.

        // Send the request to obtain the return value or handle the exception.
        try {
            StopReplicationJobResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
        } catch (ClientException e) {