Building an Extension for Railo: Part 1

Posted by Mark Drew on code on July 2, 2010

Tagged under extensions,railo,getrailo

My role at Railo Technologies has so far been much more of a consultant so far. We consult and develop a number of projects on ACF and Railo and as I am a happy CFML user this has worked out great so far.

One of the things that I wanted to get much more into was the engine itself, and adding features to it. One feature that I am currently working on is creating a CouchDB Cache Extension.

Why CouchDB? Will firstly because it has a really simple API, secondly because you can make it replicate as needed and this makes for a great document based object store.

What I have been doing is:

Building an Extension

Building a development Extension Provider

Automating the updating of the Extension

Running Railo with a Java Debugger

Running tests on the extension

Building the Extension and a Development Extension Provider

Rather than going into all the backgound information about building your extension provider, there is a great tutorial over at the Railo Wiki, check that out before you go on, so that we are on the same page:

Building an Extension Provider Tutorial

Done? Good, now I can show you what I have been doing differently.

Each extension is a zip file with a config.xml that describes the steps involved in installing it to the Railo Administrator. But in my ExtensionProvider.cfc there is a method that gets information about the extension, and usually this is hard coded. I thought, why not include that in my extension? So I added an info node to the config.xml of the extension itself:

<config>
 <info>
 <id>10EEC23A-0779-4068-9507A9C5ED4A8646</id>
 <version>1.201007021028</version>
 <name>couch</name>
 <type>server</type>
 <label>CouchDB Cache</label>
 <description>CouchDB Cache extension</description>
 <created>2010-July-2 10:28</created> 
 <category>Core Extension</category> 
 </info>
 <step></step>
</config>

Now in my extension provider, I can just dynamically read this data to provide information to the Railo Administrator:

<cffunction name="populateCOM" access="private" returntype="void">
 <cfargument name="apps" type="query" required="yes">
 <cfset var exp="this extension is experimental and will no longer work with the final release of railo 3.1, it is not allowed to use this extension in a productve enviroment.">
 
 <cfset var rootURL=getInfo().url & "/extensions/">
 <cfset var zipFileLocation = 'ext/CouchDBCache.zip'>
 
 <cffile action="read" file="zip://#expandPath(zipFileLocation)#!/config.xml" variable="config">
 <cfset info = XMLParse(config)>

 <cfset QueryAddRow(apps)>
 <cfset QuerySetCell(apps,'download',rootURL & zipFileLocation)>
 <cfset QuerySetCell(apps,'id', info.config.info.id.XMLtext)>
 <cfset QuerySetCell(apps,'name',info.config.info.name.XMLtext)>
 <cfset QuerySetCell(apps,'type',info.config.info.type.XMLtext)>
 <cfset QuerySetCell(apps,'label',info.config.info.label.XMLtext)>
 <cfset QuerySetCell(apps,'description',info.config.info.description.XMLtext)>
 <cfset QuerySetCell(apps,'created',info.config.info.created.XMLtext)>
 <cfset QuerySetCell(apps,'version',info.config.info.version.XMLtext)>
 <cfset QuerySetCell(apps,'category',info.config.info.category.XMLtext)>
 </cffunction>

If all is good, you should now be able to add the extension provider to the Railo Server context.

 

And you should see your newly available extension in the Applications section of the Railo Server Administrator:

This means you can now install it!

In my next post I shall go into the other files that make up the extension and how you can automatically build it.

 




comments powered by Disqus