PDA

View Full Version : ExtDirectCF: A Managed ColdFusion Server-side stack with security



jimmifett
3 Jun 2009, 1:16 PM
This is a new, heavily modified fork of aconran (http://extjs.com/forum/member.php?u=802)'s DirectCFM (http://extjs.com/forum/showthread.php?t=67983) that I am calling ExtDirectCF.

Link to original details about this project and it's evolution:
http://extjs.com/forum/showthread.php?p=337767#post337767

Features:
Register exposed cfcs as in a stateful bean in application scope.
Fine grain which cfcs and methods to register.
Limit method registration to specific access scopes (remote, public, package, private).
Preserve ColdFusion Role based access enforcement.
Better error handling and reporting similar to java Exceptions.
Re-written in efficient cfscript.
Full scoping of access permission and variables.
Managment Console style application to manage registered cfcs.
Saving and loading of Registry.

To Come:
Finish mass recursive directory scan
Un-Registering individual methods from registered components via Management Console
bug fixes

v.09
* Added new Editable Paging Grid example (with Ext.ux.RowEditor) that drives
off a query object loaded into it's cfc's stateful bean in application scope.
Demonstrates a full CRUD api implentation. (thanks Ben Nadel for the info on
deleting rows from a query object)
* Added an index.cfm page in the ExtDirect directory with links to:
- ExtDirectCF Management Console
- the API.cfm page for debugging
- a link to force the framework to refresh
- a new readme file and release notes(taken from the forum)
- a link to the forum itself
- and a link to the above mentioned paging grid example.
* Added support for the Ext.Direct 1.0.1 spec.

v.08
* Fixed paths to extjs in console.cfm and example.cfm (you will still need to modify these for your own environment)
* Fixed dialogue size issue for add button in IE

v0.7
* Fixed nasty bug killing directFn. directFn now works. See example.cfm.

* Added ability to load and save the Registry to disk.

* Init() attempts to load Registry from disk. New arguments for Init() to specify path and file for saving Registry.

* Added onApplicationEnd() to application.cfc to ensure Registry is backed up to disk when application scope expires.

* ExtDirect.cfc Self Registers.

* Added support for 'Stateful Namespaces'. Example: You have a stateful cfc loaded into application or server scope. If you try to invoke it from previous versions, you'll have a new instance of that cfc. Now, you can tell it to use the existing stateful cfc instance. Components.Ext.ExtDirect has a 'Stateful Namespace' of 'application.ExtDirect'

* Some major internal registry structure changes.

* Added Management Console (console.cfm) for managing registered components. It does not yet have the ability to unregister individual methods, but it will register and unregister full components.

v0.6
* Moved the Component Registry into a private member to prevent abuse (accessible via getExtDirectRegistry()).

* Moved generateAPI() into the private scope and replaced with getAPIScript() in the public scope.

* The script API is now cached internally to the bean's private scope (accessed via getAPIScript()) and is updated whenever a component/method is added or removed. This eliminates json reserializing every time the api is loaded into a page, thus saving cpu cycles.

* Init() method now takes ns and desc as arguments to store internally and be used when generating the API script.

* Added unRegisterComponent() and unregisterMethod to remove entries from the registry. These will be useful for the Management Console.

* ExtDirect.cfc now registers itself upon initialization. This is to support the upcomming Management Console.

* Fixed bug for cffunctions that do not use the 'access' attribute (shame on you! you really should be using it!) and defaults to 'public' scope

* API.cfm changed to reflect new call to get API script

* Fixed bug in Example.cfm

* Expanded Example.cfm to better show off features and usage.

v0.5
* Initial Release

-Jim

p.s. If the zip file is giving anyone problems, let me know. Try to download with firefox or chrome. IE seems to corrupt it somehow.

CutterBl
4 Jun 2009, 2:26 AM
It all sounds great! I've downloaded everything, and look forward to taking 'er for a test drive:)

jimmifett
4 Jun 2009, 6:47 AM
update

v0.6

fixed some bugs.
made the example a bit clearer.
added more support for the upcoming management console.
made the stack self-registering.
moved some stuff into private member access.

see above for full details.

jimmifett
5 Jun 2009, 12:24 PM
update

v0.7
Fixed a few bugs, esp a nasty bug breaking directFn.
Added Management Console

see above for more details

jimmifett
5 Jun 2009, 12:56 PM
The way i'm invoking stateful cfc's (line 158 of ExtDirect.cfc) is pretty ugly, using an evaulate(), but it works. I try to avoid evaluate() like plague infested zombies.

Does anyone have a better way of doing this?



//StatefulNamespace = 'application.ExtDirect', specified
// in the cfcomponent tag's attributes and loaded into the registry

//Arguments.Component is the name of the component with it's dot
// path and used as the struct key for variables.extDirectComponentRegistry.
// Example: Componets.Ext.ExtDirect

