
1263
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
•
By calling the ColdFusion
SendGatewayMessage
function
The first method is useful to automatically respond to incoming messages. Some complex applications that respond
to incoming messages could use the
SendGatewayMessage
function either in place or in addition to the return value.
Some event gateway types also use a GatewayHelper object to send information to external resources. For example, the
ColdFusion XMPP and Lotus Sametime instant messaging event gateways provide a GatewayHelper object that can
manage buddy lists, and set configuration and status information on the instant messaging server. For more
information on the GatewayHelper object, see “
Using the GatewayHelper object
” on page 1268. For more information
on the instant messaging GatewayHelper object, see “
Sample IM message handling application
” on page 1282.
The example code in “
Example event gateway CFC
” on page 1266 shows the use of a listener return value, and indicates
how event gateways can require different data in the return structure to send equivalent messages.
Developing event gateway listener CFCs
The listener CFC responds to event gateway messages. The listener CFC uses, at a minimum, the following basic
software elements:
•
One or more listener methods
•
CFEvent structures that contain the messages
Listener CFCs can use ColdFusion persistent scopes to store data that must be preserved over multiple CFC
invocations or shared with other CFML elements.
Listener methods
The ColdFusion event gateway service calls one or more listener methods in the CFC to process incoming messages.
The number of listener methods that you must write and their names depends on the event gateway. For example, the
ColdFusion SMS event gateway requires a single listener method, which is typically named
onIncomingMessage
. (You
can change the SMS event gateway listener method name in the event gateway configuration file.) The ColdFusion
XMPP IM event gateway expects the listener CFC to have five methods:
onIncomingMessage
,
onAddBuddyRequest
,
onAddBuddyResponse
,
onBuddyStatus
, and
onIMServerMessage
. By default, if the event gateway does not specify
the method name, ColdFusion calls the
onIncomingMessage
method of the listener CFC. For the sake of consistency,
Adobe recommends you to use the
onIncomingMessage
method for any event gateway with a single listener method.
The listener method does the following:
1
Takes a single parameter, a CFEvent structure.
2
Processes the contents of the instance as required by the application.
3
Optionally, returns an outgoing message to the event gateway in a
cfreturn
tag. It can also send a message back
to the event gateway by calling the ColdFusion
SendGatewayMessage
function.
The following code shows a listener CFC with an
onIncomingMessage
method that echoes a message back to the
Socket event gateway that sent it. It contains the minimum code required to process an incoming message and respond
to the sender using the socket gateway.