Configure an endpoint

Updated at:
Copy as MD

This topic describes how to configure an endpoint in Alibaba Cloud Classic SDK for Java.

An endpoint is the network domain name used to request an API service, for example, ecs.cn-hangzhou.aliyuncs.com.

Alibaba Cloud Classic SDK provides four addressing modes for endpoints. The following list describes them in descending order of priority:

  1. User-defined: This addressing logic has the highest priority. It allows you to directly specify the exact endpoint.

    // Takes effect globally
    DefaultProfile.addEndpoint("<RegionID>", "<Product>", "<Endpoint>");
    
    // Takes effect only for the current request
    DescribeRegionsRequest request = new DescribeRegionsRequest();
    request.setSysEndpoint("<Endpoint>");
  2. Endpoint concatenation rule: This addressing logic takes effect only when you send a request over a VPC or when the cloud service SDK contains an endpoint data file. Example of an endpoint data file: Ecs Endpoint Data File.

    // Public network request
    request.productNetwork = "public"; // The default value of `productNetwork` is `public`, so you do not need to configure `productNetwork` in most cases
    
    // Cross-domain request
    request.productNetwork = "share";
    
    // IPv6 request
    request.productNetwork = "ipv6";
    
    // Proxy request
    request.productNetwork = "proxy";
    
    // Internal request
    request.productNetwork = "inner";
    
    // IPv4/IPv6 dual-stack request
    request.productNetwork = "dualstack";
    
    // VPC request
    request.productNetwork = "vpc";
    // Alternatively, enable the `enableUsingVpcEndpoint` configuration to access the VPC network
    DefaultProfile profile = DefaultProfile.getProfile("<RegionID>", "<AccessKeyId>", "<AccessKeySecret>");
    profile.enableUsingVpcEndpoint();
  3. SDK core addressing: The endpoint is resolved based on the endpoints.json data file in Java SDK Core.

  4. Location service addressing: The endpoint is obtained from the remote end by calling the Location service API. This mode requires the cloud service SDK to provide a ServiceCode. It is the primary addressing mode of Alibaba Cloud Classic SDK. However, the Location service supports only public network access. As a result, errors occur easily, which increases the troubleshooting costs for developers.