fixed date parser when there's a wrong date format specified

This commit is contained in:
Adrian Cole 2011-01-26 19:23:22 -08:00
parent a14cfac03c
commit 02fffda058
2 changed files with 16 additions and 18 deletions

View File

@ -22,7 +22,6 @@ package org.jclouds.blobstore.functions;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkNotNull;
import static com.google.common.base.Preconditions.checkState;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.blobstore.reference.BlobStoreConstants.PROPERTY_USER_METADATA_PREFIX;
import static org.jclouds.blobstore.util.BlobStoreUtils.getNameFor;
@ -53,17 +52,15 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpRespo
private final String metadataPrefix;
private final DateService dateParser;
private final Provider<MutableBlobMetadata> metadataFactory;
private final String apiVersion;
private String key;
@Inject
public ParseSystemAndUserMetadataFromHeaders(Provider<MutableBlobMetadata> metadataFactory, DateService dateParser,
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix, @Named(PROPERTY_API_VERSION) String apiVersion) {
@Named(PROPERTY_USER_METADATA_PREFIX) String metadataPrefix) {
this.metadataFactory = checkNotNull(metadataFactory, "metadataFactory");
this.dateParser = checkNotNull(dateParser, "dateParser");
this.metadataPrefix = checkNotNull(metadataPrefix, "metadataPrefix");
this.apiVersion = checkNotNull(metadataPrefix, "metadataPrefix");
}
public MutableBlobMetadata apply(HttpResponse from) {
@ -97,9 +94,10 @@ public class ParseSystemAndUserMetadataFromHeaders implements Function<HttpRespo
throw new HttpException(HttpHeaders.LAST_MODIFIED + " header not present in response: "
+ from.getStatusLine());
}
// Eucalyptus 1.6 returns iso8601 dates
if (apiVersion.indexOf("Walrus-1.6") != -1) {
metadata.setLastModified(dateParser.iso8601DateParse(lastModified.replace("+0000", "Z")));
// Walrus
if (lastModified.startsWith("20")) {
metadata.setLastModified(dateParser.iso8601DateParse(lastModified));
} else {
metadata.setLastModified(dateParser.rfc822DateParse(lastModified));
}

View File

@ -55,7 +55,7 @@ public class ParseSystemAndUserMetadataFromHeadersTest {
@BeforeTest
void setUp() {
parser = new ParseSystemAndUserMetadataFromHeaders(blobMetadataProvider, new SimpleDateFormatDateService(),
"prefix", "default");
"prefix");
parser.setName("key");
}
@ -82,8 +82,8 @@ public class ParseSystemAndUserMetadataFromHeadersTest {
HttpHeaders.LAST_MODIFIED, "Wed, 09 Sep 2009 19:50:23 GMT"));
MutableBlobMetadata metadata = blobMetadataProvider.get();
parser.parseLastModifiedOrThrowException(from, metadata);
assertEquals(metadata.getLastModified(),
new SimpleDateFormatDateService().rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
assertEquals(metadata.getLastModified(), new SimpleDateFormatDateService()
.rfc822DateParse("Wed, 09 Sep 2009 19:50:23 GMT"));
}
@Test(expectedExceptions = HttpException.class)