3

我使用 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。

4

1 回答 1

2

要测试您的应用程序,请尝试

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在您的日志中,这仅表明该方法是否已设置身份验证。在您的情况下,对于这种方法,它是true.

于 2013-06-20T21:14:57.593 回答