Skip to content

Commit

Permalink
AWS SDK for Java 1.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AWS committed Jun 20, 2014
1 parent f9d6352 commit c7b4faa
Show file tree
Hide file tree
Showing 60 changed files with 3,081 additions and 1,222 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.7.13
Bundle-Version: 1.8.0
Bundle-Vendor: Amazon Technologies, Inc
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Require-Bundle: org.apache.commons.codec;bundle-version="1.3.0",
Expand Down
22 changes: 3 additions & 19 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.7.13</version>
<version>1.8.0</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 Expand Up @@ -119,22 +119,6 @@
<optional>true</optional>
</dependency>


<!-- JDK 1.6 and above include StAX support by default, so these two dependencies
are only needed for compiling/running against a 1.5 JVM. -->
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax</artifactId>
<version>1.2.0</version>
<optional>true</optional>
</dependency>

<!-- JUnit is needed to compile the support classes for the workflow service -->
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -162,8 +146,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
<source>1.6</source>
<target>1.6</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
Expand Down
51 changes: 36 additions & 15 deletions src/main/java/com/amazonaws/http/DefaultErrorResponseHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
*/
package com.amazonaws.http;

import java.io.IOException;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXParseException;

import com.amazonaws.AmazonClientException;
import com.amazonaws.AmazonServiceException;
import com.amazonaws.transform.Unmarshaller;
import com.amazonaws.util.IOUtils;
import com.amazonaws.util.XpathUtils;

/**
Expand All @@ -36,6 +39,7 @@
*/
public class DefaultErrorResponseHandler
implements HttpResponseHandler<AmazonServiceException> {
private static final Log log = LogFactory.getLog(DefaultErrorResponseHandler.class);

/**
* The list of error response unmarshallers to try to apply to error
Expand All @@ -58,22 +62,26 @@ public DefaultErrorResponseHandler(
this.unmarshallerList = unmarshallerList;
}

/* (non-Javadoc)
* @see com.amazonaws.http.HttpResponseHandler#handle(com.amazonaws.http.HttpResponse)
*/
public AmazonServiceException handle(HttpResponse errorResponse)
throws Exception {
@Override
public AmazonServiceException handle(HttpResponse errorResponse) throws Exception {
// Try to read the error response
String content = "";
try {
content = IOUtils.toString(errorResponse.getContent());
} catch(IOException ex) {
if (log.isDebugEnabled())
log.debug("Failed in reading the error response", ex);
return newAmazonServiceException(
"Unable to unmarshall error response", errorResponse, ex);
}
// Try to parse the error response as XML
Document document;
try {
document = XpathUtils.documentFrom(errorResponse.getContent());
} catch (SAXParseException e) {
AmazonServiceException exception =
new AmazonServiceException(String.format("Unable to unmarshall error response (%s)", e.getMessage()), e);
exception.setErrorCode(String.format("%s %s", errorResponse.getStatusCode(), errorResponse.getStatusText()));
exception.setErrorType(AmazonServiceException.ErrorType.Unknown);
exception.setStatusCode(errorResponse.getStatusCode());

return exception;
document = XpathUtils.documentFrom(content);
} catch (Exception e) {
return newAmazonServiceException(String.format(
"Unable to unmarshall error response (%s)", content),
errorResponse, e);
}

/*
Expand All @@ -94,6 +102,19 @@ public AmazonServiceException handle(HttpResponse errorResponse)
throw new AmazonClientException("Unable to unmarshall error response from service");
}

/**
* Used to create an {@link newAmazonServiceException} when we failed to
* read the error response or parsed the error response as XML.
*/
private AmazonServiceException newAmazonServiceException(String errmsg,
HttpResponse httpResponse, Exception readFailure) {
AmazonServiceException exception = new AmazonServiceException(errmsg, readFailure);
final int statusCode = httpResponse.getStatusCode();
exception.setErrorCode(statusCode + " " + httpResponse.getStatusText());
exception.setErrorType(AmazonServiceException.ErrorType.Unknown);
exception.setStatusCode(statusCode);
return exception;
}
/**
* Since this response handler completely consumes all the data from the
* underlying HTTP connection during the handle method, we don't need to
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/com/amazonaws/internal/SdkDigestInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package com.amazonaws.internal;

import java.io.IOException;
import java.io.InputStream;
import java.security.DigestInputStream;
import java.security.MessageDigest;
Expand All @@ -22,6 +23,8 @@
* Base class for AWS Java SDK specific {@link DigestInputStream}.
*/
public class SdkDigestInputStream extends DigestInputStream implements MetricAware {
private static final int SKIP_BUF_SIZE = 2*1024;

public SdkDigestInputStream(InputStream stream, MessageDigest digest) {
super(stream, digest);
}
Expand All @@ -34,4 +37,45 @@ public final boolean isMetricActivated() {
}
return false;
}

// https://github.com/aws/aws-sdk-java/issues/232
/**
* Skips over and discards <code>n</code> bytes of data from this input
* stream, while taking the skipped bytes into account for digest
* calculation. The <code>skip</code> method may, for a variety of reasons,
* end up skipping over some smaller number of bytes, possibly
* <code>0</code>. This may result from any of a number of conditions;
* reaching end of file before <code>n</code> bytes have been skipped is
* only one possibility. The actual number of bytes skipped is returned. If
* <code>n</code> is negative, no bytes are skipped.
*
* <p>
* The <code>skip</code> method of this class creates a byte array and then
* repeatedly reads into it until <code>n</code> bytes have been read or the
* end of the stream has been reached. Subclasses are encouraged to provide
* a more efficient implementation of this method. For instance, the
* implementation may depend on the ability to seek.
*
* @param n
* the number of bytes to be skipped.
* @return the actual number of bytes skipped.
* @exception IOException
* if the stream does not support seek, or if some other I/O
* error occurs.
*/
@Override
public final long skip(final long n) throws IOException {
if (n <= 0)
return n;
byte[] b = new byte[(int)Math.min(SKIP_BUF_SIZE, n)];
long m = n; // remaining number of bytes to read
while (m > 0) {
int len = read(b, 0, (int)Math.min(m, b.length));
if (len == -1)
return (m == n) ? -1 : (n - m);
m -= len;
}
assert (m == 0);
return n;
}
}
Loading

0 comments on commit c7b4faa

Please sign in to comment.