谷歌云端点SPI限制
问题描述:
我定义了使用谷歌云端点一个简单的API:谷歌云端点SPI限制
@Api(name = "realestate", version = "v1")
public class RealEstatePropertyV1 {
@ApiMethod(name = "properties", httpMethod = "GET")
public List<RealEstateProperty> list() {
return ofy().load().type(RealEstateProperty.class).list();
}
}
我还配置web.xml
:
<servlet>
<servlet-name>SystemServiceServlet</servlet-name>
<servlet-class>com.google.api.server.spi.SystemServiceServlet</servlet-class>
<init-param>
<param-name>services</param-name>
<param-value>com.realestate.api.v1.RealEstatePropertyV1</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>SystemServiceServlet</servlet-name>
<url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>
</web-app>
我推出API在Eclipse和执行curl http://localhost:8888/_ah/spi/realestate/v1/properties
。响应是
<html><head><title>Error 405 HTTP method GET is not supported by this URL</title></head>
<body><h2>Error 405 HTTP method GET is not supported by this URL</h2></body>
</html>
服务器日志:
Jun 20, 2013 9:22:14 PM com.google.appengine.tools.development.DevAppServerImpl start
INFO: Dev App Server is now running
Jun 20, 2013 9:22:29 PM com.google.api.server.spi.SystemServiceServlet init
INFO: SPI restricted: true
你知道哪些呢SPI restricted
手段?我想提一下,我没有在Google API控制台中注册任何内容。我的目标是首先在本地测试API。
答
要测试你的应用程序,尝试
curl -X POST -d "{}" \
> -H "Content-Type: application/json" \
> http://localhost:8888/_ah/spi/realestate/v1/properties
更重要的是,使用API浏览器
http://localhost:8888/_ah/api/explorer
至于在日志SPI restricted
测试您的应用程序,这只是表明该方法是否有auth设置。在你的情况下,对于这种方法,它是true
。
使用你的'curl'命令,我得到以下内容:'{“error_message”:“missing/{Service}。{method}”}'。我没有在App Engine上部署API,也许这就是原因。 – Sydney
这与'localhost:8888'无关。什么是“{服务}”? – bossylobster
因为我没有为'@ ApiMethod'指定'path'属性,所以正确的URL是'http:// localhost:8888/_ah/api/realestate/v1/realestateproperty'。我从API浏览器中获得了它。起初它不起作用,因为我使用的是“objectify”,它似乎不适用于端点。 – Sydney