【问题标题】:Getting a 404 when trying to use the taffy RESTful API framework on ColdFusion 8/Windows Server 2003/IIS6尝试在 ColdFusion 8/Windows Server 2003/IIS6 上使用 taffy RESTful API 框架时出现 404
【发布时间】:2013-05-13 01:13:50
【问题描述】:

我的任务是为基于 ColdFusion 8 的 CMS 系统创建 API。在做了一些研究之后,我决定 RESTful API 是最好的选择,原因有以下三个:

  1. 使用起来非常简单
  2. 相当容易实现
  3. 优秀的长期解决方案

考虑到我首先是一名应用程序/系统程序员,高级 Web 开发并不是我的专长,因此我没有重新发明轮子,而是开始为我们的 API 寻找一些框架。

我选择Taffy 主要是因为我发现它的设计比 PowerNap 和 FW/1 更优雅,但是我在实现它时遇到了一些麻烦。

根据文档,我已将解压缩的“taffy”文件夹放在我们的 Web 根目录中,并在我们的开发站点内创建了一个 api 目录 -

xxx.xxx.xxx.xxx/dev.cms/api_mk3

里面是目录:

/resources/studentCollection.cfc
/resources/studentMember.cfc
/Application.cfc
/index.cfm

四个文件的内容如下:

studentCollection.cfc

<cfscript>
component extends="taffy.core.resource" taffy:uri="/students" {
    public function get() {
        //query the database for matches, making use of optional parameter "eyeColor" if provided
        //then...
        var someCollectionObject = ArrayNew(1);
        someCollectionObject[1] = "Jason Bristol";
        return representationOf(someCollectionObject).withStatus(200); //collection might be query, array, etc
    }
}
</cfscript>

studentMember.cfc

<cfscript>
component extends="taffy.core.resource" taffy:uri="/students/{personName}" {
    public function get(string personName) {
        //find the requested person, by name
        //then...
        return noData().withStatus(404);//representationOf(personName).withStatus(200); //member might be a structure, ORM entity, etc
    }
}
</cfscript>

Application.cfc

<cfcomponent extends="taffy.core.api">
<cfscript>

    this.name = 'CMS-API';

    variables.framework = {};
    variables.framework.debugKey = "debug";
    variables.framework.reloadKey = "reload";
    variables.framework.reloadPassword = "true";
    variables.framework.representationClass = "taffy.core.genericRepresentation";
    variables.framework.returnExceptionsAsJson = true;

    // do your onApplicationStart stuff here
    function applicationStartEvent() {
    }

    // do your onRequestStart stuff here
    function requestStartEvent() {
    }

    // this function is called after the request has been parsed and all request details are known
    function onTaffyRequest(verb, cfc, requestArguments, mimeExt) {
        // this would be a good place for you to check API key validity and other non-resource-specific validation
        return true;
    }

</cfscript>

index.cfm

Blank, as per the documentation.

我遇到的问题是如果我要导航到

xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm/students

我会得到一个 404

[14:57:02.963] GET http://xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm/students [HTTP/1.1 404 Not Found 56ms]

Request URL:
http://xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm/students


Request Method:
GET


Status Code:
HTTP/1.1 404 Not Found



Request Headers
14:57:02.000

User-Agent:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:20.0) Gecko/20100101 Firefox/20.0
Host:xxx.xxx.xxx.xxx
Connection:keep-alive
Accept-Language:en-US,en;q=0.5
Accept-Encoding:gzip, deflate
Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8


Sent Cookie
CFTOKEN:85979056CFID:1194857



Response Headers
Δ56ms

X-Powered-By:ASP.NETServer:Microsoft-IIS/6.0
Date:Fri, 17 May 2013 18:57:37 GMT
Content-Type:text/html; charset=UTF-8
Connection:close

现在假设我正确理解了所有内容,我应该有一个 .json 格式的“Jason Bristol”响应或类似的内容。

我怀疑 IIS6 中的 MIME 类型或 URL 重写存在问题,但我不知道如何更正此问题的具体细节。很长一段时间以来,我一直在推动升级到 Windows Server 2008 RC2,但没有成功。

这是操作员错误还是可以修复?

编辑: 从我所看到的情况来看,我在 CF 日志中一无所获。以下是 IIS 日志中的条目:

2013-05-20 13:56:20 W3SVC4 10.40.204.236 GET /dev.cms/api_mk3/index.cfm/students - 80 - 70.88.47.65 Mozilla/5.0+(Windows+NT+6.1;+WOW64)+AppleWebKit/537.31+(KHTML,+like+Gecko)+Chrome/26.0.1410.64+Safari/537.31 404 0 0

【问题讨论】:

  • 在尝试实现框架之前,您知道 ColdFusion 本身是否正常工作吗?你能浏览到根xxx.xxx.xxx.xxx/index.cfm中的CFM页面吗?
  • 我确实可以,我们的 CMS 系统目前在安装 ColdFusion 8 时运行正常
  • 您是否尝试通过点击 url xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm?reload=true 重新初始化 Taffy?
  • 刚试过,还是404
  • 有趣的是,我还发现点击 xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm 本身会给出 404,但该文件确实存在

标签: coldfusion iis-6 http-status-code-404 windows-server-2003 taffy


【解决方案1】:

这是在 tomcat 上安装普通香草时的一个已知问题。 (如果你使用tomcat?)

您可以在 web.xml 文件中添加额外的 servlet 映射。

<servlet-mapping>
    <servlet-name>CFMLServlet</servlet-name>
    <url-pattern>/api/index.cfm/*</url-pattern>
</servlet-mapping>

https://github.com/atuttle/Taffy/wiki/404-issue-with-Railo-or-Tomcat-and-API-in-a-sub-folder

【讨论】:

    【解决方案2】:

    这个:

    xxx.xxx.xxx.xxx/dev.cms/api_mk3/index.cfm/students
    

    看起来不像是一个有效的网址。 index.cfm 是一个网页,因此在它之后添加目录没有意义。如果学生是一个子文件夹,你需要这样的东西:

    xxx.xxx.xxx.xxx/dev.cms/api_mk3/students
    

    如果该文件夹中有索引或默认文件,它应该会出现。否则,您必须在该文件夹中指定一个文件。

    【讨论】:

    • 根据github.com/atuttle/Taffy/wiki/Getting-Started "假设您的API位于example.com/api/index.cfm,并且您已经使用URI /products和GET方法实现了资源,那么您可以打开URL:@987654323 @ 在您的浏览器中,数据将被返回,使用默认的 mime 类型进行序列化(除非另有定义,否则为 JSON)“据我了解,此 URL 格式是如何访问 API
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-06-23
    • 1970-01-01
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-10
    相关资源
    最近更新 更多