【问题标题】:ColdFusion Lucee Or Railo RestFull Webservice Mapping issueColdFusion Lucee 或 Railo RestFull Web 服务映射问题
【发布时间】:2016-02-11 19:29:23
【问题描述】:

在 ColdFusion Lucee 上创建我的第一个 RestFul Web 服务。

这些是我遵循的步骤。

  1. 在 ROOT 上创建了名为“RestAPI”的文件夹
  2. 在 RestAPI/API 下创建子文件夹(用于 CFC)
  3. 已创建 CFC RestAPI/API/Hello.cfc

你好.cfc

<cfcomponent rest="true" restpath="/hello"> 
    <cffunction name="formPost" access="remote" returnType="String" httpMethod="POST" restPath="/form">
        <cfargument name="firstname" type="String" restArgSource="Form">
        <cfargument name="lastname" type="String" restArgSource="Form">
        <cfset res="firstname : " & #firstname# & " lastname : " & #lastname#>
        <cfreturn res>
    </cffunction>
</cfcomponent>
  1. 创建 CFM Call.cfm

调用.cfm

<cfhttp url="http://mydev:8888/rest/Example/hello/form" method="POST" result="res" port="8888">
    <cfhttpparam type="formfield" name="firstname" value="Dan">
    <cfhttpparam type="formfield" name="lastname" value="Bin">
  1. 在 lucee 管理服务器中创建了一个映射。 /Example

当我运行 Call.cfm 时,我得到了这个输出

在映射 [/Example] 中找不到 [/RestAPI/call.cfm] 的休息服务

Please see the attached screen shots

Just want to know why it is not working in root folder

【问题讨论】:

  • 从您的屏幕截图看来,您已将 call.cfm 模板放置在 RestAPI 路径 mydev:8888/rest/RestAPI/call.cfm 中。将其移至 webroot 并重试mydev:8888/call.cfm
  • @Miguel-F 感谢您的回复 .. 我将 RestAPI/call.cfm 和 API 保存在 RestAPI 的子文件夹中。我不能保留 API 的根文件夹??
  • 我只是指您调用 Rest 服务的 call.cfm 文件。仅将该文件放在 webroot 中。然后从浏览器调用它mydev:8888/call.cfm。您所有的 cfc 都保留在 RestAPI 之下。
  • 忽略我之前的评论。我想我现在明白你的意思了。所以改为尝试将其称为mydev:8888/RestAPI/call.cfm。不要在调用 CFM 时包含 /rest,但在调用服务时要包含 /rest
  • @Miguel-F 是的,它在根文件夹旁边工作,实际上它在除 RestAPI 文件夹之外的任何地方工作。我试图理解为什么会这样?尽管在我的情况下我没有将我的文件保存在组件文件夹中,但它是“API”。

标签: web-services rest coldfusion railo lucee


【解决方案1】:

从您最初的屏幕截图中,我发现问题似乎在于您如何调用 call.cfm 模板。报错信息是:

在映射 [/Example] 中找不到 [/RestAPI/call.cfm] 的休息服务

这告诉我它正在通过您的 REST API 寻找服务,而不是简单地调用模板。我认为这是因为您在 URL 中使用 /rest/ 引用了您的 call.cfm 模板。再次从屏幕截图中,我在浏览器的地址栏中看到了这一点:

mydev:8888/rest/RestAPI/call.cfm

这是我建议将您的 call.cfm 模板移出该子文件夹并移至 Web 根目录的时候。但是,我认为当call.cfm 文件包含在您的/RestAPI/ 文件夹中时,如果您正确引用它,它也会起作用。您应该可以像这样引用它:

mydev:8888/RestAPI/call.cfm

请注意,我已从该 URL 中删除了浏览器请求的 /rest/ 引用。不过,您仍然需要在您的 &lt;cfhttp&gt; 调用中使用 /rest/ 引用。

最后一个问题请在答案框中回答。我可以将多个组件 (cfcs) 文件保存在一个文件夹和地图中吗?

是的,您可以在 API 文件夹中保留多个 CFC。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-10-31
    • 1970-01-01
    • 2011-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    相关资源
    最近更新 更多