Coldfusion on the Google App Engine with Open BlueDragon

ColdFusion, Web Development, BlueDragon, Internet, Google App Engine

The future is now! 

A little melodramatic maybe, but this technology is exciting.  Free cfml app servers with clustering (including data and file storage). 

First, if you don't know what the Google App Engine is yet, go here first and do a little reading.  Once you have read enough of that to be sufficiently excited, we need to set up the development and deployment tools.  Paul Kukiel has put together a really nice demo on how to do this hereNOTE THERE IS ONE THING THAT IS INCORRECT IN THE VIDEO   Do not delete the "war" directory, merely paste the openbd war over the existing one.  This is important.

Next, reading and writing data with the Google datastore. 

Storing data in a scalable web application can be tricky. A user could be interacting with any of dozens of web servers at a given time, and the user's next request could go to a different web server than the one that handled the previous request. All web servers need to be interacting with data that is also spread out across dozens of machines, possibly in different locations around the world.
Thanks to Google App Engine, you don't have to worry about any of that. App Engine's infrastructure takes care of all of the distribution, replication and load balancing of data behind a simple API—and you get a powerful query engine and transactions as well.

Thanks to the fine people at Open BlueDragon, this task is made very very simple.  Every cfc in the openBD GAE inherits the following methods from component.cfc.  GoogleWrite(), GoogleRead(), and GoogleKey().

 

-- Example object Status.cfc:

<cfcomponent displayname="Status" output="false">

	<cfproperty name="Message" displayname="Message" type="string" />
	<cfproperty name="DateTimeCreated" displayname="DateTimeCreated" type="date" />

	<cffunction name="init" access="public" output="false" returntype="Status">
		<cfreturn this/>
	</cffunction>

	<cffunction name="getMessage" access="public" output="false" returntype="string">
		<cfreturn this.Message />
	</cffunction>

	<cffunction name="setMessage" access="public" output="false" returntype="void">
		<cfargument name="Message" type="string" required="true" />
		<cfset this.Message = arguments.Message />
		<cfreturn />
	</cffunction>

	<cffunction name="getDateTimeCreated" access="public" output="false" returntype="date">
		<cfreturn this.DateTimeCreated />
	</cffunction>

	<cffunction name="setDateTimeCreated" access="public" output="false" returntype="void">
		<cfargument name="DateTimeCreated" type="date" required="true" />
		<cfset this.DateTimeCreated = arguments.DateTimeCreated />
		<cfreturn />
	</cffunction>

	
</cfcomponent>

 

-- Writing data to the datastore:

<cfscript>
//saving a new Status to Google datastore
Status = createObject( "component", "model.Status" ).init();
Status.setMessage( "I love Google App Engine and OpenBD!" );
Status.setDateTimeCreated( Now() );

/*now all we do is call the googleWrite() method on our object, notice this returns the objects new google key*/
googleKey = Status.googleWrite();
</cfscript>

 

-- Querying the datastore:  for more on this visit the openBD wiki page on the datastore

<!---
notice dbtype="google" and the quasi-SQL 
--->
<cfquery dbtype="google" name="result">
Select from Status
</cfquery>

<!---
The result of this query, is an array of matching Status objects.  Not the usual query recordset.
--->

 

Securing your new web app with the UserServiceFactory (com.google.appengine.api.users.UserServiceFactory)

Once I figured this step out, it was almost embarassingly easy to secure a page, allowing access only to validated Google account holders.

<cfscript>
UserServiceFactory = CreateObject("java","com.google.appengine.api.users.UserServiceFactory");

User = UserServiceFactory.getUserService().getCurrentUser();

/*Here I am doing a test to see if there is a valid user object returned, aka "logged in".  At this time, I haven't found the ideal solution for this*/

isLoggedIn = false;

try{
   user.getEmail();
   isLoggedIn = true;
}
catch (any excpt){}

</cfscript>

<!---

building login/logut links

--->

<cfif NOT isLoggedIn>
YOU NEED TO <a href="<cfoutput>#UserServiceFactory.getUserService().createLoginURL(toString("http://#cgi.SERVER_NAME#"))#</cfoutput>">LOGIN</a>
<cfelse>
	<cfoutput>#request.user.getEmail()#</cfoutput>:  All your email are belong to us 
	<br />
	<a href="<cfoutput>#UserServiceFactory.getUserService().createLogoutURL(toString("http://#cgi.SERVER_NAME#"))#</cfoutput>">LOGOUT</a>
</cfif>

 

Time to build some real applications.  Early indications from some experimentation by Dave Shuck, are revealing that the Mach-ii MVC framework along with the Coldspring IOC framework are working on the Google App Engine.

Other features, new or otherwise:

 

There is just no reason that we as cfml developers shouldn't be churning out app after app on this platform. 

 
Nice post. Note that the cron implementation is a little different from python projects to java projects. It seems that on the free app-engine accounts google stop the application after a given time. I have been using the built in cron support to keep my demos "hot" for there fast for the next person.

http://code.google.com/appengine/docs/java/config/...
 
posted 112 days ago
Add Comment Reply to: this comment OR this thread
 
Vince Bonfanti said:
 
Hi Aaron,

"The future is now!" exactly captures my initial reaction to Google App Engine:

http://blog.newatlanta.com/index.cfm/2009/6/4/Goog...

Vince
 
posted 108 days ago
Add Comment Reply to: this comment OR this thread
 
 
Very exciting stuff isn't it. I am really astounded that there are people talking this down.
 
posted 108 days ago
Add Comment Reply to: this comment OR this thread
 

Search

Fuelly