|
Project Information
Featured
Downloads
Links
|
Another Amazon AWS SimpleDB wrapper?Yes, this is yet another wrapper for Amazon SimpleDB. First of all, despite the REST hype, I still see SOAP + WS standards as a much more mature platform for enterprise development. Second, there needs to be an authority that keeps APIs in synch with latest Amazon AWS WSDLs. I would like to utilize my development team to help become such an authority, hopefully with your help. And by help I mean user community. Please use this API if you like it or not ;) Since all the projects we are involved in make use of Spring framework, we decided to make heavy use of it here as well. We are actively using Apache ServiceMix and Progress Fuse OSGi-containers, that is why the project is using Maven with PAX to create OSGi bundles. If you are not using OSGi, you can treat this library as a regular jar. We love Apache CXF (untill we ran into issues with EC2 WSDL and wsdl2java :)) and use it as to help out with SOAP stuff. UsageAt first, check out our unit tests to get the best idea about SimpleDB client. The API is very simple to use once you configure everything. // Get all domains.
SimpleDB simpledb = (SimpleDB) context.getBean("simpleDB");
Iterator<List<Domain>> domainsIterator;
try {
domainsIterator = simpledb.getDomains();
while (domainsIterator.hasNext()) {
List<Domain> domains = (List<Domain>) domainsIterator.next();
for (Domain domain : domains) {
System.out.println(domain.getName());
}
}
} catch (SimpleDBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
// Issue select.
Iterator<List<Item>> itemIterator;
try {
itemIterator = simpledb.select("select * from Domain where LN='Party' and city like 'Buck%'");
while (itemIterator.hasNext()) {
List<Item> items = (List<Item>) itemIterator.next();
for (Item item : items) {
System.out.print(item.getIdentifier());
List<ItemAttribute> attributes = item.getAttributes();
for (ItemAttribute attribute : attributes) {
System.out.print(attribute.getName() + "=" + attribute.getValue() + " , ");
System.out.println();
}
}
}
} catch (SimpleDBException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}Spring Context<!-- Expose properties. -->
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location" value="aws.properties"/>
</bean>
<!-- Client Keystore Callback. -->
<bean id="clientKeystorePasswordCallback" class="com.netflexitysolutions.amazonws.sdb.security.ClientKeystorePasswordCallback">
<constructor-arg value="classpath:clientKeystore.properties"/>
</bean>
<!--
This bean is an Out interceptor which will add a timestamp,
sign the timestamp and body.
-->
<bean id="TimestampSignEncrypt_Request" class="org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor">
<constructor-arg>
<map>
<entry key="action" value="Timestamp Signature"/>
<entry key="user" value="${keystore.alias}"/>
<entry key="signaturePropFile" value="${signaturePropFile}"/>
<entry key="encryptionPropFile" value="${encryptionPropFile}"/>
<entry key="encryptionUser" value="${keystore.alias}"/>
<entry key="signatureKeyIdentifier" value="DirectReference"/>
<entry key="passwordCallbackRef" value-ref="clientKeystorePasswordCallback"/>
<entry key="signatureParts" value="${signatureParts}"/>
</map>
</constructor-arg>
</bean>
<!-- JAX-WS Client for Amazon AWS SimpleDB web service. -->
<jaxws:client id="amazonSimpleDBService" serviceClass="com.amazonaws.sdb.doc._2009_04_15.AmazonSDBPortType" address="${amazonaws.simpledb.url}">
<jaxws:outInterceptors>
<ref bean="TimestampSignEncrypt_Request"/>
<bean class="org.apache.cxf.interceptor.LoggingOutInterceptor"/>
</jaxws:outInterceptors>
<jaxws:inInterceptors>
<bean class="org.apache.cxf.interceptor.LoggingInInterceptor"/>
</jaxws:inInterceptors>
</jaxws:client>
<!-- This is Netflexity SimpleDB client that you should use to call Amazon SimpleDB. -->
<bean id="simpleDB" class="com.netflexitysolutions.amazonws.sdb.SimpleDBClient">
<constructor-arg ref="amazonSimpleDBService"/>
</bean> aws.propertiesamazonaws.simpledb.url=https\://sdb.amazonaws.com
keystore.alias=REPLACEME
signaturePropFile=clientKeystore.properties
encryptionPropFile=clientKeystore.properties
signatureParts={Element}{http\://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd}Timestamp;{Element}{http\://schemas.xmlsoap.org/soap/envelope/}BodyclientKeystore.propertiesorg.apache.ws.security.crypto.provider=org.apache.ws.security.components.crypto.Merlin org.apache.ws.security.crypto.merlin.keystore.type=jks org.apache.ws.security.crypto.merlin.keystore.password=REPLACEME org.apache.ws.security.crypto.merlin.keystore.alias=REPLACEME org.apache.ws.security.crypto.merlin.file=awskeystore.jks awskeystore.jksThis is your java keystore file. Obviously, you can rename it, just make sure you update clientKeystore.properties accordingly. This is the most complex step of the entire setup. Unlike REST, SOAP needs a keystore file, composed of a pair: your Amazon x509 certificate (xxx.pem) and your Amazon private key. Unfortunatelly, java keygen utility cannot create a keystore using exising certificate + private key. To create, the keystore, please follow these instructions. In couple of days we will provide a utility that will simplify things. http://www.agentbob.info/agentbob/79-AB.html Contains Instructions http://www.slproweb.com/products/Win32OpenSSL.html Contains Windows OpenSSL install instructions. Here is what had to do:
|