Alan adı kayıt görevlerini gönderme gibi API işlemlerini çağırmak üzere Alibaba Cloud Domain Names Java SDK'sını yükleyin ve kullanın.
Ön Koşullar
Bir RAM kullanıcısı AccessKey çifti oluşturun. Hesap AccessKey'inin sızması tüm kaynakları riske attığından, bir Alibaba Cloud hesabı yerine bir RAM kullanıcısı kullanmanızı öneririz. AccessKey çiftini nasıl alacağınız hakkında bilgi için bkz. AccessKey Oluşturma.
-
RAM kullanıcısının alan adı yönetimi izinlerine sahip olması gerekir. Bu örnekte AliyunDomainFullAccess sistem ilkesi kullanılır.
-
Sistem ilkeleri:
AliyunDomainFullAccess: Domain Names üzerinde tam izinler.
AliyunDomainReadonlyAccess: Alan adı kaydı ve yönetimi için salt okunur erişim.
-
Özel bir ilke de kullanabilirsiniz.
Özel bir ilkenin nasıl oluşturulacağı hakkında daha fazla bilgi için bkz. Özel İlke Oluşturma.
-
RAM kullanıcısı AccessKey çiftini ortam değişkenlerinde yapılandırın. Daha fazla bilgi için bkz. Linux, macOS ve Windows'ta Ortam Değişkenlerini Yapılandırma.
SDK'yı Yükleyin
-
Maven yapılandırma dosyanıza bir depo ekleyin.
<repositories> <repository> <id>sonatype-nexus-staging</id> <name>Sonatype Nexus Staging</name> <url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>true</enabled> </snapshots> </repository> </repositories> -
Projenizin pom.xml
<dependencies>bölümüne aşağıdaki bağımlılığı ekleyin, ardından Maven'i yenileyin.<dependency> <groupId>com.aliyun</groupId> <artifactId>domain20180129</artifactId> <version>3.15.1</version> </dependency>
SDK'yı Kullanın
1. Bir istemci başlatın
Alibaba Cloud SDK'ları, AccessKey çiftleri ve STS belirteçleri gibi istemci başlatma için birden fazla kimlik bilgisi türünü destekler. Daha fazla bilgi için bkz. Kimlik Bilgilerini Yönetme. Bu örnekte bir AccessKey çifti kullanılır.
import com.aliyun.domain20180129.Client;
import com.aliyun.teaopenapi.models.Config;
public class Sample {
private static Client createClient() throws Exception {
Config config = new Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
// Specify an endpoint. For information about endpoints, visit https://api.alibabacloud.com/product/Domain.
.setEndpoint("domain.aliyuncs.com");
return new Client(config);
}
}
2. Bir istek nesnesi oluşturun
Hedef API işlemini ve parametrelerini API Referansı bölümünde bulun ve istek nesnesini oluşturun.
İstek nesneleri {API adı}Request adlandırma kuralını izler. Örneğin, SaveSingleTaskForCreatingOrderActivate için SaveSingleTaskForCreatingOrderActivateRequest kullanılır.
SaveSingleTaskForCreatingOrderActivateRequest request = new SaveSingleTaskForCreatingOrderActivateRequest()
.setDomainName("example.com");
3. İşlemi çağırın
Yanıt nesneleri {API adı}Response adlandırma kuralını izler. Örneğin, SaveSingleTaskForCreatingOrderActivate işlemi SaveSingleTaskForCreatingOrderActivateResponse döndürür.
// Specify the runtime parameters.
RuntimeOptions runtime = new RuntimeOptions();
SaveSingleTaskForCreatingOrderActivateResponse response = client.saveSingleTaskForCreatingOrderActivateWithOptions(request, runtime);
4. Özel durumları yönetin
Java SDK'sı iki özel durum türü fırlatır: TeaUnretryableException ve TeaException.
TeaUnretryableException: Tüm yeniden deneme girişimleri tükendikten sonra ağ hataları devam ettiğinde fırlatılır.
-
TeaException: İş mantığı hataları için fırlatılır.
ÖnemliBu örnekte yalnızca gösterim amacıyla hatalar yazdırılır. Üretim ortamında sistem kararlılığını sağlamak için özel durumları doğru şekilde yönetin; hataları raporlayın, ayrıntıları günlüğe kaydedin ve yeniden denemeler uygulayın.
try {
Client client = createClient();
SaveSingleTaskForCreatingOrderActivateRequest request = new SaveSingleTaskForCreatingOrderActivateRequest()
.setDomainName("example.com");
// Specify the runtime parameters.
RuntimeOptions runtime = new RuntimeOptions();
SaveSingleTaskForCreatingOrderActivateResponse response = client.saveSingleTaskForCreatingOrderActivateWithOptions(request, runtime);
} catch (TeaUnretryableException ue) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
ue.printStackTrace();
// Obtain the error message.
System.out.println(ue.getMessage());
// Obtain the request message and query the request information when an error occurs.
System.out.println(ue.getLastRequest());
} catch (TeaException e) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
e.printStackTrace();
// Obtain the error code.
System.out.println(e.getCode());
// Obtain the error message that contains the request ID.
System.out.println(e.getMessage());
// Obtain the detailed error information that is returned by the server.
System.out.println(e.getData());
} catch (Exception e) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
e.printStackTrace();
}
5. Tam örnek
import com.aliyun.domain20180129.Client;
import com.aliyun.domain20180129.models.SaveSingleTaskForCreatingOrderActivateRequest;
import com.aliyun.domain20180129.models.SaveSingleTaskForCreatingOrderActivateResponse;
import com.aliyun.tea.TeaException;
import com.aliyun.tea.TeaUnretryableException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;
public class Sample {
private static Client createClient() throws Exception {
Config config = new Config()
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_ID environment variable is configured in the code runtime environment.
.setAccessKeyId(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_ID"))
// Required. Make sure that the ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variable is configured in the code runtime environment.
.setAccessKeySecret(System.getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET"))
// Specify an endpoint. For information about endpoints, visit https://api.alibabacloud.com/product/Domain.
.setEndpoint("domain.aliyuncs.com");
return new Client(config);
}
public static void main(String[] args_) {
try {
Client client = createClient();
SaveSingleTaskForCreatingOrderActivateRequest request = new SaveSingleTaskForCreatingOrderActivateRequest()
.setDomainName("example.com");
// Specify the runtime parameters.
RuntimeOptions runtime = new RuntimeOptions();
SaveSingleTaskForCreatingOrderActivateResponse response = client.saveSingleTaskForCreatingOrderActivateWithOptions(request, runtime);
} catch (TeaUnretryableException ue) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
ue.printStackTrace();
// Obtain the error message.
System.out.println(ue.getMessage());
// Obtain the request message.
System.out.println(ue.getLastRequest());
} catch (TeaException e) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
e.printStackTrace();
// Obtain the error code.
System.out.println(e.getCode());
// Obtain the error message that contains the request ID.
System.out.println(e.getMessage());
// Obtain the detailed error information that is returned by the server.
System.out.println(e.getData());
} catch (Exception e) {
// Handle exceptions with caution in your actual business scenario and do not ignore exceptions in your project. In this example, error messages are printed for reference only.
e.printStackTrace();
}
}
}