Do ColdFusion and Flex really place nice together?

A comment came in on one of my earlier blog posts; and I thought the conversation was interesting enough that I'm promoting it to a post.

The original blog post was about getting ColdFusion and Flex to share objects (CFC and ActionSCript Classes) back and forth. There is a cool automatic conversion from CFCs to ActionScript objects provided by the built-in ColdFusion AMF Gateway.

To make this work you have to specify the properties in the CFC, and the ActionScript object in the same order, using the same case sensitivity, and with the same data type. This is where Ionectu drops in:

"Adobe has gone through a lot of trouble to make sure that ColdFusion and Flex play really nice together"

Translation : `Adobe` is retarded and here`s why, it`s quite simple.

With compilable languages, It`s a must to at least pretend to be able to create it once and leave it alone. It`s OOP not HTML ... amf remoting is `dependency central`. NORMAL people need to be able to change one end and not scrue up the entire thing, this is what development is about (in part), continuity, to have a flow that can be easily redirected.

Amf remoting remindes me of something along the lines of

if(this.file == "index") displayPage(1); else if(this.file == "page2") displayPage(2); else if(this.file == "page3") displayPage(3); else if(this.file == "page4") displayPage(4); else buy a hamster and teach it oop, it`s gonna come up with something better than Adobe did

The hell ?! Are all Adobe employees Google or Microsoft "rejects" ? (that`s not a nice thing to say, I know and I`m sorry, I`m just really pissed off, it just rubs me wrong.)

I, personally, think it is a big leap to call Adobe retarded for the Flex Remoting implementation in ColdFusion. It seems reasonable to me that when two completely separate systems have any similar objects used for the purpose of communicating between these two systems that when you change something on one system a similar change will have to made in the second.

As one example, If you change a database table, you may also have to change a Gateway Object or Data Access Object that relates to that table.

The sole purposes of Value Objects / Data Transfer Objects is to share data between two systems, in our case CF and Flex. IF you make changes to one side of the equation, it makes sense to me that you have to make changes to the other side.

Yes, the exchange is finicky in the order of properties on the objects, the data types of said properties, and the case sensitivity of the property names. CF is not case sensitive--most of the time--but Flex and most programming languages are. I accept the case sensitivity requirement without complaint.

I don't understand Ionectu comparison to the "If" condition. At the end of the day most development is some kind of if condition, isn't it?

I, basically, told that to the commenter, and he followed up:

In, Adobe`s making sure that CF and Flex play nice together they kind of forgot to teach them, how to understand and help each other. At the moment all that they can do is copy values from point a to point b (if you have points defined) (If you don`t you`re better off using wsdl btw). They don`t play nice togheter.. they just copy values from point a to point 1 from point b to point 2, the concept is the simplest I`ve ever seen .... this value goes here, this one here, and .... hm.. yep yep this goes here. Yeah that it. Client.as ....

And if that took them year(s).. well then that`s just sad. They could have spend some time "implementing" some "usability"

