
1268
DEVELOPING
COLDFUSION 9 APPLICATIONS
Using External Resources
Las
t
upda
te
d 8/5/2010
SendGatewayMessage(gatewayID, messageStruct)
•
The
gatewayID
parameter must be the gateway ID specified in the ColdFusion Administrator for the event gateway
instance that sends the message.
•
The
messageStruct
parameter is a structure whose contents depends on the requirements of the
outgoingMessage
method of the event gateway, and possibly the recipient application. For example, in addition to any message, the
structure could include a destination identifier.
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
1269.
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 could 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 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 (see “
Integrating J2EE and Java Elements in CFML Applications
” on page 1125). 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 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>
Using the event gateway error log file
When a standard ColdFusion event gateway encounters an error that does not prevent the event gateway from
continuing to process, it logs it to the eventgateway.log file in the ColdFusion logs directory. Other event gateways can
also to log information in this file, or to other application-specific files in the logs directory.
Содержание COLDFUSION 9
Страница 1: ...Developing Applications ADOBE COLDFUSION 9...