3

私は、ColdFusion 8 ベースの CMS システム用の API を作成する任務を負っています。いくつかの調査を行った後、次の 3 つの理由から 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

4 つのファイルすべての内容は次のとおりです。

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>

学生会員.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>

アプリケーション.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>

索引.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

すべてを正しく理解していると仮定すると、"Jason Bristol" などの .json 形式の応答が得られるはずです。

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
4

2 に答える 2

1

これは、Tomcat のプレーン バニラ インストールに関する既知の問題です。(Tomcatを使用している場合は?)

web.xml ファイルに追加のサーブレット マッピングを追加できます。

<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

于 2015-01-08T10:49:04.340 に答える
-1

これ:

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

有効な URL ではないようです。index.cfm は Web ページなので、その後にディレクトリを追加しても意味がありません。学生がサブフォルダーの場合、次のようなものが必要です。

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

そのフォルダーにインデックスまたは既定のファイルがある場合は、表示されるはずです。それ以外の場合は、そのフォルダー内のファイルを指定する必要があります。

于 2013-05-17T19:24:59.493 に答える