>> GreenByte.info By Nick Tong (quiksilv) | Supported by: TalkWebSolutions.co.uk

Setting up Coldspring within fusebox via the CS lexicons

After a couple of hours chatting back and forth on the fusebox mailing list I've got the coldSpring lexicons working. The reason this took so long was because I had a concern that to use any of the lexicons you have to use the initialize lexicon to setup coldspring (CS). This meant that I had to change my code that I'd already setup, somehow that didn't feel right. That said it's just a 5 min change (once you know what you're doing).

Cutting to the chase:

To get CS setup you need to initilise the CS factory, you do this using the initialize verb mentioned above. The best place to do this is in the appinit section of fusebox.xml.cfm as this is called as you start your app (it's like the onApplicationStart function in application.cfm). Within this function I call a fuseaction in my model circuit:

<appinit>
   <fuseaction action="m.coldSpringSetup" />
</appinit>
NB: Make sure you use "fuseaction action="m.coldSpringSetup" and not "do action="m.coldSpringSetup" "

Then inside my model circuit i have this fuseaction

...
<circuit access="public" xmlns:cs="coldspring/">
<fuseaction name="coldSpringSetup">
   <cs:initialize    coldspringfactory="servicefactory" defaultproperties="#application.defaultProperties#">
      <cs:bean beanDefinitionFile="#expandPath('/config/coldspring.xml.cfm')#" />
   </cs:initialize>
</fuseaction>
...

So what is it that we're doing here.
<circuit access="public" xmlns:cs="coldspring/"> - we're declaring the namespace for the coldspring lexicons
cs:initialize - this calls the initialize verb from the coldspring lexicon folder.
coldspringfactory="servicefactory" - this is giving the coldspring factory it's name.
cs:bean - this calls the bean verb from the coldspring lexicon folder.
beanDefinitionFile="#expandPath('/config/coldspring.xml.cfm')#" - this passes my config file to coldspring

Once you've done this you'll all set up...wait, what! Yup, it's that easy.

Next you'll want to call some a method within CS, right?


<cs:get    bean="categoryService"
         returnvariable="variables.categoryService"
         coldspringfactory="servicefactory" />

So what's going on here:
cs:get - this invokes the get verb from the coldspring lexicon folder.
bean="categoryService" - this tells CS which bean (function or method) in needs to get from the CS factory
coldspringfactory="servicefactory" - this tells CS which coldspring factory to use.

And that all folks!

You can then call your objects as normal

<invoke object="variables.categoryService" methodcall="productCategorySelect(attributes.catalogueID)" returnVariable="qProductCategoryList" />
A big thanks goes out to nathan strutz and Qasim Rasheed for these lexicons.


 
Comments
nick tong's Gravatar Note: If you set up reactor via CS then you can add this to your "coldSpringSetup" fuseaction:

<cs:get bean="ReactorFactory"
            returnvariable="application.reactor"
            coldspringfactory="servicefactory" />
# Posted By nick tong | 16/03/07 23:10 | Report abusive comment
Dan Lancelot's Gravatar Thanks for that Nick - will definately make my life easier when i start to look at CS in (hopefully) a few weeks...

One question:
within the <cs:get .../> tag you set: coldspringfactory="servicefactory"

I presume this must tie up with the application.servicefactory object that was created within the <cs:initialise .../> tag

How come its referenced as servicefactory and not as application.servicefactory?
# Posted By Dan Lancelot | 16/03/07 23:23 | Report abusive comment
nick tong's Gravatar Hi Dan, glad to help.

The initlize verb prepends the coldspringfactory with: myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory#

#fb_.coldspringfactory# being the name you give it.

The get verb also uses this to get the CS factory name:

#fb_.returnvariable#myFusebox.getApplication().getApplicationData().#fb_.coldspringfactory#.getBean
# Posted By nick tong | 16/03/07 23:26 | Report abusive comment
Dan Lancelot's Gravatar Ahh - thanks - that makes sense then.
# Posted By Dan Lancelot | 16/03/07 23:28 | Report abusive comment
Sean Corfield's Gravatar Note that "servicefactory" is the default so you can omit it from the cs:initialize and cs:get verbs.

You only need that attribute if you want to use a different variable name - or have multiple factories (so you'd have multiple cs:initialize tags with different coldspringfactory attributes).
# Posted By Sean Corfield | 20/03/07 03:08 | Report abusive comment
Howard Fore's Gravatar Nick, thanks for this, looks cool. What's the application.defaultProperties that's referred to in the cs:initialize tag?
# Posted By Howard Fore | 24/08/07 02:46 | Report abusive comment
Nick Tong's Gravatar @Howard - thanks. The applicationdefaultproperties argument is where I store my dynamic valubales that i was to pass into the ColdSpring's xml file i.e. my datasource name. Dan Vega has a good post on passing entries into CS here: http://www.danvega.org/blog/index.cfm/2006/11/25/P...
# Posted By Nick Tong | 24/08/07 07:47 | Report abusive comment
Toni's Gravatar bind p name or??
# Posted By Toni | 13/04/08 07:31 | Report abusive comment
Tim's Gravatar Hi there

If anyone can help me with this i'd be much appreciated, I'm getting the following error:

Element SERVICEFACTORY is undefined in a CFML structure referenced as part of an expression.

For the life of me I can find a solution anywhere. If you have come across this before and found a solution, I'd love to hear it.

Cheers,
Tim
# Posted By Tim | 19/09/08 15:05 | Report abusive comment
Nick Tong's Gravatar Hi Tim - are your mapping setup correctly - whats your setup? CF mapping, Virtual, files in your root etc
# Posted By Nick Tong | 25/09/08 00:01 | Report abusive comment
Tim's Gravatar Hi Nick - I only have access to the web root so all the files are in there. No mapping or anything. It's seem to happen randomly though if I had to guess I'd say the more people using the site the more it happens.

Initialised like zis:

   <fuseaction name="coldspring">
   <cs:initialize coldspringfactory="servicefactory">
       <cs:bean beanDefinitionFile="#expandPath('/config/coldspring.xml.cfm')#" />
       </cs:initialize>
   </fuseaction>   

Any Ideas?
# Posted By Tim | 02/10/08 19:39 | Report abusive comment
Dan Lancelot's Gravatar @Tim

Without seeing the context, this may not be relevant, but:

Are you only initialising ColdSpring (and the fusebox CS initialisation) on application initialisation, rather than on every request?

Have you ensured that access to this coldspring fuseaction is single threaded - your reported issue sounds like it could be a concurrency issue - if you had 2 concurrent requests to the initialisation action, the ServiceFactory could have been created by request 1, and be being accessed either as part of initialisation process - or from elsewhere in the application - and then request 2 will come along and begin initialising again - and in so doing destroy the ServiceFactory... which then doesn't exist for request 1...

Could that be your issue?
# Posted By Dan Lancelot | 03/10/08 10:58 | Report abusive comment
Nick Tong's Gravatar @Tim - @Dan is right it could well be that you have the app initialing CS on more than one request. I tend to setup CS and Transfer in my globalfuseactions in the fusebox.xml file - i.e.

<globalfuseactions>
      
      <appinit>
         <fuseaction action="security-m.frameworkSetup" />
      </appinit>
....

I hope that helps
# Posted By Nick Tong | 06/10/08 08:19 | Report abusive comment
Travis's Gravatar I'm new to Coldspring and can't seem to quite get the setup right. I did the above which makes sense, but i wasn't sure what the application.defaultproperties are set to and where the config path for the coldspring.xml.cfm file came from. i have downloaded the lexicon for coldspring. When run i get a "Could not find the ColdFusion Component coldspring.beans.DefaultXmlBeanFactory" error. thanks for any advice
# Posted By Travis | 20/11/08 15:26 | Report abusive comment
nick tong's Gravatar Hi Travis - it sounds like a pathing issue - can you check your paths are correct?
# Posted By nick tong | 20/11/08 22:33 | Report abusive comment
ivanko's Gravatar Are you only initialising ColdSpring (and the fusebox CS initialisation) on application initialisation, rather than on every request?
# Posted By ivanko | 22/11/08 16:13 | Report abusive comment
nick tong's Gravatar yes - thanks correct - once it's in the app scope you don't need to do anything else with it.
# Posted By nick tong | 22/11/08 16:28 | Report abusive comment
BlogCFC was created by Raymond Camden. This blog is running version 5.5.1.