//Arguments.Method is the method to call
// Example: saveRegistry

//argv is a name/value parameter struct. With the above examples,
// it's simply an empty StructNew()

MyStruct.OperationResult = Evaluate("#variables.extDirectComponentRegistry[Arguments.Component]['StatefulNamespace']#.#Arguments.Method#(argumentcollection = argv)");

-Jim

CutterBl
5 Jun 2009, 1:36 PM
Have you tried something like...



MyStruct.OperationResult = VARIABLES.extDirectComponentRegistry[ARGUMENTS.Component]['StatefulNamespace'][ARGUMENTS.Method](argumentCollection:argv);

jimmifett
5 Jun 2009, 2:23 PM
That doesn't work for me since the StatefulNamespace is the actual location in memory for the already instantiated component.

So, the component is registered as 'Components.Ext.ExtDirect', but the StatefulNamespace 'application.ExtDirect' says that it's already loaded into the application scope under application.ExtDirect.



application.ExtDirect = CreateObject("Component", "Components.Ext.ExtDirect").Init()


So what i'm trying to do is call application.ExtDirect.saveRegistry() dynamically.

This could also be used when you load stateful cfcs into the server scope:


server.mycfc = CreateObject("Component", "mycfc").Init()


with 'server.mycfc' as the StatefulNamespace, i'd want to dynamically call server.mycfc.someMethod();

jimmifett
8 Jun 2009, 6:27 AM
Ok, looks like what I want to attempt with function references to replace the evaluate may not work. Oh well, at least evaluate is better than nothing.

Anywho, some screenshots of the Management Console:

aconran
8 Jun 2009, 1:23 PM
Management Console looks neat; great work!

realjax
14 Aug 2009, 5:48 AM
This looks very interesting.
I've tried putting ExtDirectCF in a subdir of the webroot but then all hell breaks loose.

Is that not an option or am I missing something?

Cheers

Sanems
30 Aug 2009, 11:04 PM
1 for perl, would begin coding against it today. Also, can there be/is there a JS-based stack for possible use with apps like freeswitch and couchDB?Thanks Ext

jimmifett
10 Sep 2009, 6:42 AM
This looks very interesting.
I've tried putting ExtDirectCF in a subdir of the webroot but then all hell breaks loose.

Is that not an option or am I missing something?

Cheers

what problem specifically do you run into?
Also, i found a bug that doesn't show up in firefow, but does in IE for the admin tool. I fixed it, but forgot to upload it. (bug is super oversized dialogue thingy)

*goes to look for the fix and upload...*

jimmifett
10 Sep 2009, 7:19 AM
I had been busy lately and had not gotten a chance to work on updates, but now I have more time to support this stack :D

Just uploaded v0.8 which fixes a console bug in IE and changed the paths of where i had ext3 pointed to. Formerly this pointed at a release candidate.

ok, to clear up a little bit of confusion, i'll discuss filesystems.

this stack expects your filesystem to look similiar to this before extraction:

/
/Components
/Javascript
/Javascript/ext-3.0.0

after extraction, it should look similar to this:

/
/Components
/Components/Ext
/Components/Ext/ExtDirect.cfc
/ExtDirect
/ExtDirect/API.cfm
/ExtDirect/Application.cfc
/ExtDirect/Console.cfm
/ExtDirect/example.cfc
/ExtDirect/example.cfm
/ExtDirect/example2.cfc
/ExtDirect/example3.cfc
/ExtDirect/ExtDirectRegistery.json
/ExtDirect/Router.cfm
/Javascript
/Javascript/ext-3.0.0

now, if you have you ext 3.x library in a different location, or when a new version comes out, you will need to modify Console.cfm and example.cfm to reflect this differing path to extjs.

example, for backwards compatibility as I upgrade older stuff, i have the following:

/Javascript
/Javascript/ext-2.1
/Javascript/ext-2.2
/Javascript/ext-2.2.1
/Javascript/ext-3.0-rc2
/Javascript/ext-3.0.0

I will eventually add a /Javascript/ext-3.0.1 to my filesystem and have to change my files.

Of additional note is the Application.cfc. You can either leave this in the ExtDirect directory to keep it segmented from the rest of the application, especially if you use a different framework; or you can move it into your root if you'd like to build upon this basic framework. The choice is up to you. I think most people will leave it in the ExtDirect directory, and I recommend as much unless you like to tinker and are good at playing with application frameworks.

-J

jimmifett
10 Sep 2009, 7:22 AM
1 for perl, would begin coding against it today. Also, can there be/is there a JS-based stack for possible use with apps like freeswitch and couchDB?Thanks Ext

You may wish to ask this in a different thread :)
This particular thread is for the ExtDirectCF stack.

-J

