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 .