我使用 Google Cloud Endpoints 定义了一个简单的 API:
@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>
我在 Eclipse 中启动 API 并执行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。