User Guide

Table Of Contents
1092 Chapter 45: Creating Custom Event Gateways
Building an event gateway
This section describes how to build an event gateway. To build a Gateway class, you can start with
the EmptyGateway.java file as a template. (In the server configuration, this file is located in the
cf_root/gateway/src/examples/ directory; in the J2EE configuration, the file is in the cf_root/WEB-
INF/cfusion/gateway/src/examples/ directory.) This file defines a nonfunctional event gateway,
but has the basic skeleton code for all Gateway class methods.
Wherever possible, the following sections use code based on the sample Socket event gateway to
show how to implement event gateway features. (In the server configuration, this file is cf_root/
gateway/src/examples/socket/SocketGateway.java; in the J2EE configuration, the file is cf_root/
WEB-INF/cfusion/gateway/src/examples/socket/SocketGateway.java.)
Class constructor
An event gateway can implement any of the following constructors:
MyGateway(String gatewayID, String configurationFile)
MyGateway(String gatewayID)
MyGateway()
When ColdFusion MX starts, it calls the constructor for each event gateway instance that you
configure in ColdFusion MX. (ColdFusion also calls the gateway
Start method after the event
gateway is instantiated.). ColdFusion first attempts to use the two-parameter constructor.
Because each event gateway instance must have a unique ID, ColdFusion provides redundant
support for providing the ID. If the event gateway implements only the default constructor,
ColdFusion provides the ID by calling the event gateways
setGatewayID method.
If the event gateway does not implement the two-parameter constructor, it does not get
configuration file information from ColdFusion.
The constructor normally calls the static
GatewayServices.getGatewayServices method to
access ColdFusion event gateway services. Although you need not do this, it is a good coding
practice.
A minimal constructor that takes only a gateway ID might look like the following:
public MyGateway(String gatewayID) {
this.gatewayID = gatewayID;
this.gatewayService = GatewayServices.getGatewayServices();
}
The gateway constructor must throw a coldfusion.server.ServiceRuntimeException exception if
there is an error that otherwise cannot be handled. For example, you should throw this exception
if the event gateway requires a configuration file and cannot read the file contents.
If your gateway uses a configuration file, the constructor should load the file, even if the
Start
method also loads the file. You should do this because the constructor does not run in an
independent thread, and ColdFusion can display an error in the ColdFusion MX Administrator
of the file fails to load. If the
Start method, which does run in a separate thread, fails to load the
file, ColdFusion logs the error, but it cannot provide immediate feedback in the administrator.