Search in sources :

Example 11 with Rule

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method writeRule.

private void writeRule(XmlWriter xml, RoutingRule rule) {
    xml.start("RoutingRule");
    final RoutingRuleCondition condition = rule.getCondition();
    if (condition != null) {
        xml.start("Condition");
        xml.start("KeyPrefixEquals");
        if (condition.getKeyPrefixEquals() != null) {
            xml.value(condition.getKeyPrefixEquals());
        }
        // </KeyPrefixEquals">
        xml.end();
        if (condition.getHttpErrorCodeReturnedEquals() != null) {
            xml.start("HttpErrorCodeReturnedEquals ").value(condition.getHttpErrorCodeReturnedEquals()).end();
        }
        // </Condition>
        xml.end();
    }
    xml.start("Redirect");
    final RedirectRule redirect = rule.getRedirect();
    if (redirect != null) {
        if (redirect.getprotocol() != null) {
            xml.start("Protocol").value(redirect.getprotocol()).end();
        }
        if (redirect.getHostName() != null) {
            xml.start("HostName").value(redirect.getHostName()).end();
        }
        if (redirect.getReplaceKeyPrefixWith() != null) {
            xml.start("ReplaceKeyPrefixWith").value(redirect.getReplaceKeyPrefixWith()).end();
        }
        if (redirect.getReplaceKeyWith() != null) {
            xml.start("ReplaceKeyWith").value(redirect.getReplaceKeyWith()).end();
        }
        if (redirect.getHttpRedirectCode() != null) {
            xml.start("HttpRedirectCode").value(redirect.getHttpRedirectCode()).end();
        }
    }
    // </Redirect>
    xml.end();
    // </CORSRule>
    xml.end();
}
Also used : RedirectRule(com.amazonaws.services.s3.model.RedirectRule) RoutingRuleCondition(com.amazonaws.services.s3.model.RoutingRuleCondition)

Example 12 with Rule

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule in project aws-sdk-android by aws-amplify.

the class BucketConfigurationXmlFactory method convertToXmlByteArray.

public byte[] convertToXmlByteArray(BucketReplicationConfiguration replicationConfiguration) {
    final XmlWriter xml = new XmlWriter();
    xml.start("ReplicationConfiguration");
    final Map<String, ReplicationRule> rules = replicationConfiguration.getRules();
    final String role = replicationConfiguration.getRoleARN();
    xml.start("Role").value(role).end();
    for (final Map.Entry<String, ReplicationRule> entry : rules.entrySet()) {
        final String ruleId = entry.getKey();
        final ReplicationRule rule = entry.getValue();
        xml.start("Rule");
        xml.start("ID").value(ruleId).end();
        xml.start("Prefix").value(rule.getPrefix()).end();
        xml.start("Status").value(rule.getStatus()).end();
        final ReplicationDestinationConfig config = rule.getDestinationConfig();
        xml.start("Destination");
        xml.start("Bucket").value(config.getBucketARN()).end();
        if (config.getStorageClass() != null) {
            xml.start("StorageClass").value(config.getStorageClass()).end();
        }
        xml.end();
        xml.end();
    }
    xml.end();
    return xml.getBytes();
}
Also used : ReplicationDestinationConfig(com.amazonaws.services.s3.model.ReplicationDestinationConfig) ReplicationRule(com.amazonaws.services.s3.model.ReplicationRule) Map(java.util.Map) XmlWriter(com.amazonaws.services.s3.internal.XmlWriter)

Example 13 with Rule

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule in project aws-sdk-android by aws-amplify.

the class ExpirationHeaderParsingTest method testParseExpirationHeader1.

@Test
public void testParseExpirationHeader1() {
    MockObjectExpirationResult result = new MockObjectExpirationResult();
    ObjectExpirationHeaderHandler<MockObjectExpirationResult> handler = new ObjectExpirationHeaderHandler<MockObjectExpirationResult>();
    HttpResponse response = HttpResponse.builder().header("x-amz-expiration", "expiry-date=\"Tue, 01 Jan 2013 00:00:00 GMT\", rule-id=\"Test\"").build();
    handler.handle(result, response);
    Assert.assertEquals(1356998400000L, result.getExpirationTime().getTime());
    Assert.assertEquals("Test", result.getExpirationTimeRuleId());
}
Also used : ObjectExpirationHeaderHandler(com.amazonaws.services.s3.internal.ObjectExpirationHeaderHandler) HttpResponse(com.amazonaws.http.HttpResponse) Test(org.junit.Test)

Example 14 with Rule

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule in project aws-sdk-android by aws-amplify.

