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");
}
}
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);
}
Aggregations