General workflow
Learn to use the Java SDK for Elastic Desktop Service (EDS) Enterprise. This topic uses the DescribeOfficeSites API operation to query office sites as an example.
Prerequisites
You have created an AccessKey. For more information, see Create an AccessKey.
To avoid the security risks of exposing your Alibaba Cloud account's AccessKey, we recommend that you create a RAM user. Grant the RAM user the required permissions for Elastic Desktop Service (EDS) Enterprise, and then use that user's AccessKey to call the SDK. For more information, see Permission management overview.
Procedure
Before writing code, test an API operation in the OpenAPI Portal. The following steps use the DescribeOfficeSites API operation, which queries office sites, as an example.
-
Open the DescribeOfficeSites API reference and click Test in the upper-right corner.
-
On the OpenAPI Portal page, follow the prompts to sign in to your Alibaba Cloud account.
-
Enter the required parameters and click Initiate Call to view the result.
On the DescribeOfficeSites debugging page, configure parameters such as RegionId (for example,
cn-shanghai), OfficeSiteType, OfficeSiteId, Status, SecurityProtection, and MaxResults. A successful call returns a status code of 200 and a JSON response body that contains theTotalCountand theOfficeSitesarray. The array includes details about the office site, such as itsNameandCidrBlock. -
After a successful API call, click the SDK Sample tab in the right-side panel, select a language, and then click Download Project to download the sample code.
NoteThe downloaded project includes the required SDK dependencies and a demo of the API call.
Alternatively, click Run to the left of the code area to run the sample code online.
Sample code explanation
-
Initialize the
com.aliyun.teaopenapi.models.Configobject.The Config object stores the AccessKeyId, AccessKeySecret, and endpoint. In this example, the endpoint is
ecd.cn-shanghai.aliyuncs.com. For more information about regions, see View available regions and zones.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 more information about endpoints, see https://api.aliyun.com/product/ecd config.endpoint = "ecd.cn-shanghai.aliyuncs.com"; -
Instantiate a client object from the
com.aliyun.ecd20200930.Clientclass.The request and response models are available in the
com.aliyun.ecd20200930.modelspackage.com.aliyun.ecd20200930.Client client = Sample.createClient(); -
Create a request object for the API operation. The class name follows the convention: API operation name + Request.
Example:
com.aliyun.ecd20200930.models.DescribeOfficeSitesRequest describeOfficeSitesRequest = new com.aliyun.ecd20200930.models.DescribeOfficeSitesRequest() -
Set parameters for the request object.
Use the setter methods of the request object to set the required parameters.
describeOfficeSitesRequest.setRegionId("your_value") -
To get a response, use the client object to send the corresponding request.
com.aliyun.ecd20200930.models.DescribeOfficeSitesResponse resp = client.describeOfficeSitesWithOptions(describeOfficeSitesRequest, runtime); com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(resp)); -
Call the getter methods of the response object to access the returned data.
For example, to get the
requestId:String requestId = resp.getBody().getRequestId(); -
Use a
catchblock to handle exceptions.catch (Exception e) { e.printStackTrace(); }
Sample response
Full response:
{
"TotalCount": 2,
"RequestId": "27716AAC-5E4C-575F-BCF9-DB215E1CA0EB",
"OfficeSites": [
{
"CloudBoxOfficeSite": false,
"TotalEdsCountForGroup": 0,
"CidrBlock": "192.168.100.0/24",
"AdHostname": "izp323uuw9q****",
"EnableServiceRoute": false,
"DnsAddress": [
"172.16.XX.XX"
],
"Name": "DemoAD_01",
"DesktopCount": 0,
"NeedVerifyZeroDevice": false,
"SubDnsAddress": [],
"OuName": "wayne01.shanghai/WayneTestOU",
"SubnetMode": "Auto",
"CenAttachStatus": "attached",
"EnableInternetAccess": true,
"NmVersion": "DEFAULT",
"Status": "REGISTERED",
"DomainName": "wayne01.shanghai",
"TotalEdsCount": 0,
"VSwitchIds": [],
"RdsLicenseStatus": "Disabled",
"EnableAdminAccess": true,
"OfficeSiteType": "AD_CONNECTOR",
"FileSystemIds": [],
"SsoEnabled": false,
"Logs": [
{
"Message": "CreateConnector.Success",
"Level": "INFO",
"Step": "CREATE_CONNECTOR",
"TimeStamp": "2024-10-24T02:45Z"
},
{
"Message": "ConnectorStatus.NotReady",
"Level": "WARN",
"Step": "WAIT_CONNECTOR_ACTIVE",
"TimeStamp": "2024-10-24T02:45Z"
},
{
"Message": "ConnectorStatus.Ready",
"Level": "INFO",
"Step": "WAIT_CONNECTOR_ACTIVE",
"TimeStamp": "2024-10-24T02:45Z"
},
{
"Message": "CheckConnector.Success",
"Level": "INFO",
"Step": "CHECK_CONNECTOR",
"TimeStamp": "2024-10-24T02:46Z"
},
{
"Message": "WaitConnectorActive.Success",
"Level": "INFO",
"Step": "CONFIG_CONNECTOR",
"TimeStamp": "2024-10-24T02:46Z"
},
{
"Message": "User.Credential.Success",
"Level": "INFO",
"Step": "CONFIG_USER",
"TimeStamp": "2024-10-24T05:48Z"
},
{
"Message": "InvalidCredential",
"Level": "ERROR",
"Step": "CONFIG_USER",
"TimeStamp": "2024-10-24T05:49Z"
},
{
"Message": "User.Credential.Success",
"Level": "INFO",
"Step": "CONFIG_USER",
"TimeStamp": "2024-10-24T05:50Z"
},
{
"Message": "User.Credential.Success",
"Level": "INFO",
"Step": "CONFIG_USER",
"TimeStamp": "2024-10-24T05:50Z"
}
],
"MfaEnabled": false,
"OfficeSiteId": "cn-shanghai+dir-312783****",
"VpcType": "standard",
"VpcId": "vpc-uf6r0plvlj9l8u960****",
"EnableCrossDesktopAccess": false,
"ProtocolType": "ASP",
"TotalResourceAmount": 0,
"CreationTime": "2024-10-24T02:43Z",
"CenId": "cen-6y8yiwkbf6n4ku****",
"DesktopAccessType": "INTERNET",
"ADConnectors": [
{
"ConnectorStatus": "RUNNING",
"VSwitchId": "vsw-uf61s651owyd2civr****",
"ADConnectorAddress": "192.168.XX.XX",
"Specification": 1,
"NetworkInterfaceId": "eni-uf6ie3truu4cly1v****"
},
{
"ConnectorStatus": "RUNNING",
"VSwitchId": "vsw-uf61s651owyd2civr****",
"ADConnectorAddress": "192.168.XX.XX",
"Specification": 1,
"NetworkInterfaceId": "eni-uf61nhnfu3fzacp0****"
}
],
"DomainUserName": "ad-user"
},
{
"CloudBoxOfficeSite": false,
"TotalEdsCountForGroup": 0,
"CidrBlock": "10.0.0.0/8",
"EnableServiceRoute": false,
"DnsAddress": [],
"Name": "default",
"DesktopCount": 0,
"NeedVerifyZeroDevice": false,
"SubDnsAddress": [],
"OuName": "default",
"SubnetMode": "Auto",
"EnableInternetAccess": true,
"NmVersion": "DEFAULT",
"Status": "REGISTERED",
"TotalEdsCount": 0,
"VSwitchIds": [],
"NeedVerifyLoginRisk": false,
"RdsLicenseStatus": "Disabled",
"EnableAdminAccess": false,
"OfficeSiteType": "SIMPLE",
"FileSystemIds": [],
"SsoEnabled": false,
"MfaEnabled": false,
"SsoType": "NONE",
"OfficeSiteId": "cn-shanghai+dir-121772****",
"VpcType": "basic",
"EnableCrossDesktopAccess": false,
"TotalResourceAmount": 0,
"CreationTime": "2024-03-26T03:01Z",
"DesktopAccessType": "INTERNET",
"ADConnectors": []
}
]
}
Complete sample code
// This file is auto-generated, don't edit it. Thanks.
package com.aliyun.sample;
import com.aliyun.tea.*;
public class Sample {
/**
* <b>description</b> :
* <p>Initialize the client using an AccessKey pair.</p>
* @return Client
*
* @throws Exception
*/
public static com.aliyun.ecd20200930.Client createClient() throws Exception {
// Leaking project code may expose your AccessKey and compromise the security of all your resources. The following sample code is for reference only.
// We recommend that you use a more secure method, such as STS, for authentication. For more information, 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 in your runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is set in your runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"));
// For more information about endpoints, see https://api.aliyun.com/product/ecd.
config.endpoint = "ecd.cn-shanghai.aliyuncs.com";
return new com.aliyun.ecd20200930.Client(config);
}
public static void main(String[] args_) throws Exception {
java.util.List<String> args = java.util.Arrays.asList(args_);
com.aliyun.ecd20200930.Client client = Sample.createClient();
com.aliyun.ecd20200930.models.DescribeOfficeSitesRequest describeOfficeSitesRequest = new com.aliyun.ecd20200930.models.DescribeOfficeSitesRequest()
.setRegionId("cn-shanghai");
com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
try {
com.aliyun.ecd20200930.models.DescribeOfficeSitesResponse resp = client.describeOfficeSitesWithOptions(describeOfficeSitesRequest, runtime);
com.aliyun.teaconsole.Client.log(com.aliyun.teautil.Common.toJSONString(resp));
String requestId = resp.getBody().getRequestId();
System.out.println(requestId);
} catch (TeaException error) {
// The following code is for demonstration only. Handle exceptions with caution in your project and do not ignore them.
// The error message.
System.out.println(error.getMessage());
// The diagnostic address.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
} catch (Exception _error) {
TeaException error = new TeaException(_error.getMessage(), _error);
// The following code is for demonstration only. Handle exceptions with caution in your project and do not ignore them.
// The error message.
System.out.println(error.getMessage());
// The diagnostic address.
System.out.println(error.getData().get("Recommend"));
com.aliyun.teautil.Common.assertAsString(error.message);
}
}
}