the class AbstractS3ResponseHandlerTest method testPopulateObjectMetadata.

@Test
public void testPopulateObjectMetadata() {
    HttpResponse response = new HttpResponse.Builder().header(Headers.REQUEST_ID, "testId").header(Headers.EXTENDED_REQUEST_ID, "extendedId").header(Headers.S3_USER_METADATA_PREFIX + "userKey", "userValue").header(Headers.LAST_MODIFIED, "Sun, 1 Jan 2006 12:00:00 GMT").header(Headers.CONTENT_LENGTH, "5").header(Headers.ETAG, "Etag").header(Headers.EXPIRES, "Sun, 1 Jan 2006 12:00:00 GMT").header(Headers.EXPIRATION, "expiry-date=\"Fri, 21 Dec 2012 00:00:00 GMT\", rule-id=\"Rule for testfile.txt\"").header(Headers.RESTORE, "ongoing-request=\"false\", expiry-date=\"Wed, 07 Nov 2012 00:00:00 GMT\"").header("UndefinedKey", "UndefinedValue").header(Headers.STORAGE_CLASS, "STANDARD_IA").build();
    ObjectMetadata om = new ObjectMetadata();
    TClass handler = new TClass();
    handler.populateObjectMetadata(response, om);
    assertNull(om.getRawMetadataValue(Headers.REQUEST_ID));
    assertNull(om.getRawMetadataValue(Headers.EXTENDED_REQUEST_ID));
    assertEquals(om.getUserMetaDataOf("userKey"), "userValue");
    assertEquals(1136116800000L, om.getLastModified().getTime());
    assertEquals(om.getContentLength(), 5);
    assertEquals(om.getETag(), "Etag");
    assertEquals(1356048000000L, om.getExpirationTime().getTime());
    assertEquals(1136116800000L, om.getHttpExpiresDate().getTime());
    assertEquals("Rule for testfile.txt", om.getExpirationTimeRuleId());
    assertEquals(1352246400000L, om.getRestoreExpirationTime().getTime());
    assertFalse(om.getOngoingRestore());
    assertEquals(om.getStorageClass(), StorageClass.StandardInfrequentAccess.toString());
}
Also used : HttpResponse(com.amazonaws.http.HttpResponse) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Test(org.junit.Test)

Example 15 with Rule

use of com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule in project aws-sdk-android by aws-amplify.

the class BucketLifecycleSaxUnmarshallerTest method unmarshalls_filter_with_emptyPrefix.

@Test
public void unmarshalls_filter_with_emptyPrefix() throws Exception {
    Rule rule = getRule(parseLifecycleConfiguration(UNKNOWN_STORAGE_CLASS_RESPONSE), 2);
    LifecyclePrefixPredicate predicate = (LifecyclePrefixPredicate) rule.getFilter().getPredicate();
    assertEquals("", predicate.getPrefix());
}
Also used : LifecyclePrefixPredicate(com.amazonaws.services.s3.model.lifecycle.LifecyclePrefixPredicate) Rule(com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)15 Rule (com.amazonaws.services.s3.model.BucketLifecycleConfiguration.Rule)13 CORSRule (com.amazonaws.services.s3.model.CORSRule)7 BucketLifecycleConfiguration (com.amazonaws.services.s3.model.BucketLifecycleConfiguration)6 LifecycleTagPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleTagPredicate)6 LifecycleAndOperator (com.amazonaws.services.s3.model.lifecycle.LifecycleAndOperator)5 HttpResponse (com.amazonaws.http.HttpResponse)4 AmazonS3 (com.amazonaws.services.s3.AmazonS3)4 XmlWriter (com.amazonaws.services.s3.internal.XmlWriter)4 RedirectRule (com.amazonaws.services.s3.model.RedirectRule)4 ReplicationRule (com.amazonaws.services.s3.model.ReplicationRule)4 LifecycleFilter (com.amazonaws.services.s3.model.lifecycle.LifecycleFilter)4 LifecycleFilterPredicate (com.amazonaws.services.s3.model.lifecycle.LifecycleFilterPredicate)4 LifecyclePrefixPredicate (com.amazonaws.services.s3.model.lifecycle.LifecyclePrefixPredicate)4 AmazonServiceException (com.amazonaws.AmazonServiceException)3 SdkClientException (com.amazonaws.SdkClientException)3 ProfileCredentialsProvider (com.amazonaws.auth.profile.ProfileCredentialsProvider)3 Regions (com.amazonaws.regions.Regions)3 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)3 ReplicationDestinationConfig (com.amazonaws.services.s3.model.ReplicationDestinationConfig)3