public static String getActivationKey(String gatewayAddress, String activationRegionName) throws AmazonClientException {
        try {
            HttpParams httpClientParams = new BasicHttpParams();
            httpClientParams.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false);
            DefaultHttpClient client = new DefaultHttpClient(httpClientParams);

            String url = "http://" + gatewayAddress;
            if (activationRegionName != null) {
                url += "/?activationRegion=" + activationRegionName;
            }
            HttpGet method = new HttpGet(url);
            HttpResponse response = client.execute(method);
            int statusCode = response.getStatusLine().getStatusCode();

            if (statusCode != 302)
                throw new AmazonClientException("Could not fetch activation key.  HTTP status code: " + statusCode);

            Header[] headers = response.getHeaders("Location");
            if (headers.length < 1)
                throw new AmazonClientException("Could not fetch activation key, no location header found");

            String activationUrl = headers[0].getValue();
            String[] parts = activationUrl.split("activationKey=");

            if (parts.length < 2 || null == parts[1])
                throw new AmazonClientException("Unable to get activation key from : " + activationUrl);

            return parts[1];
        } catch (IOException ioe) {
            throw new AmazonClientException("Unable to get activation key", ioe);
        }
    }
Sends a request to the AWS Storage Gateway server running at the
specified address and activation region, and returns the activation key
for that server.

@param gatewayAddress
           The DNS name or IP address of a running AWS Storage Gateway

@param activationRegionName
           The name of the region in which the gateway will be activated.

@return The activation key required for some API calls to AWS Storage
        Gateway.

@throws AmazonClientException
            If any problems are encountered while trying to contact the
            remote AWS Storage Gateway server.
aws-java-sdk-storagegateway/src/main/java/com/amazonaws/services/storagegateway/StorageGatewayUtils.java