When I call the URL http://192.168.2.26:8080/rest/RestSample/season/1.json , I get the error message:
"Error", "ajp-bio-8012-exec-4", "03/01/13", "16:51:58", "RestSample", "the object is not an instance of the class declaration. Sequence of files included or processed : C: \ path_to \ api \ service.cfc '' "
This is the file /api/service.cfc :
<cfscript> component restpath="season" rest="true" { remote query function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}" { var response = ""; var qry = new Query(); var userQry = ""; qry.setSQl("select * from mytable where userID = :userid"); qry.addParam(name="userid", value="#arguments.userid#", cfsqltype="cf_sql_numeric"); userQry = qry.execute().getResult(); if(userQry.recordcount == 0) { response = userQry; } else { throw(type="Restsample.SeasonsNotFoundError", errorCode='404', detail='Seasons not found'); } return response; } } </cfscript>
Edit # 1 : following this guide: http://www.anujgakhar.com/2012/02/20/using-rest-services-in-coldfusion-10/
Edit # 2 : my application.cfc
<cfscript> component output="false" { this.name = "RestSample"; this.applicationTimeout = createTimespan(0,0,0,0); this.datasource = "mydsn"; this.username = ""; this.password = ""; //this.restsettings.skipCFCWithError = true; public boolean function onRequestStart() { restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), this.name); return true; } } </cfscript>
I would also like to note that updating REST services in the ALWAYS administrator gives me the following message:
Unable to refresh REST service. Application RestSample could not be initialized. Reason: The application does not contain any rest enabled CFCs. The application does not contain any rest enabled CFCs.
However, I can delete them and add them via onRequestStart () without any problems.
Edit # 3
My current structure
/api/main/service.cfc /api/application.cfc /api/index.cfm
Application.cfc
<cfscript> component output="false" { this.name = "RestSample"; this.applicationTimeout = createTimespan(0,0,0,0); this.datasource = "mydsn"; this.username = ""; this.password = ""; this.restsettings.skipCFCWithError = true; public boolean function onRequestStart() { restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()).concat("main\"), this.name); return true; } } </cfscript>
service.cfc
<cfscript> component restpath="season" rest="true" { remote Query function getSeasonsByUserId(numeric userid restargsource="Path") httpmethod="GET" restpath="{userid}" { var response = ""; var qry = new Query(); var userQry = ""; qry.setSQl("select * from mytable where userID = :userid"); qry.addParam(name="userid", value="#arguments.userid#", cfsqltype="cf_sql_numeric"); userQry = qry.execute().getResult(); return userQry; } } </cfscript>
I still get the following error:
'object is not an instance of declaring class