User Guide

Table Of Contents
1036 Chapter 42: Using Event Gateways
The CFEvent instance passed to the event gateway contains these two parameters in the
GatewayID and Data fields; the remaining fields are empty.
The following example sends a message to a logging CFC, which logs information to a file. If the
SendGatewayMessage function returns “OK”, the example code displays a message. The code
uses an instance of the asynchronous CFML event gateway named Asynch Logger. The props
variable used in the messageStruct parameter has two entries, the destination file and the message
to log.
<cfscript>
status = "No";
props = structNew();
props.Message = "Replace me with a variable with data to log";
status = SendGatewayMessage("Asynch Logger", props);
if (status IS "OK") WriteOutput("Event Message ""#props.Message#"" has been
sent.");
</cfscript>
Note: To see the code for the CFC that logs the information, see “Using the CFML event gateway for
asynchronous CFCs” on page 1038.
Using the GatewayHelper object
The ColdFusion
GetGatewayHelper function tells ColdFusion to create and initialize a Java
GatewayHelper object that provides event gateway-specific helper methods and properties. To use
this function, the event gateway must implement a GatewayHelper class. For example, an instant
messaging event gateway might make buddy list management methods available in a
GatewayHelper object.
The ColdFusion
GetGatewayHelper function takes a single parameter, the ID of the event
gateway instance that provides the helper, and returns a GatewayHelper Java object. The
parameter value must be the gateway ID for the instance that is specified in the ColdFusion MX
Administrator. If you do not want to hard-code an ID value in the application (for example, if
your listener CFC can respond to multiple event gateway instances), get the gateway ID from the
CFEvent structure of the first incoming message.
The CFML code accesses the GatewayHelper object’s methods and properties using standard
ColdFusion Java object access techniques, as described in Chapter 37, “Integrating J2EE and Java
Elements in CFML Applications,” on page 917. For example, if an event gateway’s
GatewayHelper class includes an
addBuddy method that takes a single String parameter, you
could use the following code to get the ColdFusion MX XMPP or Sametime gateway
GatewayHelper object and add a buddy to the buddies list:
<cfscript>
myHelper = GetGatewayHelper(myGatewayID);
status = myHelper.addBuddy("jsmith23", "Jim Smith", "support");
</cfscript>