This section describes how to call the API of a public cloud service by using Eclipse.
You can download the sample code package from https://apig-demo.obs.eu-de.otc.t-systems.com/java/SdkDemo.zip.
The JDK version cannot be earlier than 1.8.
Replace the bold texts with actual values. If you use other methods, such as POST, PUT, and DELETE, see the corresponding annotations.
Replace the parameters in the URL, for example, project_id.
For details on how to obtain your region name, service name, AK/SK, project ID, and domain ID, see Obtaining Required Information.
//TODO: Replace eu-de with the name of the region in which the service to be accessed is located. private static final String region = "eu-de"; //TODO: Replace vpc with the name of the service you want to access. For example, ecs, vpc, iam, and elb. private static final String serviceName = "vpc"; public static void main(String[] args) throws UnsupportedEncodingException { //TODO: Replace the AK and SK with those obtained on the My Credential page. String ak = "ZIRRKMTWPTQFQI1WKNKB"; String sk = "Us0mdMNHk******YrRCnW0ecfzl"; //TODO: To specify a project ID (multi-project scenarios), add the X-Project-Id header. //TODO: To access a global service, such as IAM, DNS, CDN, and TMS, add the X-Domain-Id header to specify an account ID. //TODO: To add a header, find "Add special headers" in the AccessServiceImple.java file. //TODO: Test the API String url = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}"; get(ak, sk, url); //TODO: When creating a VPC, replace {project_id} in postUrl with the actual value. //String postUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/cloudservers"; //String postbody ="{\"vpc\": {\"name\": \"vpc\",\"cidr\": \"192.168.0.0/16\"}}"; //post(ak, sk, postUrl, postbody); //TODO: When querying a VPC, replace {project_id} in url with the actual value. //String url = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}"; //get(ak, sk, url); //TODO: When updating a VPC, replace {project_id} and {vpc_id} in putUrl with the actual values. //String putUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}"; //String putbody ="{\"vpc\":{\"name\": \"vpc1\",\"cidr\": \"192.168.0.0/16\"}}"; //put(ak, sk, putUrl, putbody); //TODO: When deleting a VPC, replace {project_id} and {vpc_id} in deleteUrl with the actual values. //String deleteUrl = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}"; //delete(ak, sk, deleteUrl); }
//TODO: Test the API String url = "https://vpc.eu-de.otc.t-systems.com/v1/{project_id}/vpcs/{vpc_id}"; get(ak, sk, url);
//TODO: Add special headers. //request.addHeader("X-Project-Id", "xxxxx");
Find Demo.java in the left pane of the Package Explorer, right-click, and choose Run AS > Java Application.
View the API call logs on the console.