All Products
Document Center

Install latest Java SDK

Last Updated: May 31, 2019

The file name of the new version SDK usually starts with aliyun-XXXX-sdk, followed by the product name, for example the Alibaba Cloud BOA (BSS OpenAPI) name aliyun-java-sdk-bssopenapi. The aliyun-java-sdk-core core package encapsulates certain classes used in all product SDKs, such as the IClientProfile, IAcsClient, and exception classes. The classes are packed in different JAR packages by product.

Sample of using the Java SDK

The API method GetOrderDetail is used to query the details of a specified order in this sample. We will use it as an example to demonstrate the process of using Java SDKs. The aliyun-java-sdk-core package contains the IClientProfile and IAcsClient classes, and the aliyun-java-sdk-ecs package contains other classes.

  1. Create a profile object: create an instance of the IClientProfile class named profile, which contains AccessKeyID, AccessKeySecret, and the default region information.ap-southeast-1 is the only region for BssOpenApi.

    1. //set BssOpenApi default region infomation
    2. DefaultProfile.addEndpoint("ap-southeast-1","ap-southeast-1","BssOpenApi",
    3. "");
    4. // #ak is your AccessKey, and aks is your AccessKeySecret
    5. IClientProfile profile = DefaultProfile.getProfile("ap-southeast-1", ak, aks);
  2. Create a client object: create an IAcsClient object named client from the previously created IClientProfile profile, and subsequent responses are obtained from IClientProfile. This object contains the response data that you will retrieve later.

    1. IAcsClient client = new DefaultAcsClient(profile);
  3. Create the request class: create a request class that corresponds to the method, and name the class by adding Request to the end of an API method name. For example, if the name of the API method that queries the details of a specified order, the corresponding Request class name is GetOrderDetail Request. It uses a constructor to generate a default describe class.

    1. GetOrderDetailRequest request = new GetOrderDetailRequest();
  4. Specify request parameters: specify required API parameters by using the setter setXxx. For example, the GetOrderDetail API method requires the OrderId parameter. Use other setters to set other parameters.

    1. request.setRequestId("123");
  5. Obtain the response to the request using the IAcsClient object.

    1. GetOrderDetailResponse response = client.getAcsResponse(request);

    Obtain the response parameters from the response: call the getter getXxx in the response to obtain the response values.The call process is now concluded.