aws-sdk-java icon indicating copy to clipboard operation
aws-sdk-java copied to clipboard

NumberFormatException in AbstractS3ResponseHandler::populateObjectMetadata with GET Object request

Open cgrimm01 opened this issue 13 years ago • 3 comments

For AWS SDK for Java version 1.4.1:

In the documentation it shows that the response from the GET Object has a Expires response header of the form:

Expires: Thu, 01 Dec 1994 16:00:00 GMT

This matches what the HTTP RFC2616 specifies for this field.

However, in the routine AbstractS3ResponseHandler::populateObjectMetadata, it is expecting the Expires value to be an integer; thus throws a warning exception of NumberFormatException.

The following is the current code lines from that module:

       } else if (key.equals(Headers.EXPIRES)) {
            try {
                metadata.setExpirationTime(new Date(Long.parseLong(header.getValue())));
            } catch (NumberFormatException pe) {
                log.warn("Unable to parse expiration time: " + header.getValue(), pe);
            }

Based on the API documentation and the HTTP standard, the code should really be:

} else if (key.equals(Headers.EXPIRES)) {
      try {
    SimpleDateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss zzz");

    metadata.setExpirationTime(df.parse(header.getValue()));
} catch (ParseException pe) {
    log.warn("Unable to parse expiration time:" + header.getValue(), pe);
}

cgrimm01 avatar Mar 22 '13 18:03 cgrimm01

Some more data. If doing the following Java lines with the AWS SDK, it will reproduce the problem:

GetObjectRequest objectRequest = new GetObjectRequest(bucketName, key).withResponseHeaders(new ResponseHeaderOverrides().withExpires("Tue, 25 Mar 2013 15:04:07 GMT"));

S3Object object = s3Client.getObject(objectRequest);

Note that the following commented out line does not throw the exception, but according to the HTTP Standard, this is not valid value.

//            GetObjectRequest objectRequest = new GetObjectRequest(bucketName, key).withResponseHeaders(new ResponseHeaderOverrides().withExpires("0"));

cgrimm01 avatar Mar 26 '13 15:03 cgrimm01

Thank you very much for pointing this out!

I have noticed that issue, we resolve it in a slight different way, (we have the DateUtils class). It will be included in the next release.

thanks again for your effort!

yifeireplay avatar May 24 '13 18:05 yifeireplay

Hi, we have cleared up some of the confusion with the expires headers in the 1.4.5 release - http://aws.amazon.com/releasenotes/Java/1162337172145650

wmatveyenko avatar Aug 09 '13 16:08 wmatveyenko