Resources



Sample Code and Libraries

Java Library for Amazon SimpleDB

Click for a printer friendly version of this document Printer Friendly Save to del.icio.us
Average Review:

A Java library for Amazon SimpleDB.

Submitted By: Elena@AWS  
AWS Products Used: Amazon SimpleDB
Language(s): Java
License: Apache License 2.0

About this Library

  • Based on the 2009-04-15 API version.

What's New?

  • 2009-05-20:
    • Deprecate Query and QueryWithAttributes. Please migrate to Select API
  • 2009-03-31:
    • AsyncClient support
  • 2009-03-23:
    • Support for BatchPutAttributes
  • 2009-01-22:
    • Fix signature version 2 path encoding
  • 2009-01-05:
    • Url encoding fix (bug affected signature version 2 with values containing forward slash "/")
  • 2008-12-17:
    • Support for signature version 2, DomainMetadata and Select API, https endpoint
  • 2008-08-28:
    • Support for new API - QueryWithAttributes; Removed httpclient's "response body buffering" warning.
  • 2008-04-24:
    • Fixed signature-related issue that affected clients with non-UTF8 default JVM encoding
  • 2008-01-18:
    • Fixed UTF8 encoding; Fixed disabling error retries

Prerequisites

Reference Documentation

Package Content

Path Overview
lib Binary distribution of library
src Source distribution of library.
third-party Binary distribution of library dependencies.
build.xml Ant build file to build the library

Quick Start

Library comes with code samples for each available service API. To get started with the library, follow these steps:
  1. Extract the amazon-simpledb-2009-04-15-java-library.zip file into a working directory.
  2. Add all sources under "src" directory to your compilation path.
  3. Add all jars files under "third-party/*" directory to your classpath
  4. Edit desired sample. For example: CreateDomainSample.java


    • Set AWS Access Key ID and AWS Secret Access Key
    • String accessKeyId = "Your Access Key ID";
      String secretAccessKey = "Your Secret Access Key";
                      


    • Set request parameters. For example, find following pre-generated snippet:
    • CreateDomainRequest request = new CreateDomainRequest();
      // @TODO: set request parameters here
      // invokeCreateDomain(service, request);
                      


    • And uncomment third line and add domain name to request:
    • CreateDomainRequest request = new CreateDomainRequest();
      request.setDomainName("MyDomain");
      invokeCreateDomain(service, request);
                      

  5. Compile and run CreateDomain. You should see the output similar to the following:


  6.     CreateDomainResponse
            ResponseMetadata
                RequestId
                    95cdcb68-f46c-400b-8265-8c2de2a5c475
                

    Note, you may also see additional debugging output. To adjust level of debugging, modify log4j.properties available in the root of the source tree.

  7. Experiment with samples. When ready, add library binary distribution to your application classpath, and use it.

Making Requests to a Different Region

To make the service call to a different region, instantiate the client with the configuration object, and pass the region-specific endpoint. For example:

AmazonSimpleDB service = new AmazonSimpleDBClient
     (accessKeyId, secretAccessKey, 
      new AmazonSimpleDBConfig()
      .withServiceURL("https://sdb.eu-west-1.amazonaws.com"));

See the Amazon SimpleDB Developer Guide for a complete list of region endpoints.

Previous Version Download

Comments, Questions or Feedback

If you have any comments, questions or feedback on the library, please start the discussion here.


Related Documents
Type: Articles & Tutorials Introduction to AWS for Java Developers

Discussion

The 5 most recent discussion messages. View full discussion.

Seth Bourget
RealName(TM)
Posts: 5
Registered: 11/23/07
Java Library for Amazon SimpleDB
Posted: Dec 18, 2008 2:59 PM PST
 
  Click to reply to this thread Reply

