Search in sources :

Example 1 with RoutingRuleCondition

use of com.amazonaws.services.s3.model.RoutingRuleCondition 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 2 with RoutingRuleCondition

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

the class BucketWebsiteIntegrationTest method testBucketWebsites.

/**
 * Tests that we can get, set, and delete a bucket's website configuration.
 */
@Test
public void testBucketWebsites() throws Exception {
    // create a test bucket
    s3.createBucket(bucketName);
    // get website bucketWebsiteConfiguration for new bucket
    BucketWebsiteConfiguration bucketWebsiteConfiguration = s3.getBucketWebsiteConfiguration(bucketName);
    System.out.println("bucketWebsiteConfiguration: " + bucketWebsiteConfiguration);
    // set website configuration
    bucketWebsiteConfiguration = new BucketWebsiteConfiguration(INDEX_DOCUMENT_SUFFIX, ERROR_DOCUMENT);
    List<RoutingRule> rules = new LinkedList<RoutingRule>();
    RoutingRule rule = new RoutingRule();
    rule.setCondition(new RoutingRuleCondition().withKeyPrefixEquals(PREFIX).withHttpErrorCodeReturnedEquals(ERROR_CODE));
    rule.setRedirect(new RedirectRule().withProtocol(PROTOCOL).withHostName(HOST_NAME).withHttpRedirectCode(REDIRECT_CODE).withReplaceKeyPrefixWith(NEW_PREFIX));
    rules.add(rule);
    rule = new RoutingRule();
    rule.setRedirect(new RedirectRule().withHostName(HOST_NAME));
    rules.add(rule);
    rule = new RoutingRule();
    rule.setCondition(new RoutingRuleCondition().withHttpErrorCodeReturnedEquals(ERROR_CODE));
    rule.setRedirect(new RedirectRule().withReplaceKeyWith(NEW_KEY));
    rules.add(rule);
    bucketWebsiteConfiguration.setRoutingRules(rules);
    s3.setBucketWebsiteConfiguration(bucketName, bucketWebsiteConfiguration);
    // get again
    bucketWebsiteConfiguration = s3.getBucketWebsiteConfiguration(bucketName);
    assertEquals(INDEX_DOCUMENT_SUFFIX, bucketWebsiteConfiguration.getIndexDocumentSuffix());
    assertEquals(ERROR_DOCUMENT, bucketWebsiteConfiguration.getErrorDocument());
    assertEquals(3, bucketWebsiteConfiguration.getRoutingRules().size());
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getCondition().getKeyPrefixEquals(), PREFIX);
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getCondition().getHttpErrorCodeReturnedEquals(), ERROR_CODE);
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getRedirect().getprotocol(), PROTOCOL);
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getRedirect().getHostName(), HOST_NAME);
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getRedirect().getHttpRedirectCode(), REDIRECT_CODE);
    assertEquals(bucketWebsiteConfiguration.getRoutingRules().get(0).getRedirect().getReplaceKeyPrefixWith(), NEW_PREFIX);
    assertNull(bucketWebsiteConfiguration.getRoutingRules().get(1).getCondition());
    assertEquals(HOST_NAME, bucketWebsiteConfiguration.getRoutingRules().get(1).getRedirect().getHostName());
    assertEquals("", bucketWebsiteConfiguration.getRoutingRules().get(2).getCondition().getKeyPrefixEquals());
    assertEquals(NEW_KEY, bucketWebsiteConfiguration.getRoutingRules().get(2).getRedirect().getReplaceKeyWith());
    // Test RedirectAllRequestsTo
    bucketWebsiteConfiguration = new BucketWebsiteConfiguration();
    bucketWebsiteConfiguration.setRedirectAllRequestsTo(new RedirectRule().withHostName(HOST_NAME).withProtocol(PROTOCOL));
    s3.setBucketWebsiteConfiguration(bucketName, bucketWebsiteConfiguration);
    bucketWebsiteConfiguration = s3.getBucketWebsiteConfiguration(bucketName);
    assertNotNull(bucketWebsiteConfiguration.getRedirectAllRequestsTo());
    assertEquals(HOST_NAME, bucketWebsiteConfiguration.getRedirectAllRequestsTo().getHostName());
    assertEquals(PROTOCOL, bucketWebsiteConfiguration.getRedirectAllRequestsTo().getprotocol());
    // delete
    s3.deleteBucketWebsiteConfiguration(bucketName);
    Thread.sleep(1000 * 60 * 1);
    // get again
    bucketWebsiteConfiguration = s3.getBucketWebsiteConfiguration(bucketName);
    assertNull(bucketWebsiteConfiguration);
}
Also used : RedirectRule(com.amazonaws.services.s3.model.RedirectRule) BucketWebsiteConfiguration(com.amazonaws.services.s3.model.BucketWebsiteConfiguration) RoutingRuleCondition(com.amazonaws.services.s3.model.RoutingRuleCondition) RoutingRule(com.amazonaws.services.s3.model.RoutingRule) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

RedirectRule (com.amazonaws.services.s3.model.RedirectRule)2 RoutingRuleCondition (com.amazonaws.services.s3.model.RoutingRuleCondition)2 BucketWebsiteConfiguration (com.amazonaws.services.s3.model.BucketWebsiteConfiguration)1 RoutingRule (com.amazonaws.services.s3.model.RoutingRule)1 LinkedList (java.util.LinkedList)1 Test (org.junit.Test)1