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.
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.
Create a profile object: create an instance of the IClientProfile class named profile, which contains AccessKeyID, AccessKeySecret, and the default region information.
ap-southeast-1is the only region for BssOpenApi.
//set BssOpenApi default region infomation
// #ak is your AccessKey, and aks is your AccessKeySecret
IClientProfile profile = DefaultProfile.getProfile("ap-southeast-1", ak, aks);
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.
IAcsClient client = new DefaultAcsClient(profile);
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.
GetOrderDetailRequest request = new GetOrderDetailRequest();
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.
Obtain the response to the request using the IAcsClient object.
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.