under 'what's new' it claims that on 12-17-2008 support for signature version 2 was added but I just downloaded the code (12-18-2008) and there's no support for signature version 2 look at class: AmazonSimpleDBClient.java

    private String signParameters(Map<String, String> parameters, String key)
            throws  SignatureException {

        String signatureVersion = parameters.get("SignatureVersion");
        StringBuffer data = new StringBuffer();

        if ("0".equals(signatureVersion)) {
            data.append(parameters.get("Action")).append(parameters.get("Timestamp"));
        } else if ("1".equals(signatureVersion))  {
            Map<String, String> sorted =  new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER);
            parameters.remove("Signature");
            sorted.putAll(parameters);
            Iterator pairs = sorted.entrySet().iterator();
            while (pairs.hasNext()) {
                Map.Entry pair = (Map.Entry)pairs.next();
                data.append(pair.getKey());
                data.append(pair.getValue());
            }
        } else {
            throw new SignatureException("Invalid Signature Version specified");
        }
        return sign(data.toString(), key);
    }



Reviews
Create Review Write a Review

Nice, but difficult model to use, Jan 4, 2008 3:40 PM
Reviewer: J. Levine
This is a good library, but the way that it models the SimpleDB actions and implements them in Java leaves me confused -- so confused that while I did what I wanted to, I ended up giving up on the idea of using the library again. One example: there's an object (AmazonSimpleDBClient) that serves as the main client object, and it has the methods you'd expect, like createDomain. But rather than taking a String (the name of the domain you'd like to create), the createDomain method takes a weird CreateDomain object, an object that simply doesn't have to exist and semantically leaves me confused every time I need to create it. The same thing holds true for the deleteDomain method, which also takes a weird DeleteDomain object. (And the CreateDomain and DeleteDomain objects aren't related at all, through inheritance or common ancestry, which is further weirdness.) I ended up finding out that typica (http://code.google.com/p/typica/) has implemented code to handle SimpleDB, and it looks like it's a lot more straightforward to implement; I'll give that a try next.

Using mpck services, Mar 4, 2008 9:13 AM
Reviewer: vishprat24
I used mock service that simulates Amazon Simple DB responses without calling Amazon Simple DB service. and responses are loaded from local XML files available under com/amazonaws/sdb/mock folder. I followed the below steps: 1) Modified "CreateDomainSample.java" as mentioned in standard guide to use mock service. 2) Addedd domain name "Mystore" using method "withDomainName()" 3) Modified ListDomainsSample.java same as mentioned in step 1. 4) expected result as mentioned in standard guide:: "SimpleDB service returns the list of domain including the newly created domain(i.e. "Mystore")... but it loads the static content from local xml file. Is this work against Amazon Simple DB service only?

A bit verbose, but uses interfaces, Mar 5, 2008 12:14 PM
Reviewer: Kim Pepper
I found this a little bit verbose to use, lots of creating model objects which could have been hidden behind the api. The best feature is the fact the main entry point to the library is an interface, which means unit testing with jMock is very easy to do. Compare this against the tipica library, where you need to call static methods and is therefore impossible to mock out.

Updated distro?, Mar 5, 2008 2:25 PM
Reviewer: alipope
In the "What's new section" there is a mention to an update form 2008-01-18, but it looks like the download is pointing to the previous version. Has the download been updated? cheers, ./alex -- .w( the_mindstorm )p.

Nice try, but..., Apr 7, 2008 4:25 PM
Reviewer: William B. Pietri
I appreciate that Amazon took the time to provide a Java API client, but this one borders on unusable for my purposes. It is my strong suspicion that it was built entirely based on theory, rather than by building something useful and then extracting an API. Issues that occur to me off the bat: Objects that are clearly related don't have proper superclasses, requiring special-case code. That's especially problematic with the requests and responses, preventing general code for preprocessing, error handling, or logging. Construction of real-world interactions is painfully verbose. Core API objects have only setters where they clearly should have useful constructors. Some with real constructors could use convenience methods to increase readability. More generally, convenience methods seem to be lacking. It is great to see a mock implementation for testing, but again, it doesn't look like it was used for real-world tests, which would allow for varying success and failure responses.
Welcome, Guest Help
Login Login