Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Wednesday, August 4, 2010

Rapid cloud development using App Engine for the Cycle Hire Widget Android application

Update Oct 2010: It's been several months since we introduced you to Little Fluffy Toys and their exciting Google App Engine story. Since then, their app has continued getting rave reviews. We're happy to let you know that there is a great follow-up to this story from the Android and UI/UE/UX perspective, and you can find it here: http://blog.radioactiveyak.com/2010/10/android-app-surgery-cycle-hire-widget.html

This post is another entry in our ongoing series of guest posts contributed by App Engine developers. Today we partner with Little Fluffy Toys Ltd to tell the story of how they were able to learn App Engine (plus Python) and launched their service paired with their Android application in less than a week!

Introduction

Last week, Little Fluffy Toys Ltd (LFT) launched an Android app to help its users find bicycles and rental locations in London. While this story doesn't sound particularly phenomenal, how they accomplished this using Google App Engine (and Android) makes their application and its launch one of the most exciting success stories so far in 2010.

The development team at LFT were able to quickly come up-to-speed on learning a new programming language and development environment in order to build and launch the App Engine backend service for their Android mobile app to the world in less than one week. The executive summary:

  • Attended 1-hour Thursday night presentation on Google App Engine (Jul 22)
  • Started to learn Python and App Engine on Saturday afternoon
  • Launched live service Wednesday, announcing their Android app with an App Engine backend (Jul 28)

Before we get to the good stuff, a brief backgrounder on the project which spawned the application: metropolitan bicycle-sharing systems, specifically London's. Based on the success and popularity of the Paris Vélib' system, the Barclays Cycle Hire scheme originated mid-November back in 2008 from its mayor, a strong cycling proponent.

The system launched on July 30, 2010; however a month before the project reached its completion, a call for apps was given by the mayor seeking independent developers so that there would be a variety of mobile and web apps available by show time. Enter Little Fluffy Toys Ltd which ended up creating the Cycle Hire Widget app for Android. They needed a backend system to manage the data, found App Engine, and the rest was history. Shortly after going live with their app and the launch of London's bicycle rental system, I had a chance to discuss how their project came together with the help of App Engine.

NOTE: Cycle Hire Widget is only available in the Android Market if you are located within the UK. If you wish to view the application from outside the UK, please download and install it from within your Android browser via this link — bear in mind that the distances to your nearest rental/hire location will be ridiculous!

App Engine and LFT

As we mentioned above, the sole purpose of their App Engine app is to receive data from and provide data to the Android app running on users' mobile phones. The App Engine stored data is "global" for all mobile clients out there, and this includes names, locations, and dynamic specifics related to each bike station such as the data found in the app's screenshot below. Take note all the valuable data that is provided in real-time by App Engine:

If you're a bit familiar with App Engine, you would no doubt have heard about it as a platform for web applications, but this is a use case highlighting App Engine for a non web-based server-side application where no part of the app is user-facing save for what gets sent back to the mobile app. While this type of app doesn’t get much press, it’s more common than people think.

I met Kenton Price, the director and chief architect of Little Fluffy Toys Ltd, at a developer event recently, and he seemed to think that App Engine would be the right tool for the Cycle Hire Widget. It turned out to be true(!), and when I asked about LFT's needs and how they were met by App Engine after their successful product launch, here is what he had to say:

"As you know, we were massively against the clock with the launch of the cycle hire scheme, and we needed something we could get going with fast that would effortlessly scale to perhaps tens of thousands of mobile users. App Engine seemed the perfect choice from what we had read of it before the meeting, and after your presentation it was obviously the way to go. Your recommendation to use Python was scary given neither of us knew a thing about it, but then again we only knew Java from Android not from web development so we didn't have the domain knowledge of building Java web services. So we went with Python, and it worked out really well. I'm astounded how we actually delivered this product in a very short space of time when we both have full schedules working on projects for our clients and other demanding outside interests. Particularly satisfying was having a solution that was agile and flexible enough to enable us to display live cycle availability data within hours of it becoming unexpectedly available at the launch, so we were live in the field with real-time data that very same launch morning, a feature our competitors are still struggling to replicate."

