ColdFusion Lucee或Railo RestFull Webservice Mapping问题

时间:2015-11-10 19:37:22

标签: web-services rest coldfusion railo lucee

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

这些是我遵循的步骤。

  1. ROOT上的已创建文件夹名为" RestAPI"
  2. 在RestAPI / API(适用于CFC)下创建子文件夹
  3. 创建了CFC RestAPI / API / Hello.cfc
  4. Hello.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
    2. Call.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
      2. 当我运行Call.cfm时,我得到了这个输出

          

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

        Please see the attached screen shots

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

1 个答案:

答案 0 :(得分:1)

从您的初始屏幕截图中我发现问题似乎就是您调用call.cfm模板的方式。报告的错误消息是:

  

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

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

mydev:8888/rest/RestAPI/call.cfm

这时我建议将您的call.cfm模板移出该子文件夹并进入网络根目录。但是,我认为如果在call.cfm文件夹中包含/RestAPI/文件时正确引用它也会有效。您应该能够像这样引用它:

mydev:8888/RestAPI/call.cfm

请注意,我已从此URL中删除了浏览器请求的/rest/引用。尽管如此,您仍然需要/rest/电话中的<cfhttp>引用。

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

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

相关问题