paradoxy
28 Sep 2009, 10:07 AM
I can't wait to get my hands on ExtDirectCF. Been struggling (as an Ext newbie) with the Ext version and need a new approach.

Alas, whenever I download the zip it is corrupt. Is it me or is everyone having the same problem?

Are there any other locations to download the archive?

Thank you!

Update...I was downloading with IE. Tried downloading with Chrome and viola, it's ok. Odd problem with zips and IE.

jimmifett
14 Oct 2009, 8:31 AM
New version up. Check out the release notes in the original post.

New example showing a fully implemented CRUD api in a paging grid with row editor.

Added support for Ext.Direct 1.0.1

new index.cfm page with links to the example, console, and other useful things.

TomChiverton
6 Nov 2009, 1:57 AM
I'm not sure, but you might need to make the same mods to your version as I just posted to the original in order to run on the Railo CFML engine: http://www.extjs.com/forum/showthread.php?p=403454#post403454

JGALFO
25 Mar 2010, 10:16 AM
Hi Jim,

I've downloaded the package and started playing with it and came up with a few questions and suggestions.

First of all great job on something that to me sounds like a good candidate for another CF Framework (I know I said the bad word) but for those of us who are using CF only as the middleware of sorts, controlling our model and as way of manage the data layer, this would be perfect. I am not too familiar yet with Direct but it seems to be the cleanest way to interact with the back end.

I noticed no recent posts in here. Is this project still alive?
I'd like to share a few modifications I made to it that will allow among other things to place "the framework" anywhere in the server. I'd like to also integrate it with coldspring which is a well known IoC framework for ColdFusion.

I am still playing with it and trying to get my arms around it and I did not want to re-invent the wheel if people have already thought/implemented some of these things.

Please let me know.
Thanks
Jose.

jimmifett
25 Mar 2010, 10:44 AM
Yep, still alive.
I've been waiting for designer to come out clean up some stuff.

The framework presented with this Direct handler is an ultra lightweight version of what I normaly use, having the bare bones basics, geared for simplicity and to get up to speed quickly.

I'd appreciate any input you may have.

JGALFO
25 Mar 2010, 10:06 PM
Jim,
I'd be curious to see what you use but attached is my version with some modifications to make it portable in a any directory structure. The changes are quite a few so please check the ReadmeByJose.txt in the package.

Expand the attached myapp.zip on your wwwroot directory. This will setup the following directory structure:

/myapp - The root directory for your application
/myapp/ExtDirect - The directory for ExtDirect management
/myapp/cfcs - The directory for your application cfcs
/myapp/cfcs/Ext - The directory for the ExtDirect.cfc (and any future framework related cfcs if any)
/resources - General directory for js, css and in this setup the ext library
/resources/js - JavaScripts specific to your app
/resources/css - CSS specific to your app
/resources/ext-3.1.1 - The Ext library (version used for this test. Not included because of the size)
/samples/ExtDirectCF_Examples - The sample app

Note: I only tested this in my mac and in Linux using coldFusion 8.

Please check out some of the things I did as well as some of my notes regarding planned modifications. Again I put forth the disclaimer that I am still familiarizing with the feature rich ExtDirect.cfc and the whole thing so I might have missed a few things.

Let me know what you think and maybe we can coordinate a few of those changes. I am planning to use this in my next project.
Feel free to contact me at my yahoo IM, my nick is jgalfonso

Thanks
Jose.

TomChiverton
29 Mar 2010, 12:28 AM
I use this framework less because modern CFML engines allow CFCs to be invoked and return JSON formatted objects trivially.
If you need to perform common or repeatable transforms to make your CFCs useful to the outside world, something like ColdSpring's Remote Facade feature is a good way to go.

jimmifett
9 Apr 2010, 6:36 AM
Big update coming soon. The changes are enough that i've completely skipped 1.0 and gone straight to a 2.0 revision. I'll have it posted up hopefully sometime this weekend after I finish re-doing the management console, re-do the demo grid example, and add a form example.

Some of the changes:
* moved api.cfm and router.cfm into a single non-bean cfc.
* separated console handler into it's own cfc, removing exposure of the main core. Allows for more robust console and end user to plug in own console authentication model w/o worrying about the functionality of the core.
* cleaned up results spitting back out the data object from the original request due to lazy object copying.
* added several of Jose's contributions.
* finally finished ability to register entire directories with optional recursion.
* moved init config information into an xml file, with option to specify alternate config files during init().
* added debug struct to the core cfc bean to aid in troubleshooting. Stores info on last internal action if in debug mode.
* debug mode.
* debug.cfm convenience page to view registry and debug struct.
* added tons of more error handling, esp in regards to the json registry backup file during read and write operations.
* simplified component level AllowExtDirectReflection attribute back down to ExtDirect bc i'm a lazy typer ;)
* added support for ExtFormHandler... dunno how I missed that the first go around...
* console supports removal of specific methods of a component in the registry.
* console requires authentication to use. Uses simple hard coded auth by default. Override with your own custom auth model in the cfc if you wish.
* cleaned up a couple missing var scopings.
* moved all code to extjs 3.2.0 (cf8 is still a minimum requirement)
* alphabetized methods and sorted by scope access
* lots of fiddling with the internal wibbly wobbly, timey whimey... stuff.

