
1266
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
Debugging event gateway CFCs
When an event gateway CFC responds to an event, it cannot display debugging information in the response page, as
CFM pages do. As a result, many of the normal ColdFusion debugging techniques, including the
cfdump
tag, are not
available. When you develop event gateway CFCs, consider the following debugging techniques:
•
Place trace variables in the Application scope. These variables persist, and you can specify an application name for
your CFC (see “
Application scope
” on page 1265). You can inspect the Application scope contents, including your
trace variables, in any CFML page that has the same application name as your CFC.
•
Use
cflog
tags to help you trace any errors by logging significant events to a file. Also, carefully inspect the
eventgateway.log and exceptions.log files that ColdFusion maintains. For more information on using the
eventgateway.log file, see “
The eventgateway.log file
” on page 1260.
•
You can simulate responses from CFCs to the event gateway by using the
SendGatewayMessage
function in a CFM
page. The function’s
message
parameter should contain the information that the CFC would place in its return
variable.
•
If you run ColdFusion from the command line, you can use the Java
System.out.println
method to write
messages to the console window, as the following code shows:
<cfscript>
sys = createObject("java", "java.lang.System");
sys.out.println("Debugging message goes here");
</cfscript>
Note:
You do not have to restart the event gateway instance when you change a CFC. ColdFusion automatically uses the
updated CFC when the next event occurs.
Example event gateway CFC
The following code shows a temperature scale converter tool that can work with any of several event gateways: SMS,
XMPP, Lotus Sametime, or the example Socket event gateway. Users enter a string that consists of the temperature
scale (F, Fahrenheit, C, or Celsius), a comma, and a temperature on their device. The CFC converts Celsius to
Fahrenheit or Fahrenheit to Celsius, and returns the result.
This example shows how a responder event gateway application can work, and illustrates how different event gateway
types require different outgoing message formats:
<cfcomponent displayname="tempconverter" hint="Convert temperatures between
Celsius and Fahrenheit">
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<!--- Standard error message giving the correct input format. --->
<cfset var errormsg = "Please enter scale, integer where scale is F or C,
for example:F, 32">
<!--- Get the message. --->
<cfset data=cfevent.DATA>
<cfset message="#data.message#">
<!--- Where did it come from? --->
<cfset orig="#CFEvent.originatorID#">
<!--- Process the input, generate a message with the new temperature. --->
<!--- Input format is: degrees, temperature. --->
<cfif listlen(message) eq 2>
<cfif (listgetat(message,1) IS "F") OR
(listgetat(message,1) IS "Fahrenheit") OR