Coldfusion, Flex, and SSL
So I want to start off this post by stating that I’m a computer programmer. I don’t consider myself a computer scientist, and I generally prefer my IDEs and other software just work. I don’t want to have to think too much about the configuration, etc. That being said, I have been itching to try Flex for a long time. I finally have an opportunity at work, and the process I had to go through to get it all working was daunting to say the least. But now that I have it in place, everything seems to be going smoothly.
So here’s the situation, I work on a website that resides totally in SSL, it’s an application we’ve developed with some sensitive information in it, so I wanted to make sure everything stays in that realm. Also, I used ColdSpring and Model-Glue (version 2, the sites been around a while now) to get it all running. In order to use the Flash Builder 4.5 wizards to generate the RemoteObjects for ColdFusion, Flash Builder needs to do introspection. I can’t find any other way to actually connect them together.
So the first thing that has to be covered is creating the RemoteObject using ColdSpring. This isn’t as intuitive as I would have first thought, but didn’t seem too difficult. You create a coldspring.aop.framework.RemoteFactoryBean and you have to make sure you instantiate it or else it doesn’t get created. This just means a simple application.remoteFactory.getBean(‘ServiceRemote’) call and you have your remote bean file. All looks good.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <bean id="ServiceRemote" class="coldspring.aop.framework.RemoteFactoryBean" > <property name="target"> <ref bean="Service" /> </property> <property name="serviceName"> <value>ServiceRemote</value> </property> <property name="beanFactoryName"> <value>remotingBeanFactory</value> </property> <property name="relativePath"> <value>/model/RemoteObjects/</value> </property> <property name="remoteMethodNames"> <value>method1,method2</value> </property> </bean> |
The first problem then comes if you try to use the CFC Explorer to go to this file. You’ll find that the CFCExplorer doesn’t trigger the application’s OnApplicationStart or anything else, so you don’t have your bean factory. I’m not sure how others have handled this, but I added in a line like this to the bottom of my application.cfc:
1 2 3 4 5 | <cfif not isDefined('application.remotingBeanFactory') and (FindNoCase('cfcexplorer',CGI.SCRIPT_NAME) neq 0 )> <cfscript> this.onApplicationStart(); </cfscript> </cfif> |
The second part of the CFIF being to keep that onApplicationStart from firing every time I went to it.
Now, this still didn’t seem to fix the whole problem, and I ended up finding this post on Application Introspection by Terrence Ryan. Boy did that help. I have found that if I add it to the RemoteObject after generation, I get my cfcexplorer to fire up every time. Like so:
1 2 3 4 5 6 7 8 | <cfset bfUtils = createObject("component","coldspring.beans.util.BeanFactoryUtils").init()/> <cfset test = new Application() /> <cfif not len(variables.beanFactoryName)> <cfset bf = bfUtils.getDefaultFactory(variables.beanFactoryScope) /> <cfelse> <cfset bf = bfUtils.getNamedFactory(variables.beanFactoryScope, variables.beanFactoryName) /> </cfif> |
Now we get into the really fun stuff. Thanks to Joshua Curtiss’ post on Flex Remoting over SSL I found that you have to make changes in the remoting-services.xml file in your flex folder in order to actually use the secure channel.
After that, if you’re doing your local development like I am with a self-signed certificate, you have to remember to import that certificate into the JVM keystore for your Flash Builder installation. You can see some samples on this here: http://www.java-samples.com/showtutorial.php?tutorialid=210
The last step, is to make sure that your template file that you’re using is a .cfm instead of a .html when you’re running your testing. Thanks to Mike Morearty’s ASP.NET example: Changing the filenames in Flex Builder html templates, I found this pretty simple too. Just make sure you use a format of ${application}${build_suffix}.template.cfm for your CFM pages. And Flash Builder seems to launch in the html page anyway, so you could probably do a url relocate meta tag in that template to forward over to your cfm page and not have to change it every time you launch.
UPDATE: So if you add this line under the opening
tag in your index.template.html, it’ll launch your templated CFM page:1 | <meta HTTP-EQUIV="REFRESH" content="0; url=${application}${build_suffix}.cfm"> |
Pshew! That was a lot of work to get introspection to work for your Data Service Objects. But once you’re there, it does seem to come together very nicely!