-J

JGALFO
9 Apr 2010, 11:30 AM
Great Jim, I am looking forward to checking out the new version!
Let me know if you looked into adapting it to coldspring, that's something I'd be very interested in. Once you have your version up I can help on that adaptation if needed.
Thanks.
Jose.

JGALFO
23 Apr 2010, 2:10 PM
Hi Jim
Any updates on the revisions you were working on?

jimmifett
27 Apr 2010, 4:54 AM
Sorry, got delayed with family and work, will have it up as soon as I can get some free time from one of the two lol

Stju
4 May 2010, 3:03 PM
Very nice implementation, thought i have a Question:
In response from ColdFusion database query Row headers are all in UPPERCASE..
There are some cases when You need to pass configuration data back to Client side, WHICH is CASE SENSITIVE...
Just a few examples: metagrid , meta form, tree node configurations and so on..

JGALFO
4 May 2010, 3:58 PM
You can map it in the reader config section of your store:



reader: new Ext.data.JsonReader({
fields: [
{ name: 'employeeId', mapping: 'EMPLOYEEID', type: 'int' }
,{ name: 'employeeName', mapping: 'EMPLOYEENAME', type: 'string' } ]

,idProperty: 'employeeid'
,root : 'ORG'
,totalProperty : 'RECORDCOUNT'
})

Stju
4 May 2010, 4:09 PM
Yes and No..
Yes mapping will work for grid data, but not for example places where you need to specify like Tree iconCls... , and other places where defenition is by - directFn..
I came up with a dirty solution at serverside.
After Encoding to JSON, Just apply this function which will fix case problem =D>
If at some stage I need other ones, just add to list..


<cffunction name="reservedEXTJS" access="public" returntype="string" output="false">
<cfargument name="toTest" type="string" required="true">
<cfscript>
return ReplaceList(toTest, "iconcls,uiprovider", "iconCls,uiProvider");
</cfscript>
</cffunction>

jdennis
12 May 2010, 11:48 AM
How do you pass named parameters to Ext DirectCF via JavaScript?



I have a function that passes JavaScript parameters to my ColdFusion function via Ext Direct CF by ordinal position. However, I would like to pass in the parameters as named parameters or as an object. Is there a way to do this? If so, what is the syntax to do this so that Ext DirectCF can interpret what values are mapped to the arguments in the CF method?


This works but is not the preferred

function getNavDescription(page_id, role_id, header_id)
{
var cfComponent = "components.main.navigation";
Ext.ss[cfComponent].getNavigationDescription(page_id, role_id, header_id, function(obj){
rcvdResponse(obj);
});
}


Preferred Something Similar to this...


function getNavDescription(page_id, role_id, header_id)
{
var cfComponent = "components.main.navigation";
Ext.ss[cfComponent].getNavigationDescription({page_id: page_id, role_id: role_id, header_id_name: header_id}, function(obj){
rcvdResponse(obj);
});
}

CutterBl
12 May 2010, 12:33 PM
This is actually a deficiency of the Ext.Direct api implementation, and is listed in their notes within the Direct documentation as a feature coming at some time in the future.

jdennis
13 May 2010, 4:04 PM
This is actually a deficiency of the Ext.Direct api implementation, and is listed in their notes within the Direct documentation as a feature coming at some time in the future.

Thanks that was quick response.

hampsterx
27 May 2010, 1:47 AM
Hi guys,

I have a formPanel and the following defined


api: {

submit: Ext.tracker['cfc.category'].save,
load: Ext.tracker['cfc.category'].load
},



The load works fine but I cannot get the submit to work at all :(
Is this feature suppose to work with ExtDirectCF? If so can someone provide an example

Cheers and fantastic work with ExtDirectCF,

murrah
15 Aug 2014, 12:55 PM
Hi.

Back at this post: http://www.sencha.com/forum/showthread.php?70264-ExtDirectCF-A-Managed-ColdFusion-Server-side-stack-with-security&p=456740&viewfull=1#post456740 there was talk of a version 2.0.

Did that happen? The 0.9 version seems to be the latest I can find.

Thanks,
Murray

jimmifett
19 Aug 2014, 1:25 PM
Yeah, there is a much better version 2.0 that I use frequently for work. In spare time, I've been working on demos for it. I'll see about finishing up the demos and uploading sooner rather than later.

-Jim

murrah
20 Aug 2014, 11:49 AM
Thanks Jim, that would be great!
Murray