Skip to content

Commit

Permalink
Version 1.5.3 of the AWS Java SDK
Browse files Browse the repository at this point in the history
This release includes a new, community contributed feature for looking up AWS regions, as well performance improvements and bug fixes.
  • Loading branch information
Fulghum committed Aug 6, 2013
1 parent cf49d27 commit 2bec875
Show file tree
Hide file tree
Showing 368 changed files with 4,449 additions and 112 deletions.
2 changes: 1 addition & 1 deletion META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: AWS SDK for Java
Bundle-SymbolicName: com.amazonaws.sdk;singleton:=true
Bundle-Version: 1.5.2
Bundle-Version: 1.5.3
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<artifactId>aws-java-sdk</artifactId>
<packaging>jar</packaging>
<name>AWS SDK for Java</name>
<version>1.5.2</version>
<version>1.5.3</version>
<description>The Amazon Web Services SDK for Java provides Java APIs for building software on AWS’ cost-effective, scalable, and reliable infrastructure products. The AWS Java SDK allows developers to code against APIs for all of Amazon's infrastructure web services (Amazon S3, Amazon EC2, Amazon SQS, Amazon Relational Database Service, Amazon AutoScaling, etc).</description>
<url>https://aws.amazon.com/sdkforjava</url>

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/amazonaws/AmazonWebServiceClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Map.Entry;
import java.util.concurrent.CopyOnWriteArrayList;

import com.amazonaws.handlers.RequestHandler;
import com.amazonaws.http.AmazonHttpClient;
Expand Down Expand Up @@ -63,7 +64,7 @@ public abstract class AmazonWebServiceClient {
public AmazonWebServiceClient(ClientConfiguration clientConfiguration) {
this.clientConfiguration = clientConfiguration;
client = new AmazonHttpClient(clientConfiguration);
requestHandlers = Collections.synchronizedList(new LinkedList<RequestHandler>());
requestHandlers = new CopyOnWriteArrayList<RequestHandler>();
}

/**
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/com/amazonaws/auth/AWS4Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,24 @@ public class AWS4Signer extends AbstractAWSSigner {
/** Date override for testing only */
protected Date overriddenDate;

protected ThreadLocal<SimpleDateFormat> dateTimeFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
final SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
return dateTimeFormat;
}
};

protected ThreadLocal<SimpleDateFormat> dateStampFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
protected SimpleDateFormat initialValue() {
final SimpleDateFormat dateStampFormat = new SimpleDateFormat("yyyyMMdd");
dateStampFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
return dateStampFormat;
}
};

protected static final Log log = LogFactory.getLog(AWS4Signer.class);


Expand Down Expand Up @@ -233,17 +251,11 @@ protected HeaderSigningResult computeSignature(Request<?> request, Date date, St
}

protected String getDateTimeStamp(Date date) {
SimpleDateFormat dateTimeFormat;
dateTimeFormat = new SimpleDateFormat("yyyyMMdd'T'HHmmss'Z'");
dateTimeFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
return dateTimeFormat.format(date);
return dateTimeFormat.get().format(date);
}

protected String getDateStamp(Date date) {
SimpleDateFormat dateStampFormat;
dateStampFormat = new SimpleDateFormat("yyyyMMdd");
dateStampFormat.setTimeZone(new SimpleTimeZone(0, "UTC"));
return dateStampFormat.format(date);
return dateStampFormat.get().format(date);
}

