Sunday, May 22, 2011

Debugging JSON Proxy / ColdBox with ColdFire

It's late and time is short, so let's get right to it. You have a ColdBox application. You're using a JSON Proxy to marshal your objects into the model. You need to be able to debug / trace access to the CFCs under the hood, since the context of the debugging is within the XHR, and not the page itself. You also love Firebug, and want to take advantage of that.

Let's begin. Bear with me as I'm not nearly as organized as Ray or Ben. I'll assume you already have Firebug installed, and I'll assume you have a ColdBox project you're working with, one that presumably implements the JSON Proxy.

Step 1: Download Nathan Mische's ColdFire addon from RIAForge. Install.

Step 2: Open up your ColdBox app, go to your /interceptors directory. Create a new file called 'coldfire.cfc' in that directory.

Step 3: Find the file in the ColdFire addon archive named ColdFireAdvice.cfc (in /coldfusion/coldspring). This is an Advisor for ColdSpring that ColdFire relies on. ColdSpring, of course, is an AOP-based framework, utilizing dependency injection as a way to wire objects together. Guess what else uses dependency injection? If you guessed ColdBox, you are allowed to read on.

Step 4: Copy the contents of the ColdFireAdvice.cfc and paste it into your /interceptors/coldfire.cfc file.

Step 5: Change the <cfcomponent> so that it extends 'coldbox.system.interceptor', instead of 'coldspring.aop.AfterReturningAdvice'.

Step 6: Change the first <cffunction> so that it is named 'postEvent', rather than 'afterReturning'. Delete the four arguments; returnVal, method, args, and target...should now all be gone. Your final updated <cffunction> should have no <cfargument> calls.

Step 7: Open up your coldbox.xml.cfm config file, scroll down to the <interceptors> and add a new interceptor declaration:

<!-- COLDFIRE TRACING -->
<Interceptor class="interceptors.coldfire"/>

Step 8: Be sure that your CFAdmin debugger is set to "coldfire" and that you have put the appropriate "trace.cfm" in your ColdFusion server's /debug folder (You *did* perform the ColdFire installation up above, right?). Put in a few <cftrace> calls in your model CFC files--you know, the ones that you proxy through your JSON Proxy CFC.

Step 9: Flip over to Firebug, Click on the ColdFusion tab, choose the appropriate jsonProxy.cfc call from the call list (it's a clickable drop-down menu to the right of 'Variables'; all of the individual XHR calls will be selectable). Be sure the "Traces" filter is chosen. Voila! JSON Proxy debugging in ColdFire.





0 comments: