Coldfusion on the Google App Engine with Open BlueDragon
ColdFusion, Web Development, BlueDragon, Internet, Google App EngineThe 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 here. NOTE 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.
BlueDragon 7 JX and Apache 2.2 on Ubuntu Feisty (7.04)
BlueDragonSo you want to install BlueDragon 7 (JX version) with Apache 2.2 on your Ubuntu Feisty machine?
Well, lucky for you it is SO EASY!
First- go download BlueDragon JX for linux
Once you have that, head over to Dave Shucks HowTo on installing Apache2.2 from source here. His write-up is for 6.06 (Dapper) but it still works great.
Ok so if you have come this far you know that "IT WORKS!" right?
That was the hard part, now all you need to do is locate the downloaded BlueDragon installation shell script. (Lets say it is in my /home/alynch/download directory) and run it.
Note: Be sure to run the shell script as root if you want it to correctly connect to your Apache webserver.
sudo /home/alynch/download/BlueDragon_Server_JX_70_339-Linux.sh
Not running the script as sudo won't throw any exceptions, but it will fail to make the necessary changes to your httpd.conf file.
Follow the prompts, choose your installation directory or accept the default. And thats it! As soon as the installer is finished, restart Apache and start serving .cfm's through port 80.
FOR MYSQL USERS:
You will need to download the connector from MySQL here
Extract the connector jar file from the downloaded archive. Change the jar file's name:
-from (something like) mysql-connector-java-5.0.4-bin.jar
-to mysql.jar
And move the mysql.jar to the lib directory of your BlueDragon installation directory. If you had already started BlueDragon, you will need to restart it once you have placed the mysql.jar file in the lib directory.
FYI The default BlueDragon admin location is http://localhost:8080/bluedragon/admin.cfm.
My VERY EARLY impression is that the installer was much nicer than the ColdFusion installer, with heavy points going to the easy of the Apache webserver configuration as compared to wsconfig for ColdFusion. Other than that it's really too early to report on much else.





Loading....