Site Contents
Home
My Blog
ColdFusion
JRun
Flex
Wireless & Networking
Hardware & Gadgets
HDTV
Software Picks
Pictures
Contact Me
Search


My Articles & Papers
Flex Performance
Server/Client
mm.com Under the Hood
Multiple Instances of CFMX
Multiple Instance Config
NLB with ColdFusion
Clustering CFMX for J2EE
Multi-Tier Hardware LB w CFMX
Cisco CSS & Coldfusion MX
JRun 4 Jini based Clustering
WiFi Growth

2ID Tacweb

Other Hobbys
Body-For-Life Challenge

Personal Projects
Family Pool
Deck Gate

username:
password:
 

 
GoogleTalk via ColdFusion MX 7 XMPP gateway

This is from Peter Reese in ColdFusion support and I thought I would share his experience.

I attended a Ben Forta presentation discussing CFMX 7 event gateways.  I found for the most part it was information that was covered in the event gateways brown bag last year before CFMX 7 came out.  However, one point I found interesting and can share was that we now have available an open IM network that we can utilize XMPP on – Google Talk.  XMPP is one of the default gateways that ship with CFMX 7. 

It seems this has been a trendy thing to play with recently.  Here is Damon Cooper’s blog discussing his tests:

http://www.dcooper.org/blog//client/index.cfm?mode=entry&entry=F40021C0-4E22-1671-57C5B573FC438CC9

So I created a couple Google Talk http://www.google.com/talk accounts and started playing with the gateway to get them talking.  I needed to provide a cell phone number that can accept SMS messages to create the gmail accounts to use with Google talk.  Luckily I had my phone as well as my wife’s to set two accounts up.

It was pretty easy to get going.  It took maybe an hour.  It’s a great way to get into using event gateways if you haven’t tried setting one up. 

I utilized the basic “echo” application to run a hello world type test.

First, I needed to create an event gateway.  I went into the CF Admin and under “Event Gateways” and “Gateway Instances” I chose “Add” and entered the following values:

Gateway ID: GoogleTalk
Gateway Type: XMPP – XMPP Gateway
CFC Path: {cf.rootdir}/gateway/cfc/examples/echo.cfc
Configuration File: {cf.rootdir}/gateway/config/xmpp.cfg

Then, I had to set up a few files before the gateway instance would start.  The echo.cfc and xmpp.cfg existed, but needed to be modified slightly to work with Google Talk.

Resources I used to determine the correct values and other information are in these pages:

Livedocs for onAddBuddyRequest – stole this code to set up the echo.cfc to allow the add buddy request

http://livedocs.macromedia.com/coldfusion/7/htmldocs/00000747.htm

Google Talk for developers FAQ – helps with settings in XMPP.cfg

http://www.google.com/talk/developer.html

Here are the modified files:

-------------------xmpp.cfg-----------
#
# XMPP Instant Message Configuration file
#
# This is the XMPP Instant Message Server username to be used by the Gateway
# e.g. someone@jabber.org
userid=brakbot@gmail.com #enter your gmail account here - pete

# This is the password for the above username
password=password #enter your gmail password here - pete

# This is the resouceName used to identify your loggin instance
resourceName=ColdFusion
#
# Optional settings
# secureprotocol = TSL or SSL
# if SSL specified, use must specify ip and port of secure server
#
# securerequirement = true or false
# whether a secure connection to the server is required. If server
# connection will only succeed if a secure connection was
# successfully established.
secureprotocol=TSL
securerequirement=true
# Specify Server and Port settings to overwrite
# See {cf.root}/gateway/lib/JABBER.properties to check default settings
#
# if secureprotcol is specify as SSL then serverip and port need to be specified
# secure port use to be 5223
#
serverip=talk.google.com
serverport=5222
# This is how many times you would like to retry to
# connect to the XMPP server if the Gateway gets disconnected
# or on startup. 0 means not to retry, -1 means try forever.
# The default is -1 (forever)
#retries=-1
# This is the number of seconds to wait between connection
# attempts.  The minimum is 1 second.
# The default is 5 seconds.
#retryinterval=5
# Default method names, if they are not specified, we use default
# If they specified, then we use their name as CFC method names
# If the value is an empty string such as 'onBuddyStatusFunction='
# then it means we don't send this type of event in IM Gateway
#
onIncomingMessageFunction=onIncomingMessage
onAddBuddyRequestFunction=onAddBuddyRequest
onAddBuddyResponseFunction=onAddBuddyResponse
onBuddyStatusFunction=onBuddyStatus
onIMServerMessageFunction=onIMServerMessage

