public class EC2MetadataClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private static java.lang.String |
EC2_METADATA_SERVICE_URL
Default endpoint for the Amazon EC2 Instance Metadata Service.
|
private static org.apache.commons.logging.Log |
log |
static java.lang.String |
SECURITY_CREDENTIALS_RESOURCE
Default resource path for credentials in the Amazon EC2 Instance Metadata Service.
|
Constructor and Description |
---|
EC2MetadataClient() |
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getDefaultCredentials()
Connects to the Amazon EC2 Instance Metadata Service to retrieve the
default credential information (if any).
|
private java.net.URL |
getEc2MetadataServiceUrlForResource(java.lang.String resourcePath)
Constructs a URL to the EC2 metadata service for the specified
resource path.
|
java.lang.String |
readResource(java.lang.String resourcePath)
Connects to the metadata service to read the specified resource and
returns the text contents.
|
private java.lang.String |
readResponse(java.net.HttpURLConnection connection)
Reads a response from the Amazon EC2 Instance Metadata Service and
returns the content as a string.
|
private static final java.lang.String EC2_METADATA_SERVICE_URL
public static final java.lang.String SECURITY_CREDENTIALS_RESOURCE
private static final org.apache.commons.logging.Log log
public java.lang.String getDefaultCredentials() throws java.io.IOException
java.io.IOException
- If any problems are encountered while connecting to the
Amazon EC2 Instance Metadata Service.public java.lang.String readResource(java.lang.String resourcePath) throws java.io.IOException, AmazonClientException
resourcePath
- The resourcejava.io.IOException
- If any problems were encountered while connecting to metadata
service for the requested resource path.AmazonClientException
- If the requested metadata service is not found.private java.lang.String readResponse(java.net.HttpURLConnection connection) throws java.io.IOException
connection
- The connection to the Amazon EC2 Instance Metadata Service.java.io.IOException
- If any problems ocurred while reading the response.private java.net.URL getEc2MetadataServiceUrlForResource(java.lang.String resourcePath) throws java.io.IOException
resourcePath
- The resource portion of the URL.java.io.IOException
- If a valid URL could not be constructed.