【问题标题】:Railo REST API configuration not workingRailo REST API 配置不起作用
【发布时间】:2014-11-13 11:16:04
【问题描述】:

我正在努力在 railo 中创建一个 REST API,但我的 railo 配置似乎有些问题。
我的铁路管理员一直告诉我:

“您的环境中未配置 REST Servlet”

所以,我在我的 web.xml(位于 my-website/WEB-INF/web.xml)中添加了 REST Servlet 启用代码

	<servlet id="RESTServlet">
	  <description>Railo Servlet for RESTful services</description>
	  <servlet-name>RESTServlet</servlet-name>    
	  <servlet-class>railo.loader.servlet.RestServlet</servlet-class>
	  <load-on-startup>2</load-on-startup>
	</servlet>  
	
	<servlet-mapping>
	  <servlet-name>RESTServlet</servlet-name>
	  <url-pattern>/rest/*</url-pattern>
	</servlet-mapping>	
但它仍然无法正常工作。
当我尝试调用 API 时,我给了我 404 错误。
看起来 railo 服务器无法识别 url 的 /rest/ 部分。

尝试访问 REST API 的 url 是这样的:

{mysite}/rest/{rest-api-mapping-name}/{component-rest-parth}/{function-rest-path}

请告诉我我做错了什么。

谢谢

【问题讨论】:

  • 你们用什么方法来部署Railo?雷洛战争?您的 CFML servlet 是否被正确调用? (IE:你能运行 CFML 模板好吗?)
  • 我不确定部署方法。但我认为这是 railo Tomcat 安装程序。此外,所有其他 CFML 模板都运行良好。
  • 好的,我想我知道发生了什么。最后一个问题:您使用的是什么操作系统和网络服务器?也许是 Linux 上的 Apache?
  • 我在下面发布的答案应该解决您得到的 404 问题。 REST servlet 定义应该已经在 Tomcat 默认 web.xml 文件中定义,该文件位于 {railo install}/tomcat/conf/web.xml

标签: rest railo


【解决方案1】:

如果您在 Linux 上使用带有 Railo 安装程序的 Apache,那么您需要对 Apache 配置进行快速修改,以启用对 REST 的访问。在您的主要 Apache 配置文件(debian 上的 /etc/apache2/apache2.conf 和 RHEL 上的 /etc/httpd/httpd.conf)中,您需要编辑 Railo 代理配置并取消注释 REST 模式匹配,如下所示:

<IfModule mod_proxy.c>
        <Proxy *>
        Allow from 127.0.0.1
        </Proxy>
        ProxyPreserveHost On
        ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2
        ProxyPassMatch ^/(.+\.cfchart)(/.*)?$ http://127.0.0.1:8888/$1$2
        ProxyPassMatch ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2
        # optional mappings
        #ProxyPassMatch ^/flex2gateway/(.*)$ http://127.0.0.1:8888/flex2gateway/$1
        #ProxyPassMatch ^/messagebroker/(.*)$ http://127.0.0.1:8888/messagebroker/$1
        #ProxyPassMatch ^/flashservices/gateway(.*)$ http://127.0.0.1:8888/flashservices/gateway$1
        #ProxyPassMatch ^/openamf/gateway/(.*)$ http://127.0.0.1:8888/openamf/gateway/$1
        ProxyPassMatch ^/rest/(.*)$ http://127.0.0.1:8888/rest/$1
        ProxyPassReverse / http://127.0.0.1:8888/
</IfModule>

具体来说,这一行需要取消注释:

ProxyPassMatch ^/rest/(.*)$ http://127.0.0.1:8888/rest/$1

如果这有助于摆脱您目前遇到的 404,请告诉我们。

【讨论】:

  • 我知道这是一个老问题。但是我在 Lucee 4.5/Apache/Tomcat 和 Windows 2008R2 IIS7 上使用我的 REST API 得到 404。您知道使用 web.config 文件的类似解决方案吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-05-03
  • 2023-03-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-01-15
  • 2016-03-27
相关资源
最近更新 更多