This topic describes how to use Alibaba Cloud SDK for Java to call the SearchTemplate operation to search for custom transcoding templates.

Prerequisites

Before you begin, ensure that the following requirements are met:
  • You must have an Alibaba Cloud account and an AccessKey pair (AccessKey ID and AccessKey secret) to use Alibaba Cloud SDK for Java. You can create and view your AccessKey pair on the AccessKey Management page in the Alibaba Cloud Management Console.
  • You have installed Alibaba Cloud SDK for Java. For more information about SDK versions, see Alibaba Cloud SDK.
    <project>
        <modelVersion>4.0.0</modelVersion>
        <groupId>java.demo</groupId>
        <artifactId>test</artifactId>
        <version>1.0-SNAPSHOT</version>
        <dependencies>
            <! -- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-core -->
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-core</artifactId>
                <version>4.4.3</version>
            </dependency>
        <! -- https://mvnrepository.com/artifact/com.aliyun/aliyun-java-sdk-mts -->
            <dependency>
                <groupId>com.aliyun</groupId>
                <artifactId>aliyun-java-sdk-mts</artifactId>
                <version>2.7.2</version>
            </dependency>
        </dependencies>
    </project>

Sample code

This section shows the sample code:
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.exceptions.ServerException;
import com.aliyuncs.mts.model.v20140618.*;
import com.aliyuncs.profile.DefaultProfile;
import com.google.gson.Gson;

public class TestSearchTemplate {

    public static void main(String[] args) {        
        // Initialize request parameters.
        DefaultProfile profile = DefaultProfile.getProfile(
                "<your-region-id>",         // The ID of the region.
                "<your-access-key-id>",     // The AccessKey ID.
                "<your-access-key-secret>"); // The AccessKey secret.
        IAcsClient client = new DefaultAcsClient(profile);
        SearchTemplateRequest request = new SearchTemplateRequest();
        // The status of the transcoding template. Valid values: All, Normal, and Deleted. Default value: All.
        request.setState("All");
        // Paging. Default values: PageNumber = 1L. PageSize = 10L.
        request.setPageNumber(1L);
        request.setPageSize(10L);
        try {
            SearchTemplateResponse response = client.getAcsResponse(request);
            System.out.println(new Gson().toJson(response));
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            System.out.println("ErrCode:" + e.getErrCode());
            System.out.println("ErrMsg:" + e.getErrMsg());
            System.out.println("RequestId:" + e.getRequestId());
        }
    }
}