Java SDK

Updated at:

This topic describes how to install and use the Java SDK.

Install the Java SDK

  1. Install the Alibaba Cloud VS SDK for Java.

For example, to install the SDK by adding a Maven dependency, add the following dependency to the `pom.xml` file:

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>vs20181212</artifactId>
  <version>2.0.0</version>
</dependency>
		
Note

Use the latest version of the Visual Edge Computing Service SDK. For the specific version number, see the SDK Center.

Use the Java SDK

The following code example shows the three main steps to call the Java SDK:

  1. Create and initialize a Config instance.

  2. Create an API request and set the parameters.

  3. Initiate the request and handle the response or exceptions.

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

import com.aliyun.tea.*;

public class Sample {

    /**
     * description :
     * <p>Initializes the client using an AccessKey pair.</p>
     * @return Client
     * 
     * @throws Exception
     */
    public static com.aliyun.vs20181212.Client createClient() throws Exception {
        // Leaking your project code may expose your AccessKey and compromise the security of all resources in your account. The following code is for reference only.
        // Use a more secure method, such as Security Token Service (STS), for authentication. For more information about authentication methods, see: https://help.aliyun.com/document_detail/378657.html.
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is set.
                .setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
                // Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set.
                .setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
        // For the endpoint, see https://api.aliyun.com/product/vs
        config.endpoint = "vs.cn-beijing.aliyuncs.com";
        return new com.aliyun.vs20181212.Client(config);
    }

    public static void main(String[] args_) throws Exception {
        java.util.List<String> args = java.util.Arrays.asList(args_);
        com.aliyun.vs20181212.Client client = Sample.createClient();
        com.aliyun.vs20181212.models.AddVsPullStreamInfoConfigRequest addVsPullStreamInfoConfigRequest = new com.aliyun.vs20181212.models.AddVsPullStreamInfoConfigRequest()
                .setDomainName("your_value")
                .setAppName("your_value");
        try {
            // Print the API return value when you run the code.
            client.addVsPullStreamInfoConfigWithOptions(addVsPullStreamInfoConfigRequest, new com.aliyun.teautil.models.RuntimeOptions());
        } catch (TeaException error) {
            // This section only prints the exception. Handle exceptions with caution. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Troubleshooting URL
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        } catch (Exception _error) {
            TeaException error = new TeaException(_error.getMessage(), _error);
            // This section only prints the exception. Handle exceptions with caution. Do not ignore exceptions in your project.
            // Error message
            System.out.println(error.getMessage());
            // Troubleshooting URL
            System.out.println(error.getData().get("Recommend"));
            com.aliyun.teautil.Common.assertAsString(error.message);
        }        
    }
}