protected Date getDateFromRequest(Request<?> request) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,84 +28,102 @@
* Credentials provider implementation that loads credentials from the Amazon
* EC2 Instance Metadata Service.
*/
public class InstanceProfileCredentialsProvider implements AWSCredentialsProvider {

protected AWSCredentials credentials;
protected Date credentialsExpiration;

public AWSCredentials getCredentials() {
if (needsToLoadCredentials()) loadCredentials();
if (expired()) {
throw new AmazonClientException("The credentials received from the Amazon EC2 metadata service have expired");
}

return credentials;
}

public void refresh() {
loadCredentials();
}

protected boolean needsToLoadCredentials() {
if (credentials == null) return true;

if (credentialsExpiration != null) {
int thresholdInMilliseconds = 1000 * 60 * 5;
boolean withinExpirationThreshold = credentialsExpiration.getTime() - System.currentTimeMillis() < thresholdInMilliseconds;
if (withinExpirationThreshold) return true;
}

return false;
}

private boolean expired() {
if (credentialsExpiration != null) {
if (credentialsExpiration.getTime() < System.currentTimeMillis()) {
return true;
}
}

return false;
}

private synchronized void loadCredentials() {
try {
String credentialsResponse = new EC2MetadataClient().getDefaultCredentials();
JSONObject jsonObject = new JSONObject(credentialsResponse);

if (jsonObject.has("Token")) {
credentials = new BasicSessionCredentials(
jsonObject.getString("AccessKeyId"),
jsonObject.getString("SecretAccessKey"),
jsonObject.getString("Token"));
} else {
credentials = new BasicAWSCredentials(
jsonObject.getString("AccessKeyId"),
jsonObject.getString("SecretAccessKey"));
}

if (jsonObject.has("Expiration")) {
/*
* TODO: The expiration string comes in a different format than
* what we deal with in other parts of the SDK, so we have
* to convert it to the ISO8601 syntax we expect.
*/
String expiration = jsonObject.getString("Expiration");
expiration = expiration.replaceAll("\\+0000$", "Z");

credentialsExpiration = new DateUtils().parseIso8601Date(expiration);
}
} catch (IOException e) {
throw new AmazonClientException("Unable to load credentials from Amazon EC2 metadata service", e);
} catch (JSONException e) {
throw new AmazonClientException("Unable to parse credentials from Amazon EC2 metadata service", e);
} catch (ParseException e) {
throw new AmazonClientException("Unable to parse credentials expiration date from Amazon EC2 metadata service", e);
}
}

@Override
public String toString() {
return getClass().getSimpleName();
}
public class InstanceProfileCredentialsProvider implements
AWSCredentialsProvider {

protected volatile AWSCredentials credentials;
protected volatile Date credentialsExpiration;

public AWSCredentials getCredentials() {
if (needsToLoadCredentials())
loadCredentials();
if (expired()) {
throw new AmazonClientException(
"The credentials received from the Amazon EC2 metadata service have expired");
}

return credentials;
}

public void refresh() {
credentials = null;
}

protected boolean needsToLoadCredentials() {
if (credentials == null)
return true;

if (credentialsExpiration != null) {
int thresholdInMilliseconds = 1000 * 60 * 5;
boolean withinExpirationThreshold = credentialsExpiration.getTime()
- System.currentTimeMillis() < thresholdInMilliseconds;
if (withinExpirationThreshold)
return true;
}

return false;
}

private boolean expired() {
if (credentialsExpiration != null) {
if (credentialsExpiration.getTime() < System.currentTimeMillis()) {
return true;
}
}

return false;
}

private synchronized void loadCredentials() {

if (needsToLoadCredentials()) {
try {
String credentialsResponse = new EC2MetadataClient()
.getDefaultCredentials();
JSONObject jsonObject = new JSONObject(credentialsResponse);

if (jsonObject.has("Token")) {
credentials = new BasicSessionCredentials(
jsonObject.getString("AccessKeyId"),
jsonObject.getString("SecretAccessKey"),
jsonObject.getString("Token"));
} else {
credentials = new BasicAWSCredentials(
jsonObject.getString("AccessKeyId"),
jsonObject.getString("SecretAccessKey"));
}

if (jsonObject.has("Expiration")) {
/*
* TODO: The expiration string comes in a different format
* than what we deal with in other parts of the SDK, so we
* have to convert it to the ISO8601 syntax we expect.
*/
String expiration = jsonObject.getString("Expiration");
expiration = expiration.replaceAll("\\+0000$", "Z");

credentialsExpiration = new DateUtils()
.parseIso8601Date(expiration);
}
} catch (IOException e) {
throw new AmazonClientException(
"Unable to load credentials from Amazon EC2 metadata service",
e);
} catch (JSONException e) {
throw new AmazonClientException(
"Unable to parse credentials from Amazon EC2 metadata service",
e);
} catch (ParseException e) {
throw new AmazonClientException(
"Unable to parse credentials expiration date from Amazon EC2 metadata service",
e);
}
}

}

@Override
public String toString() {
return getClass().getSimpleName();
}
}
19 changes: 16 additions & 3 deletions src/main/java/com/amazonaws/internal/DynamoDBBackoffStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,22 @@
package com.amazonaws.internal;

public class DynamoDBBackoffStrategy extends CustomBackoffStrategy {
public int getBackoffPeriod(int retries) {
return (retries == 0) ? 0 : 50 * (int)Math.pow(2, retries - 1);
}
public int getBackoffPeriod(int retries) {

if (retries <= 0) {
return 0;
} else {

int delay = 50 * (int) Math.pow(2, retries - 1);

if (delay < 0) {
delay = Integer.MAX_VALUE;
}

return delay;
}

}

public static final CustomBackoffStrategy DEFAULT = new DynamoDBBackoffStrategy();
}
32 changes: 17 additions & 15 deletions src/main/java/com/amazonaws/regions/Regions.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,21 @@ private Regions(String name) {
public String getName() {
return name;
}

/**
* Retrieves a region by its name.
*
* @param regionName The name of the region. Ex.: eu-west-1
* @return The region.
*/
public static Regions fromName(String regionName) {
for (Regions region : Regions.values()) {
if (regionName.equals(region.getName())) {
return region;
}
}
throw new IllegalArgumentException("Unknown region name: " + regionName);
}

/**
* Returns a region enum corresponding to the given region name.
*
* @param regionName
* The name of the region. Ex.: eu-west-1
* @return Region enum representing the given region name.
*/
public static Regions fromName(String regionName) {
for (Regions region : Regions.values()) {
if (regionName.equals(region.getName())) {
return region;
}
}
throw new IllegalArgumentException("Cannot create enum from " + regionName + " value!");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public void setAttributeName(String attributeName) {
* Returns a reference to this object so that method calls can be chained together.
*
* @param attributeName The new value for the AttributeName property for this object.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public AccountAttribute withAttributeName(String attributeName) {
this.attributeName = attributeName;
Expand Down Expand Up @@ -90,6 +93,9 @@ public void setAttributeValues(java.util.Collection<AccountAttributeValue> attri
* Returns a reference to this object so that method calls can be chained together.
*
* @param attributeValues The new value for the AttributeValues property for this object.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public AccountAttribute withAttributeValues(AccountAttributeValue... attributeValues) {
if (getAttributeValues() == null) setAttributeValues(new java.util.ArrayList<AccountAttributeValue>(attributeValues.length));
Expand All @@ -105,6 +111,9 @@ public AccountAttribute withAttributeValues(AccountAttributeValue... attributeVa
* Returns a reference to this object so that method calls can be chained together.
*
* @param attributeValues The new value for the AttributeValues property for this object.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public AccountAttribute withAttributeValues(java.util.Collection<AccountAttributeValue> attributeValues) {
if (attributeValues == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ public void setAttributeValue(String attributeValue) {
* Returns a reference to this object so that method calls can be chained together.
*
* @param attributeValue The new value for the AttributeValue property for this object.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public AccountAttributeValue withAttributeValue(String attributeValue) {
this.attributeValue = attributeValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ public void setLicenseId(String licenseId) {
* Returns a reference to this object so that method calls can be chained together.
*
* @param licenseId Specifies the ID for the specific license to activate against.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public ActivateLicenseRequest withLicenseId(String licenseId) {
this.licenseId = licenseId;
Expand Down Expand Up @@ -116,6 +119,9 @@ public void setCapacity(Integer capacity) {
* Returns a reference to this object so that method calls can be chained together.
*
* @param capacity Specifies the additional number of licenses to activate.
*
* @return A reference to this updated object so that method calls can be chained
* together.
*/
public ActivateLicenseRequest withCapacity(Integer capacity) {
this.capacity = capacity;
Expand Down
Loading

0 comments on commit 2bec875

Please sign in to comment.