boyceofreason
boyceofreason

Reputation: 181

coldfusion 10 REST - 500 Internal Server Error

I'm trying to get a REST service set up in Coldfusion 10 and I'm having some major issues. I've tried several different install configs with Windows 7 and Vista, CF9 and 10 coexisting and standalone, IIS 7/7.5, Apache and Apache Tomcat. However at the moment I'm on Vista, IIS7, CF10 only and using the Default Web Site. I keep getting basically the same results.

The REST service is registered correctly in the CF Admin - C:\inetpub\wwwroot\resttest\ and it recognizes the CFC is REST-enabled.

Here is my simple resource:

<cfcomponent rest="true" restPath="hello">
    <cffunction name="sayHello" access="remote" returnType="String" httpMethod="GET">
        <cfset res="Hello World">
        <cfreturn res>
    </cffunction>
</cfcomponent>

and my call:

<cfhttp url="http://127.0.0.1/rest/hello/" method="GET" result="res">

When I dump out the response or go to that URI, I get 500 Internal Server Error:

Requested URL 127.0.0.1:80/jakarta/isapi_redirect.dll

Physical Path C:\ColdFusion10\config\wsconfig\1\isapi_redirect.dll

I have double and triple checked my cf config as well as IIS for the correct ISAPI filters. Everything seems to be in order. Not sure what to do here, at a loss.

Upvotes: 2

Views: 4917

Answers (7)

DDT
DDT

Reputation: 414

I've been racking my brain the last few weeks about this. On the dev server on my local machine, there are no real errors in the log, which isn't helpful.

I thought it may have been my machine so I pushed it up to my shared hosting environment and the same issue was happening. Once I put an application.cfc in there, I have yet to receive the 500 error, and the performance has also increased from 1.2 seconds per request to about 100-200ms per request with no errors.

Also, if you delete a rest service folder on the server, your Rest service will fail and you have to put the folder back in order to delete it. The whole app will crap out. It wouldn't let me delete that particular service without putting it back(just the folder itself, with nothing in it) before the app would work again. Just an FYI

Upvotes: 0

Pete OK
Pete OK

Reputation: 119

Here's a very interesting solution...

I've been having this same problem with a brand new HelloWorld.cfc rest service. When I added an Application.cfc to the REST directory, the 500 server error immediately disappeared, and everything functioned as expected.

Here was my file structure:

<root_folder>/
    |-- Application.cfc
    |-- model/
         |-- HelloWorld.cfc
    |-- test.cfm

In the root Application.cfc, in the onRequestStart function, I had the following line:

<cfset restInitApplication( "#GetDirectoryFromPath(GetCurrentTemplatePath())#model/" , "MyRestService") />

The file test.cfm then contained a simple cfhttp request, dumping the result:

<cfhttp url="localhost/rest/MyRestService/hello" result="response" method="get"></cfhttp>
<cfdump var="#response#">

HelloWorld.cfc contains only one function that returned a string:

<cfcomponent rest="yes" restpath="hello">
  <cffunction name="sayHi" access="remote" httpmethod="get" restpath="" returntype="string">
    <cfreturn "Hi World!" />
  </cffunction>
</cfcomponent>

With this initial setup, I got a 500 error, "object is not an instance of declaring class" upon visiting: "localhost/test.cfm". Much configuring and testing had no result. Declared in the CF Administrator; restarted CF; declared in code only; declared in admin only; direct browsing; cfhttp connection. Nothing worked.

Then I added an Application.cfc file to the model directory with the REST CFCs. no functions in the CFC, just the barest of Application.cfc files, so that the REST services did not try to fire Application.cfc from the parent folder.

This separation of execution contexts made all the difference. The 500 error immediately went away, and the REST responses acted as intended. So, make sure that your REST folder has its own Application.cfc file. It can have the same application name as the parent Application.cfc file, but it needs to not call an Application.cfc from a parent directory.

Hope this helps someone else!

Upvotes: 2

Johnny Oshika
Johnny Oshika

Reputation: 57562

After countless hours of struggling with this, the problem fixed itself when I changed the "Server Mapping" for my REST service configuration (the one I set in CF Administrator) from:

/api

to

api

Once I removed the preceding '/', the 500 error went away. Now I can call my API as follows:

localhost/rest/api/jobs/1

Upvotes: 0

AJ Mercer
AJ Mercer

Reputation: 11

try putting this in you function

restPath="/"

Upvotes: 1

Clarence Liu
Clarence Liu

Reputation: 4019

I have a working REST component, the main issue I found was that I upgraded an old component, remove all your other functions - only one function should have httpmethod="get", otherwise CF doesn't know which one to call (others should be POST?)

Also I have a restpath attr on the function, in cfscript:

remote struct function readRole(required numeric site_role_id restargsource="path") httpmethod="get" returnformat="json" restpath="{site_role_id}" {

Comment out all the other functions and just test this: <cfhttp url="http://127.0.0.1/rest/hello/1" method="GET" result="res">


Also to make things easier, in your App.cfc requestOnStart try adding this if you think it'll help (u can secure it too with a password or encrypted key):

if (SERVER.ColdFusion.ProductVersion GTE 10 AND structKeyExists(url, "refreshRESTful"))
    {
        restInitApplication(getDirectoryFromPath(getCurrentTemplatePath()), this.name);

    }

Upvotes: 0

AngeloS
AngeloS

Reputation: 5586

It looks like your missing a forward slash in your restPath:

<cfcomponent rest="true" restPath="/hello">

Check out this article because he has some great code samples that will take you through this in better detail:

http://www.adobe.com/devnet/coldfusion/articles/restful-web-services.html

Upvotes: 0

Russ
Russ

Reputation: 1951

I've been having problems with CF 10 REST as well. Try restarting your CF service. I have to restart every time I make a change to the REST CFC.

Upvotes: 0

Related Questions