Development experience

Reuben Harris, LFT's chief technical officer, is the lead App Engine developer for the Cycle Hire Widget. He had a great experience even though he was new to Python as well as App Engine. What excited him the most, and what was his development experience like? He tells his story here:

"The single coolest thing about this project is that it was possible to go from a state of knowing nothing whatsoever about App Engine or Python (other than the mile-high view) to having a working and useful application inside of eight hours. We're long-time geeks but we're not geniuses. For us to pick up a new language, a new SDK, a new environment, a new way of doing things, and produce anything of value at all in such a short time speaks volumes about the value, potential, and quality of App Engine and Python.

After installing the App Engine SDK, yes, the very first thing I did was your online tutorial. I did "Hello World" to find my feet then continued into webapp, since a clean URL handler with easy ways to get at HTTP variables seemed essential. Then I immediately jumped into learning about data storage. And wow, what an enlightenment that turned out to be! Goodbye SQL, don't think I'm going to miss ya.... :-)

Since the app's purpose is to manage just ~400 simple objects representing Cycle Hire Stations, each of which contains only Plain Old Data types — no object references or anything possibly messy — I felt I knew enough to implement it now, and so I dived in. And it was so easy! I started with a handler to rebuild the datastore from scratch. Then I wrote a "get" type of handler to retrieve information about groups of hire stations (returning the data in JSON). Finally I wrote an "update" handler so that updated information about cycle hire stations could be posted, and that was it. Job done.

One thing that initially confounded me was an HTTP 500 error caused by our "reset" handler exceeding the 30-second request limit. For a while I was ready to despair; HTTP 500s to anyone with much ASP experience usually means a hideous low-level bug somewhere! However, once we discovered the problem, this was easy to fix by splitting the work into multiple requests (/reset1, /reset2, etc.) It's an admin function that only we'd ever be using, so no harm done and no need to work out anything more clever.

I know we've barely scratched the surface of what can be done with App Engine. We've yet to use Memcache, background tasks, batched updates, or anything beyond simple cloud-based data storage. But that simple thing alone seemed then, and still seems, not far short of miraculous. To not have to worry about databases, servers, uptime, upgrades and above all scaling... to not have to think about any of that at all is such an immense freedom. I'm completely hooked on it and am unlikely to go back to my traditional server tools of MySQL and PHP.

To see Reuben's work in action, check out this video demonstrating how to use the Cycle Hire Widget app while roaming the streets of London seeking a bike to rent/hire or park:

Conclusion

Since the launch, the Cycle Hire Widget has gotten rave reviews from CNET, The Guardian, and The Londonist. It has even been featured by the Press Association of the UK and Ireland! One user commented on Android Market: "Can't really think of a way to make it better," a sentiment reflected in its very high feedback rating. It certainly does sound like quite a success. What does the future look like? I asked Kenton about how LFT came about as well as how they're looking to improve their succeeding offerings, and here's what he had to say:

"We formed Little Fluffy Toys Ltd as a vehicle for Android development where we do consultancy work as well as our own stuff like the Cycle Hire Widget and Social Wallpaper. Whilst all custom development enquiries are very welcome, we're also interested in hearing from people or organisations that would like us to customise Cycle Hire Widget for their particular domain, whether it's cycles with availability in another city, coffee shops with opening hours in a geographic region, or dieting group meetings at pertinent times nearby. You name it, there are a gazillion applications for it!"

Well here on the App Engine team, we're happy for Kenton and his team on being able to implement the server-side solution they needed in such a short period of time on App Engine, and better yet, to help out a worthy cause. Google itself is a socially responsible company that applauds efforts like Barclays Cycle Hire, so we're proud that technologies we provide such as Android and App Engine can be used to help make London and the Earth more sustainable!

Posted by Kenton Price & Reuben Harris, Little Fluffy Toys Ltd, and Wesley Chun, App Engine team

Wednesday, June 30, 2010

