Categories
Archives
Introducing : jQuery MultiSelect | Home | A Crappy New York Times Feature
Filed under Quick Tips on December 7, 2007 by Javier JulioColdFusion Structures: Differences in Version 7 and 8
I know my fair share of ColdFusion bloggers that have started to dig "under the hood" and see what Java objects are being used by CF even utilizing undocumented Java methods in their CF code. I never thought I'd actually take the plunge myself but I had to uncover an issue with one of our application's moving from CF7 to CF8.
The code at fault has a very simple task: to make asynchronous HTTP calls to log incoming requests. Since the application was originally running on CF7 we needed a third party library to make asynchronous HTTP POST and GET requests so we brought in Mark Mandel's AsyncHTTP. The library provides a CFC (ColdFusion Component) that acts as a wrapper for a set of Java classes that both contain a post and get method.
After viewing some cfdump's I logged I noticed an error that read "The post method was not found". The post method in the CFC was firing but the error occurred when trying to call the post method in the AsyncHTTP Java object.
With another cfdump of the Java object itself I noticed a post method with no arguments and one with two (which happens to be the one we are using). The first argument is of type java.net.URL (the URL being requested) and the second is of type java.util.HashTable (a ColdFusion structure containing form data). The post method was being called and given two parameters but I wasn't so sure that the second parameter was right.
I haven't written any Java code since college but I did remember about it supporting different method signatures. I wasn't sure if Java treated a method call that received the required number of arguments but did not match the argument types required as if the method did not exist but apparently it does. In fact a method signature in Java also accounts for the order of parameters on top of that. Some pretty hardcore stuff.
The post method was without a doubt receiving its first parameter of type java.net.URL (since it was creating a Java object of that type and passing it) so I decided to investigate the second. With one of our development servers running CF7 I ran a simple script that dumped all of the Java super classes a ColdFusion structure has. I ran the same script on CF8 and the output did not match. In fact it has one parent less. You can see the results below:
ColdFusion 7
- coldfusion.runtime.Struct
- coldfusion.util.FastHashtable
- java.util.Hashtable
- java.util.Dictionary
- java.lang.Object
ColdFusion 8
- coldfusion.runtime.Struct
- coldfusion.util.FastHashtable
- coldfusion.util.CaseInsensitiveMap
- java.lang.Object
As you can see a structure in CF8 no longer has a parent class of java.util.HashTable and this leads to Java not being able to find the post method since it's looking for that type but is not getting it. After seeing these changes I wondered if this is one of the reasons too why structure creation in CF8 is considerably faster (much like everything in CF8!).
With this information in hand I rather stupidly email Mark notifying him of my discovery and if a fix to the AsyncHTTP library would be easy. Why stupid? Well CF8 right out of the box now allows us to make asynchronous HTTP requests simply using a combination of cfthread and cfhttp. Problem solved! Our application is now running in production and performing like a true champ thanks to CF8!
Unfortunately, this leads us to no longer use Mark's awesome AsyncHTTP library but I'm sure he will understand. CF7 and AsyncHTTP or CF8? Oh that's a tough one. Sarcasm aside, Mark thanks for the advice and providing such a great library to the community!
Trackback Pings (TrackBack URL for this entry)
http://www.arc90.com/cgi-bin/mt4/mt-tb.cgi/89.
Comments
Mark,
How though would it be able to accept a java.util.Map if a CF struct doesn't even have a super class of that type? Would the AsyncHTTP library have to create a java class of that type then add in the struct data?
No big deal at all! Since we have moved to CF8 all the features of the library are now built in. Again thanks Mark, much appreciated!
Posted on December 7, 2007 6:12 PM by javierj
Nice job Javi. I look forward to reading more from you.
Posted on December 7, 2007 7:26 PM by hibiscusroto (Chris Vigliotti)
Javier, I think what Mark's alluding to is the fact that the java.util.hashtable class from which CF7's structure is extended, and the coldfusion.util.FastHashtable class from which CF8's structure is extended, both implement the interface Map. So, if he had written his code to refer to that interface, instead of specifying concrete classes, there's a good chance the library would have been forwards-compatible with CF8. No worries though Mark, that's a very understandable case - when writing Java code, it's hard to remember to declare variables as interfaces rather than the concrete classes we're actually working with.
Posted on December 9, 2007 12:22 PM by Avi Flax
I didn't think about that and I should have. With my recent experience in Flex and ActionScript I remember once I had to specify a function argument of not a certain data type like String or Boolean but an interface. For some reason I was thinking of type checking as only that simple but you can type check against a class, even an interface. Thanks for clarifying Avi.
Posted on December 10, 2007 12:10 PM by Javier Julio
Good to see you blogging! Pretty hardcore details though - clearly you're hanging out with Ben too much :->
What about something about your cool CSS work for the next posting?!
Posted on December 10, 2007 6:46 PM by Peter Bell
Peter,
Thanks for the comment! I'm hoping to get in the swing of things here. I think this would be a great opportunity for me to see if blogging is something I'd like to do more regularly. I've never gotten into it but had tried.
You know my secrets! Originally my first blog post was about my CSS Framework (or library, base, whatever you want to call it) but I need more time to write it up. I see it more as a series of blog posts like some of yours that you've done. I will let you know though once I do post up something on it!
Posted on December 10, 2007 6:54 PM by Javier Julio
Javier,
Nice to see you blogging! Keep the posts coming in.
Posted on December 11, 2007 1:33 AM by Rakshith
Rakshith, thanks! When are you going to share the code for that CFU presentation you made on the AJAX features in CF8? It was using a combination of just about all the AJAX tags and cfexchange. Let me know! :)
Posted on December 11, 2007 10:04 AM by Javier Julio
Great post Javi. I couldnt add a comment earlier. Anyway...
Gotta love doing a little under the hood work with coldfusion :) CF/Java fun stuff!!
Cheers man!
Posted on December 12, 2007 12:26 AM by Matthew Abbott
Introducing : jQuery MultiSelect | Main | A Crappy New York Times Feature

Javier,
Happy to help out!
In retrospect, I should have made the get/post interface take a java.util.Map rather than a Hashtable, but, ah well, no big deal there.
Glad you got it all sorted! ;oD
Posted on December 7, 2007 5:40 PM by Mark Mandel