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.
<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:


There are no comments for this entry.
[Add Comment]