There is a simple class posted in Alan Williamson's blog for accessing
SimpleDB.
http://alan.blog-city.com/simpledb_sqs_java.htm

I would expect it to work out of the box.  I was able to use it in an
Android app.

Carmen

-- 
Carmen
http://www.twitter.com/CarmenDelessio
http://www.talkingandroid.com
http://www.facebook.com/BFFPhoto
http://www.twitter.com/DroidDrop

On Sat, Apr 10, 2010 at 4:03 PM, deuce4 <[email protected]> wrote:

> Ikai-
>
> Thank you for the great hint, it is good to know the right track.
>
> Still hoping for another hint.  I looked at the Python code (below),
> and would like to somehow port it to Java, but have no idea where to
> begin.
>
> Really, I only need to read the Simple DB data in my Google App Engine
> App.
>
> Conceptually, I just need a little help.  Would the following code be
> the way you would return simpleDB data in XML form (as the "message"
> below)--can you wrap all the query in the URL like this?
>
> Also, is this limited to 1 MB responses?  I am unclear on the Google
> Documentation--sometimes it refers to a 1MB response limit, and
> sometimes a 10MB response limit.
>
>
> URL url = new URL("https://sdb.amazonaws.com/
> ?Action=GetAttributes
> &AWSAccessKeyId=[valid access key id]
> &DomainName=MyDomain
> &ItemName=JumboFez
> &SignatureVersion=2
> &SignatureMethod=HmacSHA256
> &Timestamp=2010-01-25T15%3A03%3A07-07%3A00
> &Version=2009-04-15
> &Signature=[valid signature]");
>
>            HttpURLConnection connection = (HttpURLConnection)
> url.openConnection();
>            connection.setDoOutput(true);
>            connection.setRequestMethod("POST");
>
>            OutputStreamWriter writer = new
> OutputStreamWriter(connection.getOutputStream());
>            writer.write("message=" + message);
>            writer.close();
>
>            if (connection.getResponseCode() ==
> HttpURLConnection.HTTP_OK) {
>                // OK
>            } else {
>                // Server returned HTTP error code.
>            }
>
>
>
>
>
> PYTHON code below:
> import cgi
> import logging
>
> from google.appengine.api import users
> from google.appengine.ext import webapp
> from google.appengine.ext.webapp.util import run_wsgi_app
> from google.appengine.ext import db
> from google.appengine.api import datastore_types
> from google.appengine.api import memcache
> import os
> from google.appengine.ext.webapp import template
>
> class MainPage(webapp.RequestHandler):
>  def get(self):
>    items_query = Item.all().order('-date')
>    items = items_query.fetch(10)
>
>    template_values = {
>      'items': items,
>      }
>
>    path = os.path.join(os.path.dirname(__file__), 'index.html')
>    self.response.out.write(template.render(path, template_values))
>
> class Edit(webapp.RequestHandler):
>  def get(self):
>    key = str(self.request.get('key'))
>    item = db.get(key)
>
>    template_values = {
>      'item': item
>      }
>
>    path = os.path.join(os.path.dirname(__file__), 'edit.html')
>    self.response.out.write(template.render(path, template_values))
>
>
> class Put(webapp.RequestHandler):
>  def handle(self):
>    self.response.headers['Content-Type'] = 'text/plain'
>
>    ui = str(self.request.get('ui'))
>    key = str(self.request.get('key'))
>    content = self.request.get('content')
>
>    if not content or len(content) == 0:
>      if ui:
>        self.redirect('/')
>      else:
>        self.response.out.write(key)
>      return
>
>    item = Item()
>    try:
>      item = db.get(key)
>    except datastore_types.datastore_errors.BadKeyError:
>      logging.debug("Could not find key %s" % key)
>    item.content = self.request.get('content')
>    item.put()
>    key = str(item.key())
>    memcache.set(key, item)
>
>
>    if ui:
>      self.redirect('edit?key=%s' % key)
>    else:
>      self.response.out.write(key)
>
>  def get(self):
>    self.handle()
>  def post(self):
>    self.handle()
>
> class Get(webapp.RequestHandler):
>  def get(self):
>    self.response.headers['Content-Type'] = 'text/plain'
>
>    key = str(self.request.get('key'))
>    item = memcache.get(key)
>    if item is None:
>      try:
>        item = db.get(key)
>        memcache.set(key, item)
>      except:
>        logging.error("Could not find key %s" % key)
>    if item is not None:
>      self.response.out.write(item.content)
>    else:
>      self.response.out.write("")
>
>
> class Item(db.Expando):
>  content = db.StringProperty(multiline=True)
>  date = db.DateTimeProperty(auto_now_add=True)
>
> application = webapp.WSGIApplication(
>                                     [('/', MainPage),
>
> ('/edit', Edit),
>
> ('/get', Get),
>
> ('/put', Put)],
>                                     debug=True)
>
> def main():
>  run_wsgi_app(application)
>
> if __name__ == "__main__":
>  main()
> Hide details
> Change log
> r4 by talsalmona on Oct 18, 2008   Diff
> [No log message]
> Go to:
> Older revisions
>  r2 by talsalmona on Oct 18, 2008   Diff
> All revisions of this file
> File info
> Size: 2792 bytes, 107 lines
> View raw file
>
>
> On Apr 10, 8:06 am, "Ikai L (Google)" <[email protected]> wrote:
> > The reason this code isn't working is because it's build on top of Apache
> > Commons HttpClient. You'll need to use URL and URLConnection to make your
> > REST calls instead.
> >
> > This is definitely possible, as people have created a Python library for
> > doing this:
> >
> > http://code.google.com/p/appengine-simpledb/source/browse/#svn/trunk
> >
> > You're using Java. I haven't seen anything in my searches for examples
> > making SimpleDB calls in Java (probably because developers just use App
> > Engine's datastore for persistence). You'll likely have to roll your own
> > client against the REST spec:
> >
> > http://docs.amazonwebservices.com/AmazonSimpleDB/latest/DeveloperGuid...
> >
> >
> >
> >
> >
> > On Fri, Apr 9, 2010 at 2:41 PM, deuce4 <[email protected]> wrote:
> > > I tried with this
> > >        //below gives error: java.lang.NoClassDefFoundError: org/apache/
> > > commons/httpclient/HttpMethod
> >
> > > //        AmazonSimpleDB sdb = new AmazonSimpleDBClient(new
> > > PropertiesCredentials(
> > > //
> > > ClockServlet.class.getResourceAsStream("AwsCredentials.properties")));
> > > //
> > > //
> > > System.out.println("===========================================");
> > > //        System.out.println("Getting Started with Amazon SimpleDB");
> > > //
> > > System.out.println("===========================================\n");
> > > //
> > > //
> > > //            // Create a domain
> > > //            String myDomain = "MyStore";
> > > //            System.out.println("Creating domain called " + myDomain
> > > + ".\n");
> > > //            sdb.createDomain(new CreateDomainRequest(myDomain));
> > > //
> > > //            // List domains
> > > //            System.out.println("Listing all domains in your account:
> > > \n");
> > > //            for (String domainName :
> > > sdb.listDomains().getDomainNames()) {
> > > //                System.out.println("  " + domainName);
> > > //            }
> > > //            System.out.println();
> >
> > > I don't have the URL fetch code attempt anymore--mostly I have the
> > > fundamental question of how to create a custom connection object like
> > > the sdb above into a Google App Engine URL Fetch connection object.
> >
> > > I'm a novice with Google App Engine
> >
> > > Any specific help would be super appreciated in connecting a Amazon
> > > SImpleDB to a Java Servlet in Google App Engine.
> >
> > > thanks
> >
> > > On Apr 10, 7:10 am, deuce4 <[email protected]> wrote:
> > > > On Apr 9, 3:23 pm, deuce4 <[email protected]> wrote:
> >
> > > > > Is there any elegant way to access data stored in Amazon's Simple
> DB
> > > > > from a Google
> > >  application?
> >
> > > > > I tried using URLfetch, but failed.  Any ideas?
> >
> > > > I suppose I am new at this, and wasn't able to get the libraries
> > > > working.  Any chance of seeing an outline of the process from someone
> > > > who is knowledgable in accessing outside data?
> >
> > > --
> > > You received this message because you are subscribed to the Google
> Groups
> > > "Google App Engine" group.
> > > To post to this group, send email to [email protected]
> .
> > > To unsubscribe from this group, send email to
> > > [email protected]<google-appengine%[email protected]><google-appengine%2Bunsubscrib
> [email protected]>
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/google-appengine?hl=en.
> >
> > --
> > Ikai Lan
> > Developer Programs Engineer, Google App Enginehttp://
> googleappengine.blogspot.com|http://twitter.com/app_engine
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google App Engine" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<google-appengine%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/google-appengine?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to