Mar
10

Have you ever wondered what specific version of ColdFusion you are using with your shared hosting provider? What about which edition - Standard or Enterprise? Perhaps you need a programmatic solution to retrieving ColdFusion datasources or scheduled tasks? Combining methods of ColdFusion's ServiceFactory with properties of the Server scope you can accomplish all of these tasks.

ColdFusion server info from the ServiceFactory

<cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")>

<cfoutput>
ColdFusion server info from the ServiceFactory:<br />
sf.LicenseService.getMajorVersion() = #sf.LicenseService.getMajorVersion()#<br />
sf.LicenseService.getEdition() = #sf.LicenseService.getEdition()#<br />
sf.LicenseService.isEnterprise() = #sf.LicenseService.isEnterprise()#<br />
sf.LicenseService.isStandard() = #sf.LicenseService.isStandard()#<br />
sf.LicenseService.isDeveloper() = #sf.LicenseService.isDeveloper()#<br />
sf.LicenseService.getOSPlatform() = #sf.LicenseService.getOSPlatform()#
</cfoutput>

In order to retrieve information from the ServiceFactory you must first create an instance of it. I prefer CF's CreateObject() function but you could also use the cfobject tag. With an instance of the ServiceFactory viewing various information about ColdFusion is simply a matter of calling functions and displaying their return values. The code above will display ColdFusion's major version number (6 or 7), the server edition (Standard or Enterprise typically), and the operating system platform. I also threw in a few booleans that display whether CF is the enterprise, standard, or developer edition. These are largely unnecessary if you use the getEdition() function, but I wanted folks to know they're available on ColdFusion 7 if you need them.

ColdFusion server info from the Server scope

ColdFusion server info from the Server scope:<br />
server.ColdFusion.AppServer = #server.ColdFusion.AppServer#<br />
server.ColdFusion.ProductName = #server.ColdFusion.ProductName#<br />
server.ColdFusion.ProductVersion = #server.ColdFusion.ProductVersion#<br />
server.ColdFusion.ProductLevel = #server.ColdFusion.ProductLevel#

With the Server scope you can retrieve the same info available through the ServiceFactory with the addition of the full ColdFusion product version (server.ColdFusion.ProductVersion). Other variables are available including the AppServer name (JRun for example), ProductName (ColdFusion Server), and ProduceLevel (Enterprise, Standard, etc.).

Operating System info from the Server scope

Operating System info from the Server scope:<br />
server.OS.Name = #server.OS.Name#<br />
server.OS.AdditionalInformation = #server.OS.AdditionalInformation#<br />
server.OS.Version = #server.OS.Version#<br />
server.OS.Arch = #server.OS.Arch#<br /><br/>

If you are interested in the operating system running your ColdFusion server take a peak at a few of the properties in the server.OS struct. Operating System name (Windows 2003 and Unix for example), version and architecture (i386 for Linux and x86 for Windows) are a few of the available properties. Another property, server.OS.AdditionalInformation has a value of Linux for Linux-based systems and is empty for Windows-based systems.

ColdFusion datasources

<cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")>

<cfdump var="#sf.DataSourceService.getDatasources()#" expand="true">

In order to view the datasources on a particular ColdFusion server you'll need an instance of the ServiceFactory. Then, you need only to call on the getDatasources() function in order to dump the datasources. You could also use a collection loop and loop over the result of the getDatasources() function. For each datasource returned, there's a wealth of information exposed including datasource name, driver and driver class, connection properties, username, password (not available in plain text for security reasons), and which privileges are activated (select, insert, update, delete, grant, drop, stored procedures, etc.)

ColdFusion scheduled tasks

<cfset sf = CreateObject("java", "coldfusion.server.ServiceFactory")>

<cfdump var="#sf.CronService.listAll()#" expand="true">

To retrieve and display a list of all the scheduled tasks, you employ the ServiceFactory only this time using a different object and methods of the object. The CronService's listAll() function returns an Array of all scheduled tasks. If you dump the Array, you'll be able to review the name of scheduled tasks, the scheduled interval, the start and finish date, the request timeout, and the URL the scheduled tasks calls.

One final word of warning: The ServiceFactory let's you access core areas of the ColdFusion server - you should be very careful when using it. It's always a good idea to test your work on a development server before you try your code in production.

Aaron West's Gravatar
About this post:

This entry was posted by Aaron West on March 10, 2007 at 10:33 AM. It was filed in the following categories: ColdFusion. It has been viewed 13781 times and has 0 comments.

0 Responses to Retrieving ColdFusion Server Info Using the ServiceFactory and Server Scope