Hi Luis,
I’ve upgraded to the latest CB build on GitHub and have been able to implement the aroundHandler. Very cool stuff!
I also created a model to model the REST results like so:
RESTResults.cfc
/**
- I model the results of a RESTful response
*/
component accessors=“true”{
property name=“data” type=“any”;
property name=“error” type=“boolean”;
property name=“messages” type=“text”;
property name=“statusCode” type=“numeric” default=“200”;
property name=“statusText” type=“string” default=“OK”;
property name=“jsonAsText” type=“boolean” default=“true”;
RestResults function init(){
return this;
}
}
And here are the functions in my handler. Note, I’ve also removed the code from my preHandler() and postHandler() which used to prepare the rc.results object and execute event.renderData(). This was done because the aroundHandler() now does this.
function aroundHandler(event,targetAction,eventArguments){
var rc = event.getCollection();
// get Restful Results object
var rc.results = getModel(“RESTResults”);
// try the action
try{
// call targeted action
arguments.targetAction(event);
}
catch(Any e){
// handle a restful exception
//handleRestfulException(e,rc.results);
}
// prepare the results
event.renderData(data=rc.results.getData(),
format=rc.format,
statusCode=rc.results.getStatusCode(),
statusText=rc.results.getStatusText(),
jsonAsText=rc.results.getJSONAsText());
}
function getUser(event){
var rc = event.getCollection();
//query for the user
rc.user = userService.getUser(rc.userid);
//validate user is not empty
if(structIsEmpty(rc.user)){
log.info(“Invalid User Request - #rc.userID#|#rc.Authorization# from #cgi.REMOTE_ADDR#, route: #event.getCurrentRoute()#”);
rc.results.setStatusCode(404);
}else{
rc.results.setData(rc.user);
}
}
For the most part everything is working correctly except that an error is thrown when trying to execute data=rc.results.getData() in the aroundHandler. Here is the stack trace:
Application Execution Exception
Error Type: Expression : [N/A]
Error Messages:
Complex object types cannot be converted to simple values.
The expression has requested a variable or an intermediate expression result as a simple value. However, the result cannot be converted to a simple value. Simple values are strings, numbers, boolean values, and date/time values. Queries, arrays, and COM objects are examples of complex values.
The most likely cause of the error is that you tried to use a complex value as a simple one. For example, you tried to use a query variable in a cfif tag.
Tag Context: |
ID: |
CF_CAST |
LINE: |
276 |
Template: |
/Library/WebServer/Documents/coldbox/system/Coldbox.cfc |
ID: |
CF_UDFMETHOD |
LINE: |
69 |
Template: |
/Library/WebServer/Documents/guardly-platform/api/v01/Application.cfc |
Framework Snapshot |
Current Event: |
User.getUser |
Current Layout: |
N/A |
Current View: |
N/A |
Bug Date: |
11/16/2010 05:50:31 PM |
Coldfusion ID: |
CFID=11300 ;
CFToken=50692952 ;
JSessionID=GUARDLY_API_V01_580E5F528360F62521A9DFA9FA175C30_11300_50692952
|
Template Path : |
/Library/WebServer/Documents/guardly-platform/api/v01/index.cfm |
Path Info : |
/user/1.json |
Host & Server: |
127.0.0.1 Nolan-Dubeaus-MacBook-Pro.local |
Query String: |
|
Browser: |
Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 |
Stack Trace: |
coldfusion.runtime.CfJspPage$ComplexObjectException: Complex object types cannot be converted to simple values.
at coldfusion.runtime.Cast._String(Cast.java:1023)
at cfColdbox2ecfc647030621$funcPROCESSCOLDBOXREQUEST.runFunction(/Library/WebServer/Documents/coldbox/system/Coldbox.cfc:276)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
at coldfusion.runtime.CfJspPage._invokeUDF(CfJspPage.java:2582)
at cfApplication2ecfc1523304759$funcONREQUESTSTART.runFunction(/Library/WebServer/Documents/guardly-platform/api/v01/Application.cfc:69)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:472)
at coldfusion.runtime.UDFMethod$ReturnTypeFilter.invoke(UDFMethod.java:405)
at coldfusion.runtime.UDFMethod$ArgumentCollectionFilter.invoke(UDFMethod.java:368)
at coldfusion.filter.FunctionAccessFilter.invoke(FunctionAccessFilter.java:55)
at coldfusion.runtime.UDFMethod.runFilterChain(UDFMethod.java:321)
at coldfusion.runtime.UDFMethod.invoke(UDFMethod.java:220)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:491)
at coldfusion.runtime.TemplateProxy.invoke(TemplateProxy.java:337)
at coldfusion.runtime.AppEventInvoker.invoke(AppEventInvoker.java:88)
at coldfusion.runtime.AppEventInvoker.onRequestStart(AppEventInvoker.java:258)
at coldfusion.filter.ApplicationFilter.invoke(ApplicationFilter.java:349)
at coldfusion.filter.RequestMonitorFilter.invoke(RequestMonitorFilter.java:48)
at coldfusion.filter.MonitoringFilter.invoke(MonitoringFilter.java:40)
at coldfusion.filter.PathFilter.invoke(PathFilter.java:94)
at coldfusion.filter.ExceptionFilter.invoke(ExceptionFilter.java:70)
at coldfusion.filter.BrowserDebugFilter.invoke(BrowserDebugFilter.java:79)
at coldfusion.filter.ClientScopePersistenceFilter.invoke(ClientScopePersistenceFilter.java:28)
at coldfusion.filter.BrowserFilter.invoke(BrowserFilter.java:38)
at coldfusion.filter.NoCacheFilter.invoke(NoCacheFilter.java:46)
at coldfusion.filter.GlobalsFilter.invoke(GlobalsFilter.java:38)
at coldfusion.filter.DatasourceFilter.invoke(DatasourceFilter.java:22)
at coldfusion.filter.CachingFilter.invoke(CachingFilter.java:62)
at coldfusion.CfmServlet.service(CfmServlet.java:200)
at coldfusion.bootstrap.BootstrapServlet.service(BootstrapServlet.java:89)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:86)
at coldfusion.monitor.event.MonitoringServletFilter.doFilter(MonitoringServletFilter.java:42)
at coldfusion.bootstrap.BootstrapFilter.doFilter(BootstrapFilter.java:46)
at jrun.servlet.FilterChain.doFilter(FilterChain.java:94)
at jrun.servlet.FilterChain.service(FilterChain.java:101)
at jrun.servlet.ServletInvoker.invoke(ServletInvoker.java:106)
at jrun.servlet.JRunInvokerChain.invokeNext(JRunInvokerChain.java:42)
at jrun.servlet.JRunRequestDispatcher.invoke(JRunRequestDispatcher.java:286)
at jrun.servlet.ServletEngineService.dispatch(ServletEngineService.java:543)
at jrun.servlet.jrpp.JRunProxyService.invokeRunnable(JRunProxyService.java:203)
at jrunx.scheduler.ThreadPool$ThreadThrottle.invokeRunnable(ThreadPool.java:428)
at jrunx.scheduler.WorkerThread.run(WorkerThread.java:66)
Any ideas as to why this occurs?
Many thanks.
Nolan
|