Using CFMX 6.1 datasources from Java code

Some of the changes in CFMX 6.1 had the unfortunate side-effect of no longer enabling access to CF datasources through JNDI. The official solution to this is to use CFMX 4 J2EE and set up datasources through the underlying J2EE server.

Turns out this drastic change is not absolutely necessary. fozizzle posted a code snippet in the web forums that retrieves a CFMX 6.1 datasource from Java.

public static Connection getUsingCFService(String datasource) {
DataSourceService ds =
coldfusion.server.ServiceFactory.getDataSourceService();
try {
return ds.getDatasource(datasource).getConnection();
} catch (SQLException e) {
throw new RuntimeException(e);
}
}

Nice find!

Picked up from Macromedia webforums.

Undocumented Application scope functions

I stumbled across four useful functions that exist in the Application scope.

getMaxInactiveInterval = #application.getMaxInactiveInterval()#
getElapsedTime = #application.getElapsedTime()#
getTimeSinceLastAccess = #application.getTimeSinceLastAccess()#
expired = #application.expired()#

UPDATE. These four functions also work on the Session scope.

They’re undocumented so they may not exist or be accessible in a future version, but there’s no security risk with them so they’re not very likely to change.

getMaxInactiveInterval() returns the timeout set for the current application. If you want the server default timeout you can grab it from the runtime service.

Continue reading

Write CFX tags in any .NET language

Montara Software announced a very promising new product called Black Knight that enables developers to write ColdFusion custom tags in any .NET language. The software is a re-implementation of the existing CFX API with native .NET code and thus allows direct communication between CF and .NET without a COM wrapper or a Web Service. This direct communication should provide a much smoother and hassle-free programming experience and improved run-time performance.

The product falls just slightly short of full .NET integration but it is a huge leap forward. While it allows direct communications it does not enable CF developers to use existing .NET assemblies–you, or someone, must write a .NET CFX wrapper. It may be possible to write a relatively generic wrapper that can be used for many assemblies so the possibilities are certailny far reaching.

Black Knight works with CF4, 5, and MX servers as well as Blue Dragon.

It’s great that third party products enable this integration, but it would be even better if this and even tighter integration were possible with CFMX out of the box. Black Knight shows that CFX tags can be written for CF in .NET languages and Blue Dragon shows that even a full CFML engine can be implemented in .NET. Hopefully a future version of CFMX will include much more .NET integration without relying on inefficient Web Services or soon-to-be-outdated technologies (COM). If you agree, tell Macromedia.