ColdFusion 9.0 Resources |
Approaches to debugging Java CFX tagsJava CFX tags are not stand-alone applications that run in their own process, like typical Java applications. Rather, they are created and run from an existing process. As a result, debugging Java CFX tags is more difficult, because you cannot use an interactive debugger to debug Java classes that another process has loaded. To overcome this limitation, you can use one of the following techniques:
Outputting debugging informationBefore using interactive debuggers became the norm, programmers typically debugged their programs by inserting output statements in their programs to indicate information such as variable values and control paths taken. Often, when a new platform emerges, this technique comes back into vogue while programmers wait for more sophisticated debugging technology to develop for the platform. If you must debug a Java CFX tag while running against a live production server, reset this technique. In addition to outputting debugging text using the Response.write method, you can also call your Java CFX tag with the debug="On" attribute. This attribute flags the CFX tag that the request is running in debug mode and therefore can generate additional extended debugging information. For example, to call the HelloColdFusion CFX tag in debugging mode, use the following CFML code: <cfx_HelloColdFusion name="Robert" debug="On"> To determine whether a CFX tag is run with the debug attribute, use the Request.debug method. To write debugging output in a special debugging block after the tag finishes executing, use the Response.writeDebug method. For information on using these methods, see ColdFusion Java CFX Reference in CFML Reference. Debugging in a Java IDEYou can use a Java IDE to debug your Java CFX tags. As a result, you can develop your Java CFX tag and debug it in a single environment.
Using the debugging classesTo develop and debug Java CFX tags in isolation from the ColdFusion, you use three special debugging classes that are included in the com.allaire.cfx package. These classes lets you simulate a call to the processRequest method of your CFX tag within the context of the interactive debugger of a Java development environment. The three debugging classes are the following:
Implement a main method
After you implement a main method as described previously, you can debug your Java CFX tag using an interactive, single-step debugger. Specify your Java CFX class as the main class, set breakpoints as appropriate, and begin debugging. Example:debugging classesThe following example demonstrates how to use the debugging classes: import java.util.Hashtable ; import com.allaire.cfx.* ; public class OutputQuery implements CustomTag { // debugger testbed for OutputQuery public static void main(String[] argv) { try { // initialize attributes Hashtable attributes = new Hashtable() ; attributes.put( "HEADER", "Yes" ) ; attributes.put( "BORDER", "3" ) ; // initialize query String[] columns = { "FIRSTNAME", "LASTNAME", "TITLE" } ; String[][] data = { { "Stephen", "Cheng", "Vice President" }, { "Joe", "Berrey", "Intern" }, { "Adam", "Lipinski", "Director" }, { "Lynne", "Teague", "Developer" } }; DebugQuery query = new DebugQuery( "Employees", columns, data ) ; // create tag, process debugging request, and print results OutputQuery tag = new OutputQuery() ; DebugRequest request = new DebugRequest( attributes, query ) ; DebugResponse response = new DebugResponse() ; tag.processRequest( request, response ) ; response.printResults() ; } catch( Throwable e ) { e.printStackTrace() ; } } public void processRequest(Request request, Response response) throws Exception { // ...code for processing the request... } } |