A Better way to serve files from the Google App Engine Virtual File System
Web Development, BlueDragon, Google App EngineThe other day I posted an example of how one might access images, for example, from your Google App's virtual file system. While it was sufficient, I wasn't really happy with how the URL's looked and how missing files were managed.
Right as I was writing this post to detail how I had rewritten the url to manage accessing VFS files, Vince posted this to the openBD mailing list...rendering my solution obsolete!
Quoted from the mailing list:
My apologies for taking so long to respond to this thread. In addition to Aaron's "getfile.cfm"--a very nice solution--GaeVFS contains a built-in servlet that allows you to do directory listings and serve files from configured directories. In order to use the GaeVfsServlet, add the following to your web.xml (this example serves files from the "/images" directory of your webapp):<servlet><servlet-name>gaevfs</servlet-name> <servlet-class>com.newatlanta.commons.vfs. provider.gae.GaeVfsServlet</ servlet-class> <init-param><param-name>dirListingAllowed</param-name> <param-value>true</param-value> </init-param><init-param><param-name>initDirs</param-name> <param-value></param-value></init-param></servlet><servlet-mapping><servlet-name>gaevfs</servlet-name> <url-pattern>/images/*</url-pattern> </servlet-mapping>You can then serve files by using normal IMG tags:<img src="/images/mypicture.jpg">You can serve files from as many directories as you'd like by adding multiple <servlet-mapping> elements and specifying the appropriate <url-pattern> elements. Also note the "dirListingAllowed" init parameter which enables/disable directory listings. Further details are available in the javadoc comments in the source code:
Url Rewriting on Google App Engine
Web Development, BlueDragon, Google App EngineLately I have been digging in to application development for the Google App Engine running Open BlueDragon. I encountered a need to rewrite and filter some URL's.
The software: UrlRewriteFilter (go get it here) I used the Beta 3.2 version.
The Installation: (borrowed in part from tuckey.org's instructions)
- Move the urlrewrite.xml to the /war/WEB-INF directory.
- Move the urlrewrite-3.2.0.jar to the /war/WEB-INF/lib directory.
- Add the following to your /war/WEB-INF/web.xml.
<filter>
<filter-name>UrlRewriteFilter</filter-name>
<filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>UrlRewriteFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- Add your own configuration to the /war/WEB-INF/urlrewrite.xml that was created.
- Re-deploy your Google App.
Examples:
<!--Redirect one url-->
<rule>
<from>/some/old/page.html</from>
<to type="redirect">/very/new/page.html</to>
</rule>
<!-- Redirect a directory -->
<rule>
<from>/some/olddir/(.*)</from>
<to type="redirect">/very/newdir/$1</to>
</rule>
<!-- Clean a url -->
<rule>
<from>/products/([0-9]+)</from>
<to>/products/index.jsp?product_id=$1</to>
</rule>
<!--
eg, /products/1234 will be passed on to /products/index.jsp?product_id=1234 without the user noticing.
-->
<!-- Browser detection -->
<rule>
<condition name="user-agent">Mozilla/[1-4]</condition>
<from>/some/page.html</from>
<to>/some/page-for-old-browsers.html</to>
</rule>Google App Engine's Virtual File System with OpenBD
ColdFusion, Internet, Web Development, BlueDragonWorking with the virutal file system on Google App Engine is fairly simple once you grasp the fact that all of your directories and files are really just BLOBs in the Google datastore. If you have worked with binary data from a database before, then this should be quite easy for you.
Interaction with the filesystem is easily done through openBD's implementation of the cfdirectory and cffile tags. You can CREATE and LIST directories from your VFS using the cfdirectory tag you know and love.
The "tricky" part comes when you find that none of the files you have uploaded are web accessible. In other words, you can upload to "/images" but you aren't going to be able to browse to "/images/mynewimage.jpg".
One solution would be to create a .cfm template to take a URL query string and serve up the requested file from the VFS.
For example: getfile.cfm?f=mynewimage.jpg
Which you could then use as the SRC in an IMG tag.
<img src="getfile.cfm?f=mynewimage.jpg" >
Where getfile.cfm might look like this:
<cffile action="readbinary" file="#ExpandPath('/images/' & url.f )#" variable="myFile">
<cfcontent type="#getMimeType(url.f)#" variable="#myFile#" reset="true" >
Note: I created this method called getMimeType() for an example site:
<cffunction name="getMimeType" > <cfargument name="fileName" /> <cfset var extension = ListLast(arguments.fileName,".") /> <cfswitch expression=".#extension#"> <cfcase value=".bmp"> <cfreturn "image/bmp"> </cfcase> <cfcase value=".css"> <cfreturn "text/css"> </cfcase> <cfcase value=".js"> <cfreturn "text/javascript"> </cfcase> <cfcase value=".jpg"> <cfreturn "image/jpeg"> </cfcase> <cfcase value=".jpeg"> <cfreturn "image/jpeg"> </cfcase> <cfcase value=".jpe"> <cfreturn "image/jpeg"> </cfcase> <cfcase value=".doc"> <cfreturn "application/msword"> </cfcase> <cfcase value=".docx"> <cfreturn "application/msword"> </cfcase> <cfcase value=".gif"> <cfreturn "image/gif"> </cfcase> <cfcase value=".gz"> <cfreturn "application/x-gzip"> </cfcase> <cfcase value=".htm"> <cfreturn "text/htm"> </cfcase> <cfcase value=".html"> <cfreturn "text/html"> </cfcase> <cfcase value=".ico"> <cfreturn "image/x-icon"> </cfcase> <cfcase value=".mov"> <cfreturn "video/quicktime"> </cfcase> <cfcase value=".mp3"> <cfreturn "audio/mpeg"> </cfcase> <cfcase value=".ppt"> <cfreturn "application/vnd.ms-powerpoint"> </cfcase> <cfcase value=".pps"> <cfreturn "application/vnd.ms-powerpoint"> </cfcase> <cfcase value=".tgz"> <cfreturn "application/x-compressed"> </cfcase> <cfcase value=".txt"> <cfreturn "text/plain"> </cfcase> <cfcase value=".wav"> <cfreturn "audio/x-wav"> </cfcase> <cfcase value=".wmv"> <cfreturn "video/x-ms-wmv"> </cfcase> <cfcase value=".xls"> <cfreturn "application/vnd.ms-excel"> </cfcase> <cfcase value=".xlsx"> <cfreturn "application/vnd.ms-excel"> </cfcase> <cfcase value=".zip"> <cfreturn "application/zip"> </cfcase> <cfcase value=".xml"> <cfreturn "application/xml"> </cfcase> <cfdefaultcase> <cfoutput>#extension#</cfoutput> FILE TYPE NOT SUPPORTED <cfabort> </cfdefaultcase> </cfswitch> </cffunction>
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....