Java SDK user guide

Updated at:

You can use the Java SDK provided by AHAS to make API calls.

Prerequisites

Install JDK 1.6 or a later version.

Get the Java SDK

You can obtain the Java SDK directly from Maven. This is the recommended method for online environments.

Open the pom.xml file in your Maven project and add the aliyun-java-sdk-core and aliyun-java-sdk-ahass-openapi dependencies.

<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-core</artifactId>
<version>4.5.6</version>
</dependency>
<dependency>
  <groupId>com.aliyun</groupId>
  <artifactId>aliyun-java-sdk-ahas-openapi</artifactId>
  <version>1.0.4</version>
</dependency>

Use the Java SDK to call an API

Replace aliyun_user_ak, aliyun_user_sk, and region_id in the following example with your actual parameter values.

import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.ahas_openapi.model.v20190901.ListFlowRulesOfAppRequest;
import com.aliyuncs.ahas_openapi.model.v20190901.ListFlowRulesOfAppResponse;
import com.aliyuncs.profile.DefaultProfile;


public class ListFlowRuleDemo {
    public static void main(String[] args){
        String regionId = "cn-hangzhou"; // The ID of the region where the application that calls the API resides.
        String accessKey = "**************"; // The AccessKey ID of your Alibaba Cloud account or RAM user.
        String accessSecret = "**************"; // The AccessKey secret of your Alibaba Cloud account or RAM user.
        String appName = "ahas-demo"; // The name of the application to query.
        String namespace = "default"; // The namespace where the application resides.

        DefaultProfile profile = DefaultProfile.getProfile(regionId, accessKey, accessSecret);
        IAcsClient client = new DefaultAcsClient(profile);
        ListFlowRulesOfAppRequest request = new ListFlowRulesOfAppRequest();
        // To call the OpenAPI over the internet, set ahasRegionId to public. Do not set this parameter for other regions.
        request.setAhasRegionId("public");
        request.setAppName(appName);
        request.setNamespace(namespace);
        try{
            // Send the request.
            ListFlowRulesOfAppResponse response = client.getAcsResponse(request);
            // Get and process the response.
            System.out.println(response.getData());
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}
Important

To manage an application that is connected over the internet, set the ahasRegionId field to public.

Regions and endpoints

The following table lists the service endpoints for the AHAS API in different regions.

Region Name

Region ID

Endpoint

China (Hangzhou)

cn-hangzhou

ahas.cn-hangzhou.aliyuncs.com

China (Shanghai)

cn-shanghai

ahas.cn-shanghai.aliyuncs.com

China (Beijing)

cn-beijing

ahas.cn-beijing.aliyuncs.com

China (Zhangjiakou)

cn-zhangjiakou

ahas.cn-zhangjiakou.aliyuncs.com

China (Shenzhen)

cn-shenzhen

ahas.cn-shenzhen.aliyuncs.com

Internet

cn-hangzhou

ahas.cn-hangzhou.aliyuncs.com