Debugging CFML Applications for Event Gateways


When you need to develop ColdFusion applications that use event gateways, you need to be particularly carefulCFCs that are responding to events work differently than when they are responding to a normal page request. If an event gateway triggers a CFC and that CFC throws an error, the event gateway continues to function without pause and does not display any sort of debugging information back to you. For this reason, you'll need to follow some different development paradigmsespecially with regard to debugging, so that you can make sure your CFCs and event gateways are functioning as expected. In this section we'll examine some techniques you can and should use to help you debug and write better code.

The first technique is to make extensive use of CFTRY, CFCATCH, and CFLOG. Keep in mind that CFCs called by the event gateway will fail, but the event gateway will continue processing requests without returning anything to you. Catching any exceptions in your CFML and dumping them to a specific file will allow you to much more easily debug your applications.

You can also use CFDUMP in your application code and write the output of CFDUMP to a file. An easy way to do this is to use CFSAVECONTENT to wrap things like CFDUMP, loop over stack traces and so forth, and then put the CFSAVECONTENT variable in the text="" attribute of the cflog file.

TIP

Using these techniques in Listings 31.2 and 31.3 to log and trap error information from your Gateway applications is an excellent way to add debugging/logging to your event gateway applications.


Something else you can do is to put debugging and tracking variables in your Application scope. Then you can dump the contents of the scope and see any information about what you are tracking.

Another major debugging approach that should always be part of any developmentbut especially with CFCs and CFML applications that use gatewaysis creating unit tests. You can easily do this by creating simple CFML pages that use the SendGateWayMessage function to simulate a message from a CFC to the event gateway. We will discuss this shortly, in the section "Creating Your Own Custom Gateways," as well as how to call those pages.

Finally, consider running the ColdFusion MX 7 server from the command line. If you do this, you can use Java System.out.println to dump error message information to your DOS or command shell. This technique is really useful when working with Java objects from ColdFusion MX 7. Simply add into your code something like this:

 <cfscript>     sys = createObject("java", "java.lang.System");     sys.out.println("Debugging message goes here"); </cfscript> 



Advanced Macromedia ColdFusion MX 7 Application Development
Advanced Macromedia ColdFusion MX 7 Application Development
ISBN: 0321292693
EAN: 2147483647
Year: 2006
Pages: 240
Authors: Ben Forta, et al

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net