How can they as a company think that it`s a success ... "Ok we did it!" .. "To use it you just have to set the same name, set the same position, set an id, on both ends ... and that might do it, I think that`s all". "We`ll call this a ... bridge? no , no, that`s not FLASHy enough.. we`ll call it a protocol.. yeah protocol" ... How can they call that a protocol :wallbash: when clearly it can`t even stand on it`s own "two" feet.

I believe there are huge benefits to using AMF, such as performance and packet size; so I don't agree that we'd be better off using WSDL.

The real question I have is, how else would you implement it? I'm not quite sure.

I can respect that it'd be nice if Flex and CF were a bit more aware of each other.

Why do the properties have to be defined in the same order? Why can't the AMF Gateway use the alias properties in CF and Flex to associate the CFC to the Class and then do some magic to match up properties and data types?

What are your thoughts on this issue?

Want to discuss this in person? Come visit the Flextras booth at 360|Flex in DC this September.

How do I convert a URLpath to SysFilePath if I have the file's URL?

I'm in a writing mood, so decided to tackle this question:

One of your pages talks about how to get a/the filepath from a URL path; so if I know the URL where a file is, can I obtain the (absolute) path, on the server, where this file is? I will gladly supply more details, I just now would like to know if this is doable, in general. thanx!!

This is a hard question to address. First, I don't intimately remember all my 560 blog posts, and the user did not let me know which one he was referring to. Second, I am not aware which technology the user is referring to. Does he want an answer for Flex? Or AIR? Or ColdFusion?

I decided to tackle answers in all three technologies. Assuming you have a URL, how do you get the system path to the file?

In CF, I believe expandPath should give you the absolute file path. Just strip out the domain name of the URL before calling it. In Flex I do not believe you can access the file path of the server, nor the client. The security sandbox prevents such access.

In AIR, a URL to a local file is also the absolute path; but you wouldn't have access to the absolute path on the server.

So, in summary, for ColdFusion use the expandPath function. In Flex or AIR, you need a convoluted work around, such as a server side service or a desktop server piece like Merapi.

You can always ask me your question here, or stop by a Flextras Friday Lunch session and ask me in person.

What are the differences between OOP in Java vs OOP in ColdFusion?

The short answer to my subject's title is there are no differences between OOP in Java and OOP in ColdFusion. For a longer answer, and some background, we need to step back 12 short hours ago...

I saw a tweet roll by my twitter stream today right before I was leaving for the Hartford User Group meeting. I remember the tweet saying something about there needing to be a difference between Java-OOP and CF-OOP. I suspect this is the tweet, although I remember it slightly differently in my head:

CF-OOP ( "Not your JAVA's OOP" ) ... and that is good!

I translated that tweet to mean that there should be different versions of Object Oriented programming based on the language you are using.

For some reason, perhaps my imagination, it seems to me that every time SoSensible and I have twitter words they are slightly combative. I'm not sure if this is intentional or if we just like to disagree in 140 characters. I, perhaps foolishly responded like this.

@sosensible OOP is one approach to software architecture. It is language agnostic. If Java-OOP & CF-OOP are different, you're doing it wrong

The reason my response may have been foolish is that it is not sensible [no pun intended] to start religious wars and then run away. In my version of the world, my tweet makes perfect sense.

Object Oriented Programming is just one a way of approaching a problem we are trying to solve. Object Oriented Programming tries to mimic entities in the real world (Objects) and define their actions (methods) and interactions. An object oriented architecture should be completely language, or platform, independent because the way that real world entities interact with each other is completely independent of a specific computer language or platform.

Procedural programming on the other hand focuses on how the computer will compute tasks. The whole purposes is to break things up so that the computer will process the tasks and solve your problem in the most efficient way possible.

As a side note, computers are fast enough these days that I'd expect performance issues between an Object Oriented Designs and Procedural Designs to be negligible.

The difference between Object Oriented Programming and Procedural Programming is all about how you model your entities and how those entities interact with each other. In OOP you create objects, which represent real world entities and you focus on the actions (methods) that those real world entities perform. In Procedural Programming, you create Abstract Data Types, which is like your own data type and the functionality that operates on that data.

Feel free to take a moment to think about your own development. Are you focusing on mimicking the real world, or are you focused on modeling your data?

For all intents and purpose, Objects and Abstract Data Types are the same. The type of objects you decide to implement and the way that they interact together is what makes a design lean more towards OO or Procedural.

When I was in college, I seem to remember a lot of examples regarding flower shops, so let's assume you live in Connecticut and want to send flowers to a friend in Virginia.

In an OO Style Approach:

You call a CT flower shop and place your order. That CT flower shop processes the order by finding a Virginia Flower Shop and passes it the order. The Virginia Flower Shop processes the order by putting the flowers together and delivering them to your Virginia friend.

So, two different flower shops are handling order processing completely differently based on the flower destination.

In a Procedural Style Approach, this may happen:

You create the order and send it to Flower Shop Flower Shop, process the order by putting the flowers together and delivering them.

So, in this situation, you are creating the order; not passing the data to the Flower Shop. And the Flower shop just knows how to handle it.

Both approaches can use a relational database in the backend to store data; and he "processing" done at the database level will probably consist of modifying the stock count.

Before ColdFusion 6--AKA CFMX--ColdFusion did not provide a facility to create either Objects or Abstract Data Types. A lot of folks claim that development in CF5 or below was in the procedural style. In most cases, it wasn't. It used a top down approach with minimal thought to encapsulation. Yes it had custom tags and includes and eventually functions, but neither were used consistently. And there was no way to encapsulate data. This was a serious problem for anyone who wanted to implement procedural (or Object Oriented) architecture in their code. It just wasn't feasible.

I got two responses to my tweet. One from John

OOP means programing with objects. Are you saying that I should require strong typed CFC arguments or I am doing it wrong?

I don't fully understand John's rebuttal, probably because he didn't fully understand my original statement. I was speaking about design principles, and I believe he responded with implementation specifics. OOP means that you model the real world. That has nothing to do with strong or loose typing.

The best response I can give to John is that If you think you're Object architecture should be different based on the language you are using, then you aren't properly modeling your real world entities and how they interact with each other. Those objects and the interactions do not change with your language.

The other response I Got came from kylerow. Gotta love Twitter, I have no idea who Kyle Row is; I wasn't even following him before now. Maybe he is following me.

language devices make a difference how you do OOP - ex: C++'s multi-inheritance vs. C#/Java single-inheritance ..

Once again, I'd tell KyleRow that he is talking about implementation details. Your model of the real world needs to be independent of the implementation details. So, in C# / Java you use interfaces, whereas in C++ you use Multiple Inheritance. That's fine, but does not really change your underlying object design now how your real world objects interact with each other.

I know that OO and Frameworks have been a bit hotbed in the ColdFusion community lately. My preaching on this topic has come up a few times in the Flextras Friday Lunch.

I think the discussion of Object Oriented vs Procedural Design is a fascinating academic discussion. But, for all intents and purposes, it doesn't matter to us folks doing development on a daily basis. Most people are using a hybrid approach, at best, and calling it Object Oriented.

I believe the real secret to successful application development is to focus on encapsulating your code so that it can be reused easily. For some reason, the strategy pattern comes to mind. I once heard it described as "Separate out what changes from that which stays the same." That is a great, important, concept which has nothing to do with your approach to architecture.

So, where am I wrong? Be prepared to explain what piece of the real world system Data Transfer Objects and Table Gateways represent.

Maybe next I'll tackle methods that return nothing.

Flex and CF gave me this error: flex.data.adapters.ChangeObjectImpl / java.lang.NoClassDefFoundError

Over at Flextras.com I created an AutoCompleteComboBox Flex Component. One of the major benefits of the AutoCompleteComboBox over other options is the ability to pull data from a database. I have it working, it went through our beta testers, and was released over a month ago.

But, no demo for this functionality exists on the site, yet. How come? Because I couldn't get Flex Remoting to work with ColdFusion on the production site. Everything worked fine on my local dev box. Everything worked fie on my development / staging server. I kept getting this error when trying to do anything on the production box:


Message: flex.data.adapters.ChangeObjectImpl
Type: java.lang.NoClassDefFoundError

This error was being e-mailed to be via the error handler in the Application.cfc. There was also a stack trace as part of the error e-mail, along with other information such as session information and cgi variables. None of it was any help in diagnosing the error.

I believe this is what was happening:

  1. Flex App makes remote call
  2. ColdFusion throws error because it has no idea how to translate CFs array of CFCs into the Flash Player's array of AS Objects.
  3. Error handler e-mailed me the error. The error handler ran succesfully, but returns no value.
  4. Because the error was caught, The Flash Player sees that the remote call has run succesfully. It executes the result handler, with a null result.
But, I still had no idea what was causing the error. Googling around offered very little help. Looking at packets with ServiceCapture was no help. All it would tell me was that nothing was being returned from the method call. It was registering as a successful call, so the result handler was being fired not the fault handler.

After some trial and error I discovered a few things, in no particular order:

  • If the remote method returned a simple value, such as a string, it worked without an issue.
  • If the remote method returned a query object, it worked without an issue.
  • If the remote method returned a mapped object, it caused the "ChangeObjectImpl" "NoClassDefFoundError" error.

So, why was this error happening? After Googling some more, I came across this link. It appears that someone fixed a similar error by moving cfgatewayadapter.jar and concurrent.jar from flex/jars to Coldfusion/lib/ .

I let my host know; he move the files, restarted the server, and bam! Everything started working. Huh? Why? Does anyone have any idea? Why wasn't this stuff configured from the start? Why did moving these files address the issue?

I'm glad it's done and I can finally post up the sample for all to see. But, now I'm having issues with the case sensitivity of a CF Mapping. It was originally set up in all lower case, not mixed case like my dev machine. ColdFusion doesn't care, but Flex does. The host told me they changed the case on the server. I Restarted the machine. Remoting is st ill returning the CFC w/ the mapping in all lowercase. Any ideas on that one?

I know I've been light at blogging on this blog, and I apologize for that. Most of my "Creative" energies for blogging are being sapped by the Flextras Friday Lunch weekly Q&A session, The Flex Show, and creating demos for Flextras.

How do I pass data to a Remote Service?

This question came up twice on the same day; once via personal e-mail and once via the House of Fusion Flex list. The question, from the House of Fusion list is this:


How do I submit data to the ColdFusion component from the Flex interface?

Using RemoteObject in Flex, you can submit data like his:


RemoteObject.methodName(data);

Basically, you pass data to a remote method the same exact way you pass it to a local method. The same approach is used if you use the WebService or HTTPService objects.

Both people who asked this question were asking in relation to ColdFusion; however the same principles apply no matter what middleware you are using. From the perspective of Flex/Flash it's just a consistent interface for accessing remote services.

I love the questions that are easy to answer. Do you have one to ask me?

Running ColdFusion in the Cloud? I don't get it!

I started this a a response to a post on Sean Corfield's blog; but decided the topic was worthy enough to write my own post about.

I've heard people speak about wanting to run an application server in the cloud. I gotta admit; I just don't get it.

How would one run an application server in the cloud? Why would one want to run an application server in the cloud? Perhaps better a question is how do we define 'cloud'?

When we talk about storage in the cloud--such as Amazon.com S3--the files are still sitting on some storage device that is remote to me. I can use APIs or [more commonly I suspect] a program to access that data.

How exactly does an application server fit into that model? My web server is a physical machine somewhere on the west coast. It routinely backs itself up to the development server in my office; a physical machine on the east coast. Does that make my dev server a part of the cloud?

It seems to me that any instance of ColdFusion running a CFC w/ a remote method call could be construed as part of the cloud. But, that instance of CF is still running on some physical server somewhere. Why should this have/need different licensing rules?

Can someone enlighten me to what people want exactly? What exactly is the use case for something like this; and how is it different than the 'traditional' hosting model which includes renting server space?

Save 10% off a Flex Authority Subscription

You all knew I was the editor in chief of Flex Authority, right? Flex Authority is a quarterly Flex journal bringing you high quality content for Flex Programmers.

I pulled a few strings and eventually some gifts fell from the tree of plenty. I have a discount code that, if you subscribe, will get you a 10% off a magazine subscription. Each issue has around 14 articles, so that is like getting five articles a year completely free.

The discount code is:


FlexEditor.11.1

Subscribe today.

I'm told this coupon code should work for any order $49.95 or above; so if you wanted to buy Issue 1, plus a 4 issue subscription, you can do that and still receive 10% off the full order. If you want to combo up with a subscription to FAQU, you can do that too.

And for those that want to meet up with me in person, I will be at 360FlexCamp in New Jersey this Friday / Saturday. I have a discount code for that too, but you have to contact me directly.

Why won't Flex Remoting work with ColdFusion?

This question comes in from a reader:

I'm trying to become familiar with Flex remoting and tie to a CFC on the back end.

When I run the flex code and press the button I receive the following error: [RPC Fault faultString="[MessagingError message='Destination 'ColdFusion' either does not exist or the destination has no channels defined (and the application does not define any default channels.)']" faultCode="InvokeFailed" faultDetail="Couldn't establish a connection to 'ColdFusion'"]

I'm not quite sure what the problem is, it could be any number of things. Here are some things I suggested that he take a look a:

  • Services Config: Did he add the services-config file to your Flex Builder project as command line argument? Bring up project properties and select Flex Compiler. The argument should be something like this:


    -services c:/CFusionMX7/wwwroot/weborb30/WEB-INF/flex/services-config.xml

    If not, you'll want to add it.

  • Check Flex Remoting Setup: There could be a problem with the Flex Remoting setup. CAn you load localhost/flex2gateway? If you see a blank page, you're all set. If you see a 404 error, then that is the problem. Is Flash Remoting support enabled from the ColdFusion administrator? Check under Data and Services --> Flex Integration.
  • Code: Check your CFC code. Will it work locally, being invoked from a cfm template? Can you generate a WSDL by loading the CFC in the browser with a ?wsdl argument? Although when using Flash Remoting, the WSDL is not needed, loading the WSDL in the browser will make you aware of potential errors w/ remote access.
  • Paths: Check the case sensitivity of your paths. If the case is wrong, the Flash Player won't find the CFC.

I've run into all sorts of these problems when trying to get this stuff working the first time. However once I made it over that initial hump I never had to look back.

Hey, did you know over at The Flex Show we're giving away a Nintendo Wii Bundle? CT is in the middle of a heat wave, so I'm gonna get out of the non-air-conditioned office and try to find some cooler places to program at.

Why use WebORB?

This comes in from a reader Kai who asked why I use WebORB over the LCDS built with ColdFusion. This was Kai's question:


I am a long-term passive ColdFusion/onTap community member. Currently I try to figure out if to use WebORB, BlazeDS/LCDS or something else ... onTap does NOT run on BlueDragon so it will not be usable with WebORB, I guess ... My question is: - Do You prefer WebORB over LCDS and if yes, why ? - Is WebORB only recommendable for Flash/Flex clients, or for Ajax clients, too ? I know that LCDS comes with those Ajax Data Services and WebORB with the Rich Client System; both do NOT support Ajax as fully as Flash/Flex. Do You have an insight if using AMF for Ajax is advantageous at all ? Or if one is better off using a realtime data exchange engine (Comet) targeted at Ajax natively - like LightStreamer, for example ... If You can give some hints out of the top of Your head, that would be great :-)
Lots of stuff to cover in here, and he did ask for off the top of my head.

For those readers who don't know, when Kai says "onTap" I suspect he is referring to Isaac Dealey's onTap framework for ColdFusion. When he talks about BlueDragon, he is referring to the CFML server from New Atlanta. BlueDragon will be released open source under a dual licensing model. The latest release of WebORB supports CFC translation between BlueDragon and the Flash Player, a feature that exists natively in ColdFusion. You could use WebORB and BlueDragon as an alternative to CF and LiveCycle.

Do I prefer one over the other? No, I don't. I've use WebORB when dealing with .NET development and the CF Server (Which has LCDS under the hood) for dealing with web applications.

The benefit to AMF over XML is that the data passed back and forth is smaller, leading to less bandwidth and quicker load times. However,I haven't done any serious AJAX Development. I do know that WebORB has AJAX support. I was aware of AJAX Data Services, but never used that either. I am not aware of any AJAX AMF implementations, so I thought that both WebORB and AJAX Data Services used different protocols for non-Flash player communications.

In terms of Comet or Lightstreamer; I never heard of them before now so cannot comment. Anyone out there want to add their two cents?

A quick reminder to everyone, I love answering people's questions (even though I get busy sometime). Feel free to ask one!

Using ColdFusion to create an Encryption / Decryption Key from Plain Text

I have been doing work with Encrypting something in ColdFusion and decrypting it in ColdFusion. I've wrote about these experiments before. I've been trying to figure out the best way to create a key.

In ColdFusion I could easily use the GenerateSecretKey function. However, if I do that, how would I pass that key to Flex? It would have to be hard coded in some manner into the Flex Component that needed the encryption algorithm.

What I wanted was a way to generate the key on the fly. Flex and ColdFusion could both use the same algorithm for generating the key, and as long as I passed it appropriate parameters it would generate the same key, thus allowing Flex to decrypt something that was encrypted in ColdFusion.

So, how do you do it?

A 128 bit key is needed. This turns into 16 text characters. So, I started like this:


<cffunction name="generateEncryptionKey" access="private" output="true" returntype="string">
<cfset var HexKey = "">
<cfset var Filler = "abcdefghijklmnop">
<cfset var keyInText = "">

This is a function definition. It defines 3 local variables, one is HexKey. This will be the key, in hex, that we return from the function. The next variable is filler. If our algorithm generates a key that is less than 16 characters, we'll want to pad it. The final local variable is the keyInText. This will be the text representation of the key.


Write some algorithm to generate a key here.

It wouldn't be appropriate for me to share the algorithm we are using for key generation. But, the next chunk of code would generate it based on some factors that can be determined on the server in CF and on the Flex client.


<cfif len(keyInText) LT 16>
<cfset keyInText = keyInText & Filler>
</cfif>

<cfset keyInText = left(keyInText,16)>

IF the key is less than 16 characters, it adds in the filler. Then it truncates the key, removing all but the first 16 characters. We now have a 16 character key, no matter what the results of our "dynamically generate a key" algorithm.


<cfset HexKey = stringToHex(keyInText)>

Next we turn the text key into Hex. I'm using the stringToHex function from cflib to do this.


<cfreturn ToBase64(BinaryDecode(HexKey, "Hex"))>
</cffunction>
And finally, we decode the key, base64 it, and pass it out of the function, ready to be used with ColdFusion's Encrypt or Decrypt functions.

I'm undecided on the wisdom in an approach like this. When sharing between systems in the past, I have used a hard-coded key that was pre-generated for the purposes of sharing. Is a "semi-random" key generator more or less secure than a hard coded key that was randomly generated?

Discuss amongst yourselves!

More Entries

All Content Copyright 2005, 2006, 2007, 2008, 2009 Jeffry Houser. May not be reused without permission
BlogCFC was created by Raymond Camden. This blog is running version 5.9.2.002.