--------------------/xmpp.cfg-----------
Plenty of unnecessary code in the echo.cfc below.  I just wanted to get it working.  It accepts all requests.
-------------echo.cfc-----------

<cfcomponent displayname="echo" hint="Process events from the test gateway and return echo">
<cffunction name="onIncomingMessage" output="no">
<cfargument name="CFEvent" type="struct" required="yes">
<!--- Get the message --->
<cfset data=cfevent.DATA>
<cfset message="#data.message#">
<!--- where did it come from? --->
<cfset orig="#CFEvent.originatorID#">
<cfset retValue = structNew()>
<cfif listcontains("XMPP,SAMETIME,YIM,AIM,MSN,ICQ,JSC", arguments.CFEVENT.GatewayType) gt 0>
<!--- gateway types YIM, AIM, MSN, ICQ and JSC are supported by JBuddy-CF --->
<cfset retValue.BuddyID = orig>
<cfset retValue.MESSAGE = "echo: " & message>
<cfelseif arguments.CFEVENT.GatewayType is "Socket">
<cfset retValue.originatorID = orig>
<cfset retValue.message = "echo: " & message>
<cfelseif arguments.cfevent.gatewaytype is "SMS">
<cfset retValue.command = "submit">
<cfset retValue.sourceAddress = arguments.CFEVENT.GatewayID>
<cfset retValue.destAddress = orig>
<cfset retValue.shortMessage = "echo: " & message>
</cfif>
<!--- send the return message back --->
<cfreturn retValue>
</cffunction>
<cffunction name="onAddBuddyRequest">
<cfargument name="CFEvent" type="struct" required="YES">
<cflock scope="APPLICATION" timeout="10" type="EXCLUSIVE">
<cfscript>
	// If the name is in the DB once, accept; if it is missing, decline.
	// If it is in the DB multiple times, take no action.
action="accept";
reason="Valid ID";
	//Add the buddy to the buddy status structure only if accepted.
if (NOT StructKeyExists(Application,"buddyStatus")) {
Application.buddyStatus=StructNew();
}
if (NOT StructKeyExists(Application.buddyStatus,
CFEvent.Data.SENDER)) {
Application.buddyStatus[#CFEvent.Data.SENDER#]=StructNew();
}
Application.buddyStatus[#CFEvent.Data.SENDER#].status="Accepted Buddy Request";
Application.buddyStatus[#CFEvent.Data.SENDER#].timeStamp=
CFEvent.Data.TIMESTAMP;
Application.buddyStatus[#CFEvent.Data.SENDER#].message=CFEvent.Data.MESSAGE;
</cfscript>
</cflock>
<!--- Log the request and decision information. --->
<cflog file="#CFEvent.GatewayID#Status" text="onAddBuddyRequest; SENDER: #CFEvent.Data.SENDER# MESSAGE:
#CFEvent.Data.MESSAGE# TIMESTAMP: #CFEvent.Data.TIMESTAMP# ACTION: #action#">
<!--- Return the action decision. --->
<cfset retValue = structNew()>
<cfset retValue.command = action>
<cfset retValue.BuddyID = CFEvent.DATA.SENDER>
<cfset retValue.Reason = reason>
<cfreturn retValue> 
</cffunction>
<cffunction name="onAddBuddyResponse">
</cffunction>
<cffunction name="onBuddyStatus">
</cffunction>
<cffunction name="onIMServerMessage">
</cffunction>
</cfcomponent>

-------------/echo.cfc-----------

I also had to add an Application.cfm in the {cfroot}/gateway/cfc/examples/ directory to use the application scope in echo.cfc.  Nothing tricky here:

-------------Application.cfm-----------

<cfapplication name="testXMPP" sessionmanagement="Yes" 
setclientcookies="Yes" sessiontimeout="#CreateTimeSpan(0,1,0,0)#" >

-------------/Application.cfm-----------

 

Once these files are in place, I started the event gateway as well as the Google Talk client on my machine.  I added my machine as a buddy and it worked! 

I found a new log file created by echo.cfc.  In there was this entry:

"Information","Thread-19","09/13/05","01:59:05","TESTXMPP","onAddBuddyRequest; SENDER: peter.reese@gmail.com MESSAGE: Requesting authorization to add 'brakbot@gmail.com' to 'peter.reese@gmail.com'  buddy list and view 'brakbot@gmail.com' presence. TIMESTAMP: {ts '2005-09-13 01:59:05'} ACTION: accept"

There was a lot more trial and error than I’m describing here, but this *hopefully* will work for you right away!

If you run into problems, places to look for issues are in the eventgateway.log and as always, the exception.log.

Good Luck!

Pete