Skip to content

Commit

Permalink
'Version 1.5.8 of the AWS Java SDK'
Browse files Browse the repository at this point in the history
This release updates the Auto Scaling client with support for launching instances in Amazon Virtual Private Cloud (Amazon VPC) with a public IP address.
  • Loading branch information
hanshuo-aws committed Sep 20, 2013
1 parent 6d88d2e commit d26ff1f
Show file tree
Hide file tree
Showing 1,924 changed files with 7,684 additions and 2,414 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.7
Bundle-Version: 1.5.8
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
11 changes: 9 additions & 2 deletions 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.7</version>
<version>1.5.8</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 All @@ -23,7 +23,7 @@
</licenses>

<properties>
<jackson.version>2.1.2</jackson.version>
<jackson.version>2.1.1</jackson.version>
<spring.version>3.0.7.RELEASE</spring.version>
</properties>

Expand Down Expand Up @@ -57,6 +57,13 @@
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
<type>jar</type>
<scope>compile</scope>
</dependency>


<!-- JavaMail is only needed if you want to use the JavaMail provider
Expand Down
7 changes: 5 additions & 2 deletions src/main/java/com/amazonaws/DefaultRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,11 @@ public String toString() {
builder.append(getHttpMethod().toString() + " ");
builder.append(getEndpoint().toString() + " ");

builder.append("/"
+ (getResourcePath() != null ? getResourcePath() : "")
String resourcePath = getResourcePath();
if (resourcePath != null && !resourcePath.startsWith("/")) {
resourcePath = "/" + resourcePath;
}
builder.append((resourcePath != null ? resourcePath : "/")
+ " ");

if (!getParameters().isEmpty()) {
Expand Down
34 changes: 32 additions & 2 deletions src/main/java/com/amazonaws/auth/AWS4Signer.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,34 @@ public class AWS4Signer extends AbstractAWSSigner {

/** Date override for testing only */
protected Date overriddenDate;

/**
* Whether double url-encode the resource path when constructing the
* canonical request. By default, we enable double url-encoding.
*
* TODO: Different sigv4 services seem to be inconsistent on this. So for
* services that want to suppress this, they should use new AWS4Signer(false).
*/
protected boolean doubleUrlEncode;

/**
* Construct a new AWS4 signer instance.
* By default, enable double url-encoding.
*/
public AWS4Signer() {
this(true);
}

/**
* Construct a new AWS4 signer instance.
*
* @param doubleUrlEncoding
* Whether double url-encode the resource path when constructing
* the canonical request.
*/
public AWS4Signer(boolean doubleUrlEncoding) {
this.doubleUrlEncode = doubleUrlEncoding;
}

protected ThreadLocal<SimpleDateFormat> dateTimeFormat = new ThreadLocal<SimpleDateFormat>() {
@Override
Expand Down Expand Up @@ -205,11 +233,13 @@ protected String getSignedHeadersString(Request<?> request) {
}

protected String getCanonicalRequest(Request<?> request, String contentSha256) {
/* This would url-encode the resource path for the first time */
String path = HttpUtils.appendUri(request.getEndpoint().getPath(), request.getResourcePath());

String canonicalRequest =
request.getHttpMethod().toString() + "\n" +
getCanonicalizedResourcePath(path) + "\n" +
/* This would optionally double url-encode the resource path */
getCanonicalizedResourcePath(path, doubleUrlEncode) + "\n" +
getCanonicalizedQueryString(request) + "\n" +
getCanonicalizedHeaderString(request) + "\n" +
getSignedHeadersString(request) + "\n" +
Expand Down Expand Up @@ -316,7 +346,7 @@ protected void processRequestPayload(Request<?> request, HeaderSigningResult hea
return;
}

protected class HeaderSigningResult {
protected static class HeaderSigningResult {

private String dateTime;
private String scope;
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/amazonaws/auth/AbstractAWSSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,14 @@ protected InputStream getBinaryRequestPayloadStreamWithoutQueryParams(Request<?>
}

protected String getCanonicalizedResourcePath(String resourcePath) {
return getCanonicalizedResourcePath(resourcePath, true);
}

protected String getCanonicalizedResourcePath(String resourcePath, boolean urlEncode) {
if (resourcePath == null || resourcePath.length() == 0) {
return "/";
} else {
String value = HttpUtils.urlEncode(resourcePath, true);
String value = urlEncode ? HttpUtils.urlEncode(resourcePath, true) : resourcePath;
if (value.startsWith("/")) {
return value;
} else {
Expand Down
34 changes: 24 additions & 10 deletions src/main/java/com/amazonaws/auth/PropertiesCredentials.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,34 @@ public class PropertiesCredentials implements AWSCredentials {
*/
public PropertiesCredentials(File file) throws FileNotFoundException, IOException, IllegalArgumentException {
if (!file.exists()) {
throw new FileNotFoundException("File doesn't exist: " + file.getAbsolutePath());
throw new FileNotFoundException("File doesn't exist: "
+ file.getAbsolutePath());
}

Properties accountProperties = new Properties();
accountProperties.load(new FileInputStream(file));
FileInputStream stream = new FileInputStream(file);
try {

if (accountProperties.getProperty("accessKey") == null ||
accountProperties.getProperty("secretKey") == null) {
throw new IllegalArgumentException("The specified file (" + file.getAbsolutePath() + ") " +
"doesn't contain the expected properties 'accessKey' and 'secretKey'.");
}
Properties accountProperties = new Properties();
accountProperties.load(stream);

accessKey = accountProperties.getProperty("accessKey");
secretAccessKey = accountProperties.getProperty("secretKey");
if (accountProperties.getProperty("accessKey") == null ||
accountProperties.getProperty("secretKey") == null) {
throw new IllegalArgumentException(
"The specified file (" + file.getAbsolutePath()
+ ") doesn't contain the expected properties 'accessKey' "
+ "and 'secretKey'."
);
}

accessKey = accountProperties.getProperty("accessKey");
secretAccessKey = accountProperties.getProperty("secretKey");

} finally {
try {
stream.close();
} catch (IOException e) {
}
}
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/com/amazonaws/auth/QueryStringSigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ private String calculateStringToSignV1(Map<String, String> parameters) {
new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
sorted.putAll(parameters);

for (String key : sorted.keySet()) {
data.append(key);
data.append(sorted.get(key));
for (Map.Entry<String, String> entry : sorted.entrySet()) {
data.append(entry.getKey());
data.append(entry.getValue());
}

return data.toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,11 @@ private void convertResources(Statement statement, JSONObject jStatement) throws
/**
* An auxiliary class to help instantiate the action object.
*/
private class NamedAction implements Action {
private static class NamedAction implements Action {

private String actionName;
NamedAction(String actionName) {

public NamedAction(String actionName) {
this.actionName = actionName;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,30 +106,50 @@ private void writeConditions(Statement statement, JSONWriter generator)
* but use different condition keys. In JSON and XML, those conditions
* must be siblings, otherwise data can be lost when they get parsed.
*/
Map<String, List<Condition>> conditionsByType = sortConditionsByType(conditions);
Map<String, List<Condition>> conditionsByType =
sortConditionsByType(conditions);

generator.key("Condition").object();
for (String conditionType : conditionsByType.keySet()) {
for (Map.Entry<String, List<Condition>> entry
: conditionsByType.entrySet()) {

String conditionType = entry.getKey();
generator.key(conditionType).object();

/*
* We could also have multiple conditions that use the same type and
* same key, in which case, we need to push them together as one entry
* when we send the JSON representation.
*/
Map<String, List<String>> conditionValuesByKey = sortConditionsByKey(conditionsByType.get(conditionType));
for (String conditionKey : conditionValuesByKey.keySet()) {
generator.key(conditionKey).array();
for (String value : conditionValuesByKey.get(conditionKey)) {
generator.value(value);
}
generator.endArray();
}
writeConditions(entry.getValue(), generator);

generator.endObject();

}
generator.endObject();
}

private void writeConditions(final List<Condition> conditions,
final JSONWriter generator)
throws IOException, JSONException {

/*
* We could also have multiple conditions that use the same type and
* same key, in which case, we need to push them together as one entry
* when we send the JSON representation.
*/
Map<String, List<String>> conditionValuesByKey =
sortConditionsByKey(conditions);

for (Map.Entry<String, List<String>> entry
: conditionValuesByKey.entrySet()) {

String conditionKey = entry.getKey();
generator.key(conditionKey).array();

for (String value : entry.getValue()) {
generator.value(value);
}

generator.endArray();
}
}

private Map<String, List<String>> sortConditionsByKey(List<Condition> conditions) {
Map<String, List<String>> conditionValuesByConditionKey = new HashMap<String, List<String>>();

Expand Down Expand Up @@ -189,26 +209,40 @@ private void writeActions(Statement statement, JSONWriter generator)
*/
private void writePrincipals(Statement statement, JSONWriter generator)
throws IOException, JSONException {

List<Principal> principals = statement.getPrincipals();
if (principals == null || principals.isEmpty()) return;

generator.key("Principal").object();
Map<String, List<String>> principalContentsByScheme = new HashMap<String, List<String>>();
Map<String, List<String>> principalContentsByScheme =
new HashMap<String, List<String>>();

for (Principal p : principals) {
List<String> principalValues = principalContentsByScheme.get(p.getProvider());
List<String> principalValues =
principalContentsByScheme.get(p.getProvider());

if (principalValues == null) {
principalValues = new ArrayList<String>();
principalContentsByScheme.put(p.getProvider(), principalValues);
principalContentsByScheme.put(p.getProvider(),
principalValues);
}
principalValues.add(p.getId());

principalValues.add(p.getId());
}
for (String scheme : principalContentsByScheme.keySet()) {

for (Map.Entry<String, List<String>> entry
: principalContentsByScheme.entrySet()) {

String scheme = entry.getKey();
generator.key(scheme).array();
for (String principalId : principalContentsByScheme.get(scheme)) {

for (String principalId : entry.getValue()) {
generator.value(principalId);
}

generator.endArray();
}

generator.endObject();
}
}
26 changes: 21 additions & 5 deletions src/main/java/com/amazonaws/http/AmazonHttpClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.InputStream;
import java.net.URI;
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
Expand Down Expand Up @@ -187,7 +188,6 @@ public <T> T execute(Request<?> request,
HttpResponseHandler<AmazonWebServiceResponse<T>> responseHandler,
HttpResponseHandler<AmazonServiceException> errorResponseHandler,
ExecutionContext executionContext) throws AmazonClientException, AmazonServiceException {
long startTime = System.currentTimeMillis();

if (executionContext == null) throw new AmazonClientException("Internal SDK Error: No execution context parameter specified.");
List<RequestHandler> requestHandlers = executionContext.getRequestHandlers();
Expand Down Expand Up @@ -387,7 +387,14 @@ private <T extends Object> T executeHelper(Request<?> request,
* up resources.
*/
if (!leaveHttpConnectionOpen) {
try {response.getEntity().getContent().close();} catch (Throwable t) {}
try {
if (response != null && response.getEntity() != null
&& response.getEntity().getContent() != null) {
response.getEntity().getContent().close();
}
} catch (IOException e) {
log.warn("Cannot close the response content.", e);
}
}
}
} /* end while (true) */
Expand Down Expand Up @@ -829,6 +836,7 @@ private int parseClockSkewOffset(org.apache.http.HttpResponse response, AmazonSe
Header[] responseDateHeader = response.getHeaders("Date");

try {

if(responseDateHeader.length == 0) {
// SQS doesn't return Date header
serverDateStr = getServerDateFromException(exception.getMessage());
Expand All @@ -837,9 +845,17 @@ private int parseClockSkewOffset(org.apache.http.HttpResponse response, AmazonSe
serverDateStr = responseDateHeader[0].getValue();
serverDate = dateUtils.parseRfc822Date(serverDateStr);
}
}
catch(Exception e) {
log.warn("Unable to parse clock skew offset from response: " + serverDateStr, e);

} catch (ParseException e) {
log.warn("Unable to parse clock skew offset from response: "
+ serverDateStr,
e);
return 0;
} catch (RuntimeException e) {
log.warn("Unable to parse clock skew offset from response: "
+ serverDateStr,
e);
return 0;
}

long diff = deviceDate.getTime() - serverDate.getTime();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/amazonaws/http/HttpClientFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,9 @@ public HttpClient createHttpClient(ClientConfiguration config) {
* less strict about the Location header to account for S3 not sending the Location
* header with 301 responses.
*/
private final class LocationHeaderNotRequiredRedirectStrategy extends DefaultRedirectStrategy {
private static final class LocationHeaderNotRequiredRedirectStrategy
extends DefaultRedirectStrategy {

@Override
public boolean isRedirected(HttpRequest request,
HttpResponse response, HttpContext context) throws ProtocolException {
Expand Down
Loading

0 comments on commit d26ff1f

Please sign in to comment.