PayPal introduces PayPal X Platform Toolkit for Google App Engine


Hello App Engine Developers!
My name is Praveen Alavilli (@ppalavilli) and I work as a developer evangelist for PayPal's X Platform at PayPal.com. I want to take the opportunity to introduce you to our new open source toolkit for Google App Engine that provides an easy way to integrate your Java apps running on App Engine with the new PayPal's Adaptive Payments API. Currently this is a Java toolkit explicitly for App Engine Java, but a Python version will be coming out soon.

Background
The Adaptive Payments API provides a set of core services offered by the PayPal X Open Global Payments Platform to enable developers to embed payments into their applications, services, and platforms. The Adaptive Payments APIs offer several new payments functionality like Split Payments and Preapprovals, that enable developers to implement a variety of monetization models - freemium, subscriptions, pay-per-use, value-added-services, micro-transactions, e-commerce, etc. in their applications built and running on the App Engine. Whether you are building an application for Businesses to process back-end disbursements or payouts to affiliates, or building a social or gaming app for Facebook / Twitter / Open Social, or building a Desktop gadget for premium content, or building a Geolocation app that only helps users find places and people around where they are but even help in transacting them, or building a Web2.0 AJAX app that mashes up content and services, or several more use cases enabled by App Engine, now you can use the PayPal X toolkit to enable payments in them as it fits the needs.

Using the toolkit
Getting started with App Engine toolkit is easy. You can either checkout the source code from svn and import it into your Eclipse project or simply download the prebuilt jar file and include it in your application's class path (/WEB-INF/lib). Similar to other APIs that you might have used, you would need PayPal API Credentials to authenticate your API requests. With the toolkit you simply create an "APICredential" object from one of your application initialization methods (in most cases from your Servlet init() method) and load the API Credentials that you have obtained from the PayPal Sandbox. (Please refer to PayPal's Sandbox guide for more detailed information on how to obtain them).
// Obtain the credentials from your configs 
credentialObj = new APICredential();
credentialObj.setAPIUsername(getServletConfig()
    .getInitParameter("PPAPIUsername"));
credentialObj.setAPIPassword(getServletConfig()
    .getInitParameter("PPAPIPassword"));
credentialObj.setSignature(getServletConfig()
    .getInitParameter("PPAPISignature"));

// setup your AppID from X.com
credentialObj.setAppId(getServletConfig()
    .getInitParameter("PPAppID"));

// setup your Test Business account email 
// in most cases this would be associated with API Credentials
credentialObj.setAccountEmail(getServletConfig()
    .getInitParameter("PPAccountEmail"));

// add required error condition checks
//....

Once the APICredentialObj is initialized successfully, save it in the application's local context so you do not need to reinitialize it on every request.
At its core, the Adaptive Payments API provides 5 generic API methods: Pay, Pay Details, Preapproval, Preapproval Details, Cancel Preapproval, Refunds, and Convert Currency. The toolkit provides the base API Request classes required to make those API calls. To make it even simpler, the toolkit also provides a few functional API wrapper classes that not only abstracts the APIs in terms of the functionality exposed (SimplePay, ChainedPay, ParallelPay, CreateSimplePreapproval, CreatePreapprovalForPeriodicPayments, PreapprovedChainedPay, etc.) but also provides a few exceptions that helps in handling errors more easily than the generic API Responses.

