Macromedia breeze-using the breeze xml web services User Manual

Page of 196
Integrating Breeze with a directory service
29
To synchronize Breeze with the directory service:
1.
Log in by calling the 
 action on the Breeze server, specifying the login name and password 
of an account administrator. Examine the returned HTTP headers to find the value of the 
BREEZESESSION cookie, which you need when calling subsequent actions.
Note: Consider creating an administrative user specifically for performing synchronizations. If you 
create such a user, you should exclude it from the list of users to synchronize when you perform the 
synchronization. 
The following code example logs in a user and obtains the cookie value:
<cfset login="john@example.com">
<cfset password="abcdefg">
<cfset accesskey="0123456789101112">
<cfset baseurl="http://breeze.example.com/">
<cfset params="accesskey=#accesskey#&action=login&login=#login#&password=
#password#">
<cfhttp url="#baseurl#api/xml?#params#" method="get">
<cfset loginHeaders= "#cfhttp.ResponseHeader#" />
<cfloop collection="#loginHeaders#" item="httpHeader">
<cfif httpHeader eq "Set-Cookie">
<cfset value= loginHeaders[httpHeader] />
<cfset cookieHeader="#value[1]#" />
<cfloop list="#cookieHeader#" index="c" delimiters=";">
<cfset cookieName= Left(c, Find('=', c)-1) />
<cfif cookieName eq "BREEZESESSION">
<cfset fullCookie= mid(c, len(cookieName)+2,
len(c)-len(cookieName)+1) />
<cfset loginCookie= Left(fullCookie, Find('.', fullCookie)-1) />
</cfif>
</cfloop>
</cfif>
</cfloop>
2.
Check that the 
login
 action completed successfully by parsing the returned XML and 
examining the value of the 
 tag’s 
code
 attribute. If the status code isn’t 
"ok"
, determine 
what the error was and handle it appropriately. 
<cfset xml= XmlParse(cfhttp.FileContent)>
<cfset resultsElement= XmlSearch(xml, "//status[@code='ok']")>
<cfif ArrayLen(resultsElement) ne 1>
<!--- No status code "ok" found. Check for other status codes and handle 
errors. --->
</cfif>