All Products
Search
Document Center

ApsaraVideo Live:Use the server SDK for Java

Last Updated:Feb 05, 2026

This topic describes how to use the server SDK for Java of ApsaraVideo Live and provides the sample code.

Prerequisites

  • A Resource Access Management (RAM) user is created and obtains the necessary permissions to use APIs provided by ApsaraVideo Live. For more information, see Create and grant permissions to a RAM user.

  • An AccessKey pair is obtained for the RAM user. The AccessKey pair is used to verify the user identity for making API calls. For more information, see Create an AccessKey pair.

  • Java 1.8 or later is installed.

Procedure

Install the SDK

To install the server SDK for Java by using Maven, add the following dependencies to the pom.xml file in your project:

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>alibabacloud-live20161101</artifactId>
  <version>2.0.1</version>
</dependency>

Use the SDK

The server SDK for Java supports various features. The following sample code provides an example on how to query the snapshot configurations of a streaming domain:

// This file is auto-generated, don't edit it. Thanks.
package demo;

import com.aliyun.auth.credentials.Credential;
import com.aliyun.auth.credentials.provider.StaticCredentialProvider;
import com.aliyun.core.http.HttpClient;
import com.aliyun.core.http.HttpMethod;
import com.aliyun.core.http.ProxyOptions;
import com.aliyun.httpcomponent.httpclient.ApacheAsyncHttpClientBuilder;
import com.aliyun.sdk.service.live20161101.models.*;
import com.aliyun.sdk.service.live20161101.*;
import com.google.gson.Gson;
import darabonba.core.RequestConfiguration;
import darabonba.core.client.ClientOverrideConfiguration;
import darabonba.core.utils.CommonUtil;
import darabonba.core.TeaPair;

//import javax.net.ssl.KeyManager;
//import javax.net.ssl.X509TrustManager;
import java.net.InetSocketAddress;
import java.time.Duration;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.io.*;

public class DescribeLiveSnapshotConfig {
    public static void main(String[] args) throws Exception {

        // HttpClient Configuration
        /*HttpClient httpClient = new ApacheAsyncHttpClientBuilder()
                .connectionTimeout(Duration.ofSeconds(10)) // Set the connection timeout time, the default is 10 seconds
                .responseTimeout(Duration.ofSeconds(10)) // Set the response timeout time, the default is 20 seconds
                .maxConnections(128) // Set the connection pool size
                .maxIdleTimeOut(Duration.ofSeconds(50)) // Set the connection pool timeout, the default is 30 seconds
                // Configure the proxy
                .proxy(new ProxyOptions(ProxyOptions.Type.HTTP, new InetSocketAddress("<YOUR-PROXY-HOSTNAME>", 9001))
                        .setCredentials("<YOUR-PROXY-USERNAME>", "<YOUR-PROXY-PASSWORD>"))
                // If it is an https connection, you need to configure the certificate, or ignore the certificate(.ignoreSSL(true))
                .x509TrustManagers(new X509TrustManager[]{})
                .keyManagers(new KeyManager[]{})
                .ignoreSSL(false)
                .build();*/

        // Configure Credentials authentication information, including ak, secret, token
        StaticCredentialProvider provider = StaticCredentialProvider.create(Credential.builder()
                // Please ensure that the environment variables ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET are set.
                .accessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                .accessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
                //.securityToken(System.getenv("ALIBABA_CLOUD_SECURITY_TOKEN")) // use STS token
                .build());

        // Configure the Client
        AsyncClient client = AsyncClient.builder()
                .region("<Your RegionId>") // Region ID
                //.httpClient(httpClient) // Use the configured HttpClient, otherwise use the default HttpClient (Apache HttpClient)
                .credentialsProvider(provider)
                //.serviceConfiguration(Configuration.create()) // Service-level configuration
                // Client-level configuration rewrite, can set Endpoint, Http request parameters, etc.
                .overrideConfiguration(
                        ClientOverrideConfiguration.create()
                                  // For endpoints, refer to https://api.alibabacloud.com/product/live
                                .setEndpointOverride("live.aliyuncs.com")
                        //.setConnectTimeout(Duration.ofSeconds(30))
                )
                .build();

        // Parameter settings for API request
        DescribeLiveSnapshotConfigRequest describeLiveSnapshotConfigRequest = DescribeLiveSnapshotConfigRequest.builder()
                .domainName("<Your DomainName>")
                .appName("<Your AppName>")
                // Request-level configuration rewrite, can set Http request parameters, etc.
                // .requestConfiguration(RequestConfiguration.create().setHttpHeaders(new HttpHeaders()))
                .build();

        // Asynchronously get the return value of the API request
        CompletableFuture<DescribeLiveSnapshotConfigResponse> response = client.describeLiveSnapshotConfig(describeLiveSnapshotConfigRequest);
        // Synchronously get the return value of the API request
        DescribeLiveSnapshotConfigResponse resp = response.get();
        System.out.println(new Gson().toJson(resp));
        // Asynchronous processing of return values
        /*response.thenAccept(resp -> {
            System.out.println(new Gson().toJson(resp));
        }).exceptionally(throwable -> { // Handling exceptions
            System.out.println(throwable.getMessage());
            return null;
        });*/

        // Finally, close the client
        client.close();
    }

}
Note
  • You can use the sample code to test the SDK functionality. Replace the placeholders with actual values in the sample code.

  • The regionId parameter specifies the ID of the service region. To obtain the region ID, see Endpoints.

  • The ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET parameters specify the AccessKey pair. For information about how to obtain an AccessKey pair, see Create an AccessKey pair.

  • DescribeLiveSnapshotConfigRequest and DescribeLiveSnapshotConfigResponse are request and response classes for querying snapshot configurations.

  • For information about request and response parameters, see DescribeLiveSnapshotConfig.

  • The APIs provided by ApsaraVideo Live have limits on the maximum number of queries per second (QPS). For information about QPS limits, see Flow control information.

