Some more differences when moving to Railo

by kai on 14/05/2013

You might remember that I’ve blogged about the differences between Railo and ColdFusion in the past. Here’s another one to look out for – this popped up on the railo mailing list the other day.

A poster was asking about some Adobe CF-specific code that was used to retrieve a list of datasources (working on Adobe CFMX 6.1):

<cfset var dsService = CreateObject("java", "coldfusion.server.ServiceFactory").DataSourceService />
<cfset var sDatasources = dsService.getDatasources() />

The question was: How do you make this work on Railo? The direct and short answer is: you can’t (at least not directly). The above code is essentially using a kind-of undocumented feature in Adobe ColdFusion that’s provided through an internal, but exposed Java class called coldfusion.server.ServiceFactory. I’ve blogged about similar issues in the past.

What’s the problem with this? This class being exposed unofficially, it’s nothing one can rely on. You might say: “But this has been working in Adobe Cold Fusion since version {6|7|8|…}”, and you’re right. It has. But it might not work in Adobe ColdFusion 10.something or 11 or 12 etc. I guess you get the idea here. Relying on those kinds of features might be fine for a while but it’s not ok doing so in general and the grand scheme of things. It can be taken away from you within the few seconds it takes to install a security hotfix… cough… cough, let’s not go there maybe… 🙂

For this specific issue – retrieving the datasources – there’s a built-in solution: <cfadmin> with action=”getDatasources” will do the trick nicely. If one was trying to write a codebase that works across Railo and Adobe ColdFusion, this would most likely require conditional coding though.

Comments on this entry are closed.

Previous post:

Next post: