Search in sources :

Example 6 with AmazonSimpleDBClient

use of com.amazonaws.services.simpledb.AmazonSimpleDBClient in project wildfly-camel by wildfly-extras.

the class SDBIntegrationTest method putAndGetAttributes.

@Test
@SuppressWarnings("unchecked")
public void putAndGetAttributes() throws Exception {
    AmazonSimpleDBClient sdbClient = provider.getClient();
    Assume.assumeNotNull("AWS client not null", sdbClient);
    assertNoStaleDomain(sdbClient, "before");
    try {
        try {
            SDBUtils.createDomain(sdbClient, domainName);
            WildFlyCamelContext camelctx = new WildFlyCamelContext();
            camelctx.getNamingContext().bind("sdbClient", sdbClient);
            camelctx.addRoutes(new RouteBuilder() {

                public void configure() {
                    from("direct:start").to("aws-sdb://" + domainName + "?amazonSDBClient=#sdbClient");
                }
            });
            camelctx.start();
            try {
                ReplaceableAttribute attr = new ReplaceableAttribute("SomeName", "SomeValue", true);
                ProducerTemplate producer = camelctx.createProducerTemplate();
                Exchange exchange = producer.send("direct:start", new Processor() {

                    public void process(Exchange exchange) throws Exception {
                        exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.PutAttributes);
                        exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        exchange.getIn().setHeader(SdbConstants.REPLACEABLE_ATTRIBUTES, Collections.singletonList(attr));
                    }
                });
                Assert.assertNull(exchange.getException());
                int retries = 10;
                List<Attribute> result = Collections.emptyList();
                while (result.isEmpty() && 0 < retries--) {
                    exchange = producer.send("direct:start", new Processor() {

                        public void process(Exchange exchange) throws Exception {
                            exchange.getIn().setHeader(SdbConstants.OPERATION, SdbOperations.GetAttributes);
                            exchange.getIn().setHeader(SdbConstants.ITEM_NAME, itemName);
                        }
                    });
                    Assert.assertNull(exchange.getException());
                    result = exchange.getIn().getHeader(SdbConstants.ATTRIBUTES, List.class);
                    System.out.println(retries + ": " + result);
                    Thread.sleep(500);
                }
                Assert.assertEquals(1, result.size());
                Assert.assertEquals(attr.getName(), result.get(0).getName());
                Assert.assertEquals(attr.getValue(), result.get(0).getValue());
            } finally {
                camelctx.stop();
            }
        } finally {
            sdbClient.deleteDomain(new DeleteDomainRequest(domainName));
        }
    } finally {
        assertNoStaleDomain(sdbClient, "after");
    }
}
Also used : ProducerTemplate(org.apache.camel.ProducerTemplate) Processor(org.apache.camel.Processor) RouteBuilder(org.apache.camel.builder.RouteBuilder) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) Attribute(com.amazonaws.services.simpledb.model.Attribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) ReplaceableAttribute(com.amazonaws.services.simpledb.model.ReplaceableAttribute) Exchange(org.apache.camel.Exchange) DeleteDomainRequest(com.amazonaws.services.simpledb.model.DeleteDomainRequest) List(java.util.List) WildFlyCamelContext(org.wildfly.extension.camel.WildFlyCamelContext) Test(org.junit.Test)

Example 7 with AmazonSimpleDBClient

use of com.amazonaws.services.simpledb.AmazonSimpleDBClient in project simplejpa by appoxy.

the class EntityManagerFactoryImpl method createClients.

private void createClients() {
    AWSCredentials awsCredentials = null;
    InputStream credentialsFile = getClass().getClassLoader().getResourceAsStream("AwsCredentials.properties");
    if (credentialsFile != null) {
        logger.info("Loading credentials from AwsCredentials.properties");
        try {
            awsCredentials = new PropertiesCredentials(credentialsFile);
        } catch (IOException e) {
            throw new PersistenceException("Failed loading credentials from AwsCredentials.properties.", e);
        }
    } else {
        logger.info("Loading credentials from simplejpa.properties");
        String awsAccessKey = (String) this.props.get(AWSACCESS_KEY_PROP_NAME);
        String awsSecretKey = (String) this.props.get(AWSSECRET_KEY_PROP_NAME);
        if (awsAccessKey == null || awsAccessKey.length() == 0) {
            throw new PersistenceException("AWS Access Key not found. It is a required property.");
        }
        if (awsSecretKey == null || awsSecretKey.length() == 0) {
            throw new PersistenceException("AWS Secret Key not found. It is a required property.");
        }
        awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
    }
    this.simpleDbClient = new AmazonSimpleDBClient(awsCredentials, createConfiguration(sdbSecure));
    this.simpleDbClient.setEndpoint(sdbEndpoint);
    this.s3Client = new AmazonS3Client(awsCredentials, createConfiguration(s3Secure));
    this.s3Client.setEndpoint(s3Endpoint);
}
Also used : AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) AmazonSimpleDBClient(com.amazonaws.services.simpledb.AmazonSimpleDBClient) InputStream(java.io.InputStream) PersistenceException(javax.persistence.PersistenceException) PropertiesCredentials(com.amazonaws.auth.PropertiesCredentials) IOException(java.io.IOException) AWSCredentials(com.amazonaws.auth.AWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials) BasicAWSCredentials(com.amazonaws.auth.BasicAWSCredentials)

Aggregations

AmazonSimpleDBClient (com.amazonaws.services.simpledb.AmazonSimpleDBClient)7 AWSCredentials (com.amazonaws.auth.AWSCredentials)3 BasicAWSCredentials (com.amazonaws.auth.BasicAWSCredentials)3 ClientConfiguration (com.amazonaws.ClientConfiguration)2 PropertiesCredentials (com.amazonaws.auth.PropertiesCredentials)2 AmazonS3Client (com.amazonaws.services.s3.AmazonS3Client)2 AmazonSimpleDB (com.amazonaws.services.simpledb.AmazonSimpleDB)2 AmazonEC2Client (com.amazonaws.services.ec2.AmazonEC2Client)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 DeleteDomainRequest (com.amazonaws.services.simpledb.model.DeleteDomainRequest)1 ReplaceableAttribute (com.amazonaws.services.simpledb.model.ReplaceableAttribute)1 File (java.io.File)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 List (java.util.List)1 PersistenceException (javax.persistence.PersistenceException)1 Exchange (org.apache.camel.Exchange)1 Processor (org.apache.camel.Processor)1 ProducerTemplate (org.apache.camel.ProducerTemplate)1 RouteBuilder (org.apache.camel.builder.RouteBuilder)1