A Simple example
To give you an example, let's say you are building a SaaS model application on App Engine that you charge your customers based on their usage. While on-boarding customers to use your app, you can use the Preapproval API to obtain authorization from your customers to charge them for the app/service based on their usage in the future. In this case you can simply use the 'CreateSimplePreapproval' to create and send a request as below:
try {

  // CreateSimplePreapproval request to setup a simple 
  // preapproval with no Payment Period Set
  CreateSimplePreapproval simplePreapproval = 
      new CreateSimplePreapproval();

  // set the API Credentials object (as given in the code above)
  simplePreapproval.setCredentialObj(credentialObj);

  // starting date in yyyy-MM-dd format
  simplePreapproval.setStartingDate("2010-06-25");

  // ending date in yyyy-MM-dd format 
  // in this case it's for an year from the starting date
  simplePreapproval.setEndingDate("2011-06-25");

  // set max total amount of all Payments
  simplePreapproval.setMaxTotalAmountOfAllPayments(52.00);

  // set max amount for each payment - let's say $1
  simplePreapproval.setMaxAmountPerPayment(1.00);

  // set max number of payments allowed - (52 weeks)
  simplePreapproval.setMaxNumberOfPayments(52);

  // set where to send the user in case of a cancellation
  simplePreapproval.setCancelUrl(req.getRequestURL() +
      "?action=preapproval&cancel=1");

  // set where to return the user after successful approval
  simplePreapproval.setReturnUrl(req.getRequestURL() + "?
    return=1&action=preapproval&preapprovalKey=${preapprovalKey}");

  /* Set other required fields */
  // ... //

  // set memo for user's transaction history
  simplePreapproval.setMemo("Preapproval for GAE Sample");

  // send the request
  PreapprovalResponse preapprovalResponse = 
      simplePreapproval.makeRequest();

  } catch (//...exceptions go here...//) {
  // handle exceptions as necessary

}

In this case, when the 'AuthorizationRequiredException' is thrown, your application would need to redirect the user to PayPal for authorizing the preapproval. The 'getAuthorizationUrl' method takes care of building the PayPal authorization url along with the Preapproval Key returned by the Preapproval API. Once the user authenticates and authorizes the preapproval request on PayPal.com, the user will be redirected back to your 'returnUrl' along with the preapprovalKey, which your application can verify by using the 'PreapprovalDetailsRequest' and store it in it's own app engine data store securely. From that point onwards, whenever the user needs to be charged for their usage of the application, the application can use one of the 'PreapprovedSimplePay' or 'PreapprovedParallelPay' or 'PreapprovedChainedPay' classes to make a payment on behalf of the user. Please refer to the sample apps to understand how to use the other classes provided by the toolkit to make Parallel,Chained or Simple Payments. For eg. the PicMartServlet.java in the PicMart sample app shows how you can make a parallel payment to two receivers at the same time.

Further examples
As mentioned earlier, if you are building a social game where users can buy digital goods (eg. micro-payments) and virtual currencies while playing a game, you can use the same Preapproval API to obtain authorization from them so you could charge their PayPal accounts as and when needed, without requiring them to re-enter their payment information or redirect to PayPal for authorizing the payments.
Other examples of using the toolkit can include:
  • An application that lets merchants or enterprises pay their suppliers, or manage affiliate networks
  • Applications to enable property owners to collect rental payments from tenants
  • With a mult-merchant marketplace, a simple payroll app enables employee salary payments in multiple countries
  • ...

As you can see, the toolkit's support of the Adaptive Payments APIs can easily enable all of these usecases.

Where to find more info
Please look at the sample code provided in the samples directory. The AdaptiveRequests.java class in AdaptiveSample and AdaptiveSampleFnAPI shows how to use the helper classes to send and receive requests. The PicMart sample app provides a simple example of how the Parallel Payment can be used in a Photo Printing app that let's users to buy prints of the pictures from Picasa Album of the photographer. This sample app uses the Picasa APIs to fetch the album and picture information from Picasa.

To learn more about the PayPal X Toolkit for App Engine, please visit: http://code.google.com/p/paypalx-gae-toolkit/ and to learn more about Adaptive Payments, please visit: https://www.x.com/community/ppx/adaptive_payments. You can find a lot of resources for developers like documentation, technical spec, sample apps, code, sdks, technical forums, technical support, etc.. on PayPal X Developer Network web site (https://www.x.com).
Posted by Praveen Alavilli (@ppalavilli), PayPal X Developer Network.

Friday, January 15, 2010

App Engine at a Conference Near You this Winter!

Happy New Year Everyone!

We're excited to be kicking off a new year, and you can expect to find many new exciting features coming to App Engine in the coming months. In addition to Google I/O 2010 coming up in May -- more on this below -- members of the App Engine team may be visiting a conference near you this quarter. Here is the full list:

2010 Jan 24-30 - Snow Sprint 2010 - Bürserberg, Austria - Nick Johnson
2010 Jan 26-27 - Jfokus - Stockholm - Patrick Chanezon
2010 Jan 28 - PROSA - Copenhagen - Patrick Chanezon
2010 Feb 17-21 - PyCon 2010 - Atlanta - Guido van Rossum, Wesley Chun, Joe Gregorio, Brett Slatkin, Andy Smith
2010 Feb 27 - Dare 2B Digital - Los Altos Hills - Wesley Chun
2010 Mar 10-12 - ConFoo.ca 2010 - Montreal - Patrick Chanezon
2010 Mar 12-16 - SXSW Interactive - Austin - Patrick Chanezon, Brett Slatkin, Sean Lynch
2010 Mar 15-18 - Cloud Connect - Santa Clara - Chris Schalk, Wesley Chun, Ikai Lan
2010 Mar 17-19 - ServerSide Java Symposium - Las Vegas - Max Ross

Although not happening until next quarter, save a place in your calendar and book your travel for May 19-20 to San Francisco for Google I/O 2010. This year will be a blockbuster, featuring your favorite Google technologies and product announcements! There are at least 6 App Engine sessions planned. Register NOW!!

In addition to I/O, Google will be hosting a variety of DevFests in Asia late this winter. Keep an eye out for specific dates and locations on the Google Developer Events Calendar.

We would love to meet with App Engine developers at any of these events! Also be sure to follow @app_engine on Twitter for ongoing announcements as well as our Reddit tag for any relevant App Engine news.

Posted by Wesley Chun, App Engine team

Wednesday, January 6, 2010

Kaazing creates custom licensing solution using Google App Engine and Google Apps



Hello App Engine Developers!
My name is Peter Lubbers and I work for Kaazing, where we have developed an enterprise-ready WebSocket gateway, named — you guessed it — Kaazing WebSocket Gateway, which enables highly scalable, full-duplex real-time Web communication based on the new HTML5 Web Sockets standard. Using Kaazing's technology, you can seamlessly and reliably extend any TCP-based business messaging protocol to the Web with ultra high performance and minimal latency. The Kaazing WebSocket Gateway also provides emulation for browsers that do not support HTML5 Web Sockets, so you can start coding against the standard today.

We recently built an automated software license key generator using Google App Engine. This internal application proved to be very easy to build and we were able to deploy it within a day. We were extremely impressed with how simple it was to create a service that links our existing Google Apps accounts. Here's a bit of background on our solution and why we chose to implement it with App Engine.

The Problem
We recently needed to automatically create custom license key files for our customers. In order to scale up to our large customer base, we needed a simple internal solution that provided an automated way to quickly generate custom license key files on demand. The key to this hosted licensing system was that it had to tie into our existing Google Apps infrastructure. Fortunately, Google Apps integration (documented here) was very easy to achieve.

Why Google App Engine?
We chose App Engine because it allowed us to create a solution quickly. Since we are already a Google Apps shop, as well as a Java shop, we found the Google Apps integration provided by App Engine to be very helpful, and because App Engine provides an extremely easy development model — from design, to prototype, to a deployed implementation — we found that it exactly suited our needs.

How we built our implementation
Our implementation was extremely simple; we basically capitalized on App Engine's out-of-the-box integration with Google Apps so it was just a matter of writing an automatic license key generator and using App Engine's built-in e-mail service. This license key generator application was then made available as an application on our Google Apps instance.

The best part? From start to finish our license key generator application took no more than a day to prototype, test, and deploy.

Future Apps on App Engine
Overall we were extremely pleased with how easy it was to use App Engine to build a custom solution on top of our existing Google Apps framework. We also appreciate App Engine's support for Java, so we look forward to building other App Engine apps in the future.

To learn more about Kaazing software including their WebSocket Gateway, which includes a developer license (with a license key generated with the App Engine powered license key generator application) visit: http://www.kaazing.com/.