The amazing adventures of Doug Hughes

I have been working on a Flex project that will use ColdFusion on the backend. Earlier this week I ran into a little problem that apparently has been reported in the past, but I was unable to find any information ahout the issue. In a nutshell, when using ColdFusion on the backend of a Flex application, ColdFusion will not (cannot?) resolve a ColdFusion mapping for any code in the psuedo-constructor, or in methods called from the psuedo-constructor of a CFC. This only seems to affect multi-server installations of ColdFusion and a bug report has already been filed.

Let me explain a bit more what’s going on. If you’d like to play along at home, grab the sample code You can place the files anywhere you like, but the ‘com’ directory must be put into the web root. Also, you need a ColdFusion mapping (it doesn’t matter what it is called or where it points to, but in the sample it is using a mapping for ColdSpring) Here is the code for test.cfc, if you are using a different mapping for your test, change ‘/coldspring’ to whatever mapping you wish to use.

<cfcomponent>
	<cfset variables.setupVal = "">
	<cfset variables.testVal = "">
	<cfset setup() />

	<cffunction name="setup" access="remote">
		<cfset variables.setupVal = expandpath('/coldspring')>
	</cffunction>

	<cffunction name="test" access="remote" returntype="string">
		<cfset var str = "" />
		<cfset variables.testVal = expandpath('/coldspring') />
		<cfset str = "setup = " & variables.setupval & chr(10) & "test = " & variables.testVal />
		<cfreturn str/>
	</cffunction>
</cfcomponent>

Just to explain the code real quick, there are 2 methods, setup() and test(). In each of these methods, the value of expandPath(‘/coldspring’) is set to a variable, variables.setupVal and variables.testVal respectively. Also, in test() we return a string which outputs the values of these 2 variables. You will see that in the psuedo-constructor, we are calling setup(), so setup() is run everytime the CFC is instanciated.

When you instantiate this CFC in a ColdFusion page (such as text.cfm in the sample code) and then call the test() method, you will see that the values of expandPath(‘/coldspring’) are the same, and should be the path set for the ColdFusion mapping you are using.

setup = c:mypathtoColdSpring
test = c:mypathtoColdSpring

Now, if you run remotingTest.html, which is a flex application that calls the same method on the same CFC, you will probably get results that look similar to this:

setup = c:pathtosamplecodecoldspring
test = c:mypathtoColdSpring

When using the same ColdFusion code from a Flex app, setup() has a different value for expandpath(‘/coldspring’) (remember, setup() is called when the CFC is instanciated). Specifically, instead of resolving the ColdFusion mapping, ‘/coldspring’ is merely appended to the path of the web root where the application is running. The somewhat unexpected result was that in test(), the ColdFusion mapping is resolved and the correct, or expected, value of expandpath(‘/coldspring’) is returned.

If you get the same results in test.cfm and the Flex application, I’d bet you are running a stand alone install of ColdFusion. I have also been able to reproduce this in ColdFusion 7 and ColdFusion 8. A work around for this would be drop whatever mappings you need into your web root, but in a lot of cases that might be impractical.

Run the sample code and let me know what your results are, include what OS, web server and version of CF you are using.

Comments on: "Interesting Issue with ColdFusion Mappings and Flex" (2)

  1. Mark Mazelin said:

    Probably a silly question, but did you verify that “use-mappings” is set to true in your ColdFusion services-config.xml? I imagine that would make it produce different results when called from flex.

    Mark

    Like

  2. Scott Stroz said:

    @Mark – I actually did think of that, yet it did not change the result. That setting only changes whether or not you can find a CFC based on a CF mapping from Flex. In this case, it is finding the CFC just fine, its code that runs when the CFC is found that causes the issue.

    Like

Comments are closed.

Tag Cloud

%d bloggers like this: