User Guide

Table Of Contents
1034 Chapter 42: Using Event Gateways
You can simulate responses from CFCs to the event gateway by using the
SendGatewayMessage function in a CFM page. The functions message parameter should
contain the information that the CFC would put in its return variable.
If you run ColdFusion MX 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 make changes to a CFC.
ColdFusion MX 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
(listgetat(message,1) IS "C") OR
(listgetat(message,1) IS "Celsius")>
<cfset scale=listgetat(message,1)>
<cfif isNumeric(listgetat(message,2))>
<cfset temperature=listgetat(message,2)>
<cfswitch expression="#scale#">
<cfcase value="F, Fahrenheit">
<cfset retmsg = temperature & " degrees Fahrenheit is "