Sample code for 30+ languages & platforms
Java

Amazon Voice ID - Describe Domain

See more Amazon Voice ID Examples

Describes the specified domain.

Chilkat Java Downloads

Chilkat2 Java
import com.chilkatsoft.chilkat2.AuthAws;
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.JsonObject;
import com.chilkatsoft.chilkat2.Rest;
import com.chilkatsoft.chilkat2.StringBuilder;

public class ChilkatExample {

    public static void main(String[] args) {
        // This example requires the Chilkat API to have been previously unlocked.
        // See Global Unlock Sample for sample code.

        Rest rest = new Rest();

        AuthAws authAws = new AuthAws();
        authAws.setAccessKey("AWS_ACCESS_KEY");
        authAws.setSecretKey("AWS_SECRET_KEY");

        // Don't forget to change the region to your particular region. (Also make the same change in the call to Connect below.)
        authAws.setRegion("us-west-2");
        authAws.setServiceName("voiceid");
        // SetAuthAws causes Chilkat to automatically add the following headers: Authorization, X-Amz-Date
        rest.setAuthAws(authAws);

        // URL: https://voiceid.us-west-2.amazonaws.com/
        boolean bTls = true;
        int port = 443;
        boolean bAutoReconnect = true;
        // Use the same region as specified above.
        try {
            rest.connect("voiceid.us-west-2.amazonaws.com", port, bTls, bAutoReconnect);
        } catch (ChilkatException e) {
            System.out.println("ConnectFailReason: " + rest.getConnectFailReason());
            System.out.println(e.getLastErrorText());
            return;
        }

        // Use this online tool to generate code from sample JSON:
        // Generate Code to Create JSON

        // The following JSON is sent in the request body.

        // {
        //     "DomainId": "<domainId>"
        // }
        //

        JsonObject json = new JsonObject();
        json.updateString("DomainId", "<domainId>");

        rest.addHeader("Content-Type", "application/x-amz-json-1.0");
        rest.addHeader("X-Amz-Target", "VoiceID.DescribeDomain");
        rest.addHeader("Accept-Encoding", "identity");

        StringBuilder sbRequestBody = new StringBuilder();
        json.emitSb(sbRequestBody);
        StringBuilder sbResponseBody = new StringBuilder();
        try {
            rest.fullRequestSb("POST", "/", sbRequestBody, sbResponseBody);
        } catch (ChilkatException e) {
            System.out.println(e.getLastErrorText());
            return;
        }

        int respStatusCode = rest.getResponseStatusCode();
        System.out.println("response status code = " + respStatusCode);
        if (respStatusCode != 200) {
            System.out.println("Response Status Code = " + respStatusCode);
            System.out.println("Response Header:");
            System.out.println(rest.getResponseHeader());
            System.out.println("Response Body:");
            System.out.println(sbResponseBody.getAsString());
            return;
        }

        JsonObject jsonResponse = new JsonObject();
        jsonResponse.loadSb(sbResponseBody);

        jsonResponse.setEmitCompact(false);
        System.out.println(jsonResponse.emit());

        // If successful, the response status code is 200, and the response syntax:

        // {
        //    "Domain": {
        //       "Arn": "string",
        //       "CreatedAt": number,
        //       "Description": "string",
        //       "DomainId": "string",
        //       "DomainStatus": "string",
        //       "Name": "string",
        //       "ServerSideEncryptionConfiguration": {
        //          "KmsKeyId": "string"
        //       },
        //       "UpdatedAt": number
        //    }
        // }

        String DomainArn = jsonResponse.stringOf("Domain.Arn");
        int DomainCreatedAt = jsonResponse.intOf("Domain.CreatedAt");
        String DomainDescription = jsonResponse.stringOf("Domain.Description");
        String DomainDomainId = jsonResponse.stringOf("Domain.DomainId");
        String DomainDomainStatus = jsonResponse.stringOf("Domain.DomainStatus");
        String DomainName = jsonResponse.stringOf("Domain.Name");
        String DomainServerSideEncryptionConfigurationKmsKeyId = jsonResponse.stringOf("Domain.ServerSideEncryptionConfiguration.KmsKeyId");
        int DomainUpdatedAt = jsonResponse.intOf("Domain.UpdatedAt");
    }
}