In this example, DescribeLiveSnapshotConfigResponse is a deserialized response object. If you want to work directly with the raw HTTP response, change the client.getAcsResponse method to the client.doAction method. Sample code:

HttpResponse httpResponse=client.doAction(describeLiveStreamSnapshotInfoRequest);
int status=httpResponse.getStatus();

Note:

  • HTTP status codes from 200 to 299 indicate successful calls.

  • HTTP status codes from 300 to 499 trigger the SDK to throw a ClientException, which indicates a client error.

  • HTTP status codes 500 and above trigger the SDK to throw a ServerException, which indicates a server error.

Important

When you use ApsaraVideo Live SDKs, adhere to the following naming conventions:

  • Add the suffix Request to the API name to denote the request class.

  • Add the suffix Response to the API name to denote the response class.

The following table lists some common APIs of ApsaraVideo Live.

API

Request class

Response class

DescribeLiveSnapshotConfig

DescribeLiveSnapshotConfigRequest

DescribeLiveSnapshotConfigResponse

AddLiveAppRecordConfig

AddLiveAppRecordConfigRequest

AddLiveAppRecordConfigResponse

DescribeLiveRecordConfig

DescribeLiveRecordConfigRequest

DescribeLiveRecordConfigResponse

AddLiveStreamTranscode

AddLiveStreamTranscodeRequest

AddLiveStreamTranscodeResponse

DescribeLiveStreamTranscodeInfo

DescribeLiveStreamTranscodeInfoRequest

DescribeLiveStreamTranscodeInfoResponse

BatchSetLiveDomainConfig

BatchSetLiveDomainConfigsRequest

BatchSetLiveDomainConfigsResponse

DescribeLiveDomainConfigs

DescribeLiveDomainConfigsRequest

DescribeLiveDomainConfigsResponse

For information about all available APIs, see API overview.

Access control

In addition to system policies that authorize RAM users to access APIs, you can create custom policies to implement finer-grained access control based on the resource type. For example, you can configure a policy to grant RAM User A access to an API operation only on Domain A and RAM User B access only on Domain B. For information about how to implement access control, see Create a custom policy.

The API reference provides the authorization information of each API, describing what permissions you can grant to a RAM user or role for using the operation. The following figure shows the authorization information of the AddLiveAppSnapshotConfig operation.

image

Note

For information about access control supported by each API, see RAM authorization.