Some Tips on Using ColdSpring Remoting

Posted on Jul 16, 2007

As part of developing a training exercise (and in my continuing series on objects and composition), I was trying to work with ColdSpring's auto-magic remoting feature (check the documentation for more information on this feature). I ran into some issues that had me pulling my hair out, so to save you the headache, I will post the details here. The first has to do with the name of your ColdSpring factory variable and the second with the ColdFusion 8 beta and remoting.ColdSpring Factory Variable Name
In the normal scenario, I might name my actual ColdSpring factory something like application.factory or application.coldspring. This seems to cause an error when using the auto-remoting feature saying something like:

"Sorry, a ColdSpring BeanFactory named  was not found in  scope. Please make sure your bean factory is properly loaded. Perhapse your main application is not running?"

After a little digging, you will find that it is calling the getDefaultFactory() method which looks for a factory name of "coldspring.beanfactory.root". I thought you might be able to change this by adding it to the default properties structure you pass into ColdSpring, but it this was possible, I could not get it working.

NOTE: Brian Kotek refers me to a better, though apparently undocumented, solution to this problem. See the comments below.

In the end, you have two solutions. The first, which I first saw here, is as to simply use the default name:

<cfset application["coldspring.beanfactory.root"]= createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties=props)/> <cfset application["coldspring.beanfactory.root"].loadBeansFromXmlFile(expandPath("/csFlex/config/services.xml"),true)/> <cfset consoleService = application["coldspring.beanfactory.root"].getBean("consoleService_remote") /> <cfset consoleService = application.factory.getBean("consoleService_remote") />

The second, and the one I prefer, is to use your usual name, but create the remote proxy "manually" using the RemoteFactoryBean API like so:

<cfset application.factory= createObject("component","coldspring.beans.DefaultXmlBeanFactory").init(defaultProperties=props)/> <cfset application.factory.loadBeansFromXmlFile(expandPath("/csFlex/config/services.xml"),true)/> <cfset consoleService = application.factory.getBean("&consoleService_remote") /> <cfset consoleService.setBeanFactoryName("factory") /> <cfset consoleService.createRemoteProxy() />

ColdSpring Remoting and ColdFusion 8 Beta
So, you have the prior issue all fixed and everything should work perfectly right? Well, not if you are running the ColdFusion 8 beta. Apparently, a change in ColdFusion 8 has made it so that when a CFC method has a returntype of "any", Flex 2 will completely choke on it returning you something like this:

ArgumentError: Error #2004: One of the parameters is invalid.
   at flash.utils::ObjectInput/readObject()
   at mx.collections::ArrayList/readExternal()
   at mx.collections::ArrayCollection/readExternal()

After searching around, it appears this was discussed on the ColdSpring list and also by Paul Hastings. On Paul's blog, Tom Jordahl notes that this will be fixed in the final release, which is good to hear. Still, it is important to note before you go pulling your hair out trying to get this to work.

Well, I am Stuck
I had hoped to get a sample together to show everyone how you could use my generator and ColdSpring to quickly build a Flex application, but since I am running only 8 locally, this might have to wait until this bug is fixed or I switch back to 7 (which I just might do - yes, I know you can run both but I don't want to spend so much time on a temporary solution).

Comments

Brian Kotek Brian, did you pass the bean factory name in the XML when you define the remote proxy? I ask because I have been using remote proxies fine and I don't have to define the application variable with a name like that.

Yes, the bug with returntype=&quot;any&quot; will be fixed in the final release of CF8.

Posted By Brian Kotek / Posted on 07/17/2007 at 12:02 AM


Brian Rinaldi @Brian, If it wasn't in the example on the docs, I didn't put it. I know others who had this problem too, so at least I am not alone. Where would this be defined?

Posted By Brian Rinaldi / Posted on 07/17/2007 at 12:34 AM


Brian Kotek I recently put up a blog entry about a modification I made to ColdSpring that will let me modify the API of methods in a generated proxy, as well as inject custom metadata into AOP Advices. The blog post has an example bean declaration in XML that shows the use of the BeanFactoryName element. You can see it at &lt;a href=&quot;http://www.briankotek.com/blog/index.cfm/2007/7/12/ColdSpring-Mad-Science-Injecting-Metadata-for-use-in-AOP-and-Proxy-Generation&quot;&gt;http://www.briankotek.com/blog/index.cfm/2007/7/12/ColdSpring-Mad-Science-Injecting-Metadata-for-use-in-AOP-and-Proxy-Generation&lt;/a&gt;. See if adding that to your XML that makes a difference.

Posted By Brian Kotek / Posted on 07/17/2007 at 12:40 AM


David Farr Thank you, thank you ... I was having exactly this problem. Being new to CS it was hard for me to know if the problem resulted from my stupidity or not. I thought I had followed the examples correctly - guess that was part of the problem. I had actually discontinued trying the remote stuff in the hopes that returning some time later would bring new insight.

Posted By David Farr / Posted on 07/17/2007 at 12:25 PM


Brian Rinaldi @Brian - That worked perfectly. Thanks. I did confirm that this was not in the remoting docs (at least not anywhere that I saw). I will make a note in the post to refer to this solution as it makes the most sense.

@David, glad it helped.

Posted By Brian Rinaldi / Posted on 07/17/2007 at 2:12 PM


Chris Phillips FYI, I'm running CF (8,0,0,171647) on Vista. And I still had to change the returntype to &quot;array&quot; in the ColdSpring generated remote proxy to get remoting to work.

So, I guess they didn't &quot;fix&quot; it for the release. Maybe it's nothing to be fixed... returntype of &quot;any&quot; is rather vague.

Posted By Chris Phillips / Posted on 08/21/2007 at 5:38 PM


Write your comment



(it will not be displayed)





About

My name is Brian Rinaldi and I am the Web Community Manager for Flash Platform at Adobe. I am a regular blogger, speaker and author. I also founded RIA Unleashed conference in Boston. The views expressed on this site are my own & not those of my employer.