Blog   About   Contact

ColdBoxProxy and JSON

If you work a lot with JSON and remote calls like me, the following coldboxproxy.cfc code could be handy for you.

<cfcomponent name="coldboxproxy" output="false" extends="coldbox.system.extras.ColdboxProxy">

    <cffunction name="process" output="true" access="remote" returntype="any" hint="Process a remote call and return data/objects back.">
        <cfset var results = "">

            <cftry>
                <!--- Call the actual proxy --->
                <cfset results = super.process(argumentCollection=arguments)>
        
                <!--- JSON ? --->
                <cfif isDefined('arguments.json')>
                    <cfheader name="expires" value="Mon, 03 Sep 1973 00:00:01 GMT">
                    <cfheader name="pragma" value="no-cache">
                    <cfheader name="cache-control" value="no-cache">
                    <cfcontent type="text/html">
                    #getPlugin("JSON").encode(data:results,queryKeyCase:"upper")#     
                <cfelse>
                    <cfreturn results>
                </cfif>

                <cfcatch type="any">#processException(cfcatch)#</cfcatch>
            </cftry>

    </cffunction>
    
    <cffunction name="processException" output="false" access="private" returntype="string" hint="Process exception and returns bugReport">
        <cfargument name="Exception" type="any" required="true" hint="The exception structure (cfcatch)">
        
        <cfset var exceptionService = "">
        <cfset var ExceptionBean = "">        
        <cfset var interceptData = StructNew()>        
        
        <!--- Get Exception Service --->
        <cfset ExceptionService = getController().getExceptionService()>
        
        <!--- Intercept The Exception --->
        <cfset interceptData.exception = arguments.exception>
        <cfset announceInterception('onException',interceptData)>
        
        <!--- Handle The Exception --->
        <cfset ExceptionBean = ExceptionService.ExceptionHandler(arguments.exception,"coldboxproxy","ColdBox Proxy Exception")>                    
        
        <!--- Return rendered bugreport --->
        <cfreturn exceptionService.renderBugReport(ExceptionBean)>
    </cffunction>
    
</cfcomponent>

The URL of your remote call will be something like this:

coldboxproxy.cfc?method=process&json&event=ehCompany.getCompanies

BOOKMARKS in Eclipse,OPENS frequently used FILES!

Just stumbled upon on article of Luis de la Rosa which explains how to use bookmarks in Eclipse to track important lines of code.

This feaure is really handy for fast opening frequently used files in Eclipse e.g. Transfer.xml.cfm or i18n files.

Am I the only one who never used bookmarks in Eclipse before?

ColdBox SideBar, Proud To Be a ColdBox Team Member!

Luis released ColdBox 2.6.1. which includes the ColdBox SideBar I developed the last two weeks.

The ColdBox SideBar uses NEW nifty interceptor output buffers, which are absolutely useful !

Don't forget to skin the SideBar and send your screenshot ( evdlinden@gmail.com )!

Thanks again Luis!

ColdBox STORE online!

Finally, you can show the world that you love ColdBox.

Check out the ColdBox Store

Want to Become a ColdBox VETERAN?

Check out the course outline of the ColdBox Platform Training Seminars in Dallas.

ColdBox RELOAD FRAMEWORK LINK on error

I work a lot with Lightwire using ColdBox's IOC Plugin.
Sometimes I forget to reload the framework (?fwreinit=1) after adding a new method to a manager/service.
ColdBox/ColdFusion throws an error on calling the new method, because it doesn't exist in the cached cfc.

I got tired of typing ?fwreinit=1, so I adjusted ColdBox's custom error template ( {YOUR_APP}/includes/generic_error.cfm )
and added a reload framework link. Simple, but a time saver...

You don't want to show a reload link on live systems, so I integrated the environment variable.
This variable is set by the evironment interceptor or by the config settings tag: DevEnvironments.

STEP 1:
Make sure you have a valid value for 'CustomErrorTemplate' in your ColdBox settings file.
e.g. includes/generic_error.cfm

STEP 2:
Skip if you're using the environment interceptor.

Make sure that you have setup your DevEnvironments settings tag e.g.
<DevEnvironments>
     <url>localhost</url>
</DevEnvironments>

STEP 3:
Copy/REPLACE the following code in the error template (includes/generic_error.cfm).


<cfset exception = event.getValue("ExceptionBean")>

<!--- Which environment? Show reload framework link? --->
<cfswitch expression="#controller.getSetting('environment')#">
    <cfcase value="development">
        <cfset fwReInitHref = "#CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#">
        <cfif not REFindNoCase('fwreinit',CGI.QUERY_STRING)>
            <cfset fwReInitHref = fwReInitHref & '&fwreinit=1'>
        </cfif>
        <cfoutput>
            <div align="center"><a href="#fwReInitHref#" style="color:blue;">Reload framework</a></div>
        </cfoutput>
        <!--- Default ColdBox error template --->
        <cfinclude template="/coldbox/system/includes/BugReport.cfm">
    </cfcase>
    <cfdefaultcase>
        <!--- Error message on live environment --->
        Sorry, an error occured, please contact administrator    
    </cfdefaultcase>
</cfswitch>

ColdBox 2.6 Final Release, wooow!

ColdBox 2.6 is out! Loads of new features, so don't wait and download now.

Here is the  ColdBox 2.6 press release.

Thanks Luis, for your hard work and dedication!

ColdBox Training Seminars, don't miss!

You want to become a ColdBox veteran?

Luis Majano and other qualified ColdBox trainers give seminars in Dallas on October 4-5, 2008.

Register now and get a Early-Bird discount!

ColdBox 2.6 RC 2, tons of GOODIES!

Luis released ColdBox 2.6. RC2.

Tons of new GOODIES so Check it out now!

WebCharts3D and ColdBox Step-by-step Tutorial

Luis Majano and I made a STEP-BY-STEP-tutorial how to use the ColdBox WebCharts3D plugin